[rkward-cvs] SF.net SVN: rkward:[3470] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Mar 8 09:38:30 UTC 2011


Revision: 3470
          http://rkward.svn.sourceforge.net/rkward/?rev=3470&view=rev
Author:   tfry
Date:     2011-03-08 09:38:30 +0000 (Tue, 08 Mar 2011)

Log Message:
-----------
Use an enum to enhance readability and searchability of code.

Modified Paths:
--------------
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/core/renvironmentobject.cpp
    trunk/rkward/rkward/core/rfunctionobject.cpp
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/core/robject.h
    trunk/rkward/rkward/rbackend/rkstructuregetter.cpp

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2011-03-08 09:38:30 UTC (rev 3470)
@@ -63,7 +63,7 @@
 			int child_index = getIndexOf (child);
 			RK_ASSERT (child_index >= 0);
 			if (RKGlobals::tracker ()->removeObject (child, 0, true)) {
-				RData *child_name_data = new_data->getStructureVector ()[0];
+				RData *child_name_data = new_data->getStructureVector ()[StoragePositionName];
 				RK_ASSERT (child_name_data->getDataType () == RData::StringVector);
 				RK_ASSERT (child_name_data->getDataLength () >= 1);
 				QString child_name = child_name_data->getStringVector ()[0];
@@ -79,15 +79,15 @@
 bool RContainerObject::updateStructure (RData *new_data) {
 	RK_TRACE (OBJECTS);
 	unsigned int data_length = new_data->getDataLength (); 
-	RK_ASSERT (data_length >= 5);
+	RK_ASSERT (data_length >= StorageSizeBasicInfo);
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
 
 	if (!RObject::updateStructure (new_data)) return false;
 
-	if (data_length > 5) {
-		RK_ASSERT (data_length == 6);
+	if (data_length > StorageSizeBasicInfo) {
+		RK_ASSERT (data_length == (StorageSizeBasicInfo + 1));
 
-		RData *children_sub = new_data->getStructureVector ()[5];
+		RData *children_sub = new_data->getStructureVector ()[StoragePositionChildren];
 		RK_ASSERT (children_sub->getDataType () == RData::StructureVector);
 		updateChildren (children_sub);
 		updateRowNamesObject ();
@@ -101,9 +101,9 @@
 RObject *RContainerObject::createChildFromStructure (RData *child_data, const QString &child_name, int position) {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (child_data->getDataType () == RData::StructureVector);
-	RK_ASSERT (child_data->getDataLength () >= 2);		// need to see at least the type at this point
+	RK_ASSERT (child_data->getDataLength () >= (StoragePositionType + 1));		// need to see at least the type at this point
 
-	RData *type_data = child_data->getStructureVector ()[1];
+	RData *type_data = child_data->getStructureVector ()[StoragePositionType];
 	RK_ASSERT (type_data->getDataType () == RData::IntVector);
 	RK_ASSERT (type_data->getDataLength () == 1);
 
@@ -154,8 +154,8 @@
 	for (unsigned int i = 0; i < new_child_count; ++i) {
 		RData *child_data = new_children->getStructureVector ()[i];
 		RK_ASSERT (child_data->getDataType () == RData::StructureVector);
-		RK_ASSERT (child_data->getDataLength () >= 1);
-		RData *child_name_data = child_data->getStructureVector ()[0];
+		RK_ASSERT (child_data->getDataLength () >= (StoragePositionName + 1));
+		RData *child_name_data = child_data->getStructureVector ()[StoragePositionName];
 		RK_ASSERT (child_name_data->getDataType () == RData::StringVector);
 		RK_ASSERT (child_name_data->getDataLength () >= 1);
 		QString child_name = child_name_data->getStringVector ()[0];

Modified: trunk/rkward/rkward/core/renvironmentobject.cpp
===================================================================
--- trunk/rkward/rkward/core/renvironmentobject.cpp	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/core/renvironmentobject.cpp	2011-03-08 09:38:30 UTC (rev 3470)
@@ -142,16 +142,16 @@
 bool REnvironmentObject::updateStructure (RData *new_data) {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
-	RK_ASSERT (new_data->getDataLength () >= 5);
+	RK_ASSERT (new_data->getDataLength () >= StorageSizeBasicInfo);
 
 	if (!(type & ToplevelEnv)) {
 		if (!RObject::updateStructure (new_data)) return false;
 	}
 
-	if (new_data->getDataLength () > 5) {
-		RK_ASSERT (new_data->getDataLength () == 6);
+	if (new_data->getDataLength () > StorageSizeBasicInfo) {
+		RK_ASSERT (new_data->getDataLength () == (StorageSizeBasicInfo + 1));
 
-		RData *children_sub = new_data->getStructureVector ()[5];
+		RData *children_sub = new_data->getStructureVector ()[StoragePositionChildren];
 		RK_ASSERT (children_sub->getDataType () == RData::StructureVector);
 		updateChildren (children_sub);
 	} else {

Modified: trunk/rkward/rkward/core/rfunctionobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rfunctionobject.cpp	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/core/rfunctionobject.cpp	2011-03-08 09:38:30 UTC (rev 3470)
@@ -48,7 +48,7 @@
 
 bool RFunctionObject::updateStructure (RData *new_data) {
 	RK_TRACE (OBJECTS);
-	RK_ASSERT (new_data->getDataLength () >= 5);
+	RK_ASSERT (new_data->getDataLength () >= StorageSizeBasicInfo);
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
 
 	if (!RObject::updateStructure (new_data)) return false;
@@ -60,11 +60,11 @@
 
 bool RFunctionObject::updateArguments (RData *new_data) {
 	RK_TRACE (OBJECTS);
-	RK_ASSERT (new_data->getDataLength () == 7);
+	RK_ASSERT (new_data->getDataLength () == (StoragePositionFunValues + 1));
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
 
-	RData *argnames_data = new_data->getStructureVector ()[5];
-	RData *argvalues_data = new_data->getStructureVector ()[6];
+	RData *argnames_data = new_data->getStructureVector ()[StoragePositionFunArgs];
+	RData *argvalues_data = new_data->getStructureVector ()[StoragePositionFunValues];
 
 	RK_ASSERT (argnames_data->getDataType () == RData::StringVector);
 	RK_ASSERT (argvalues_data->getDataType () == RData::StringVector);

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/core/robject.cpp	2011-03-08 09:38:30 UTC (rev 3470)
@@ -264,18 +264,18 @@
 		return false;
 	}
 
-	RK_ASSERT (new_data->getDataLength () >= 5);
+	RK_ASSERT (new_data->getDataLength () >= StorageSizeBasicInfo);
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
 
 	if (!canAccommodateStructure (new_data)) return false;
 
 	bool properties_change = false;
 
-	properties_change = updateName (new_data->getStructureVector ()[0]);
-	properties_change = updateType (new_data->getStructureVector ()[1]);
-	properties_change = updateClasses (new_data->getStructureVector ()[2]);
-	properties_change = updateMeta (new_data->getStructureVector ()[3]);
-	properties_change = updateDimensions (new_data->getStructureVector ()[4]);
+	properties_change = updateName (new_data->getStructureVector ()[StoragePositionName]);
+	properties_change = updateType (new_data->getStructureVector ()[StoragePositionType]);
+	properties_change = updateClasses (new_data->getStructureVector ()[StoragePositionClass]);
+	properties_change = updateMeta (new_data->getStructureVector ()[StoragePositionMeta]);
+	properties_change = updateDimensions (new_data->getStructureVector ()[StoragePositionDims]);
 
 	if (properties_change) RKGlobals::tracker ()->objectMetaChanged (this);
 	if (type & NeedDataUpdate) updateDataFromR (0);
@@ -307,11 +307,11 @@
 
 bool RObject::canAccommodateStructure (RData *new_data) {
 	RK_TRACE (OBJECTS);
-	RK_ASSERT (new_data->getDataLength () >= 5);
+	RK_ASSERT (new_data->getDataLength () >= StorageSizeBasicInfo);
 	RK_ASSERT (new_data->getDataType () == RData::StructureVector);
 
-	if (!isValidName (new_data->getStructureVector ()[0])) return false;
-	if (!isValidType (new_data->getStructureVector ()[1])) return false;
+	if (!isValidName (new_data->getStructureVector ()[StoragePositionName])) return false;
+	if (!isValidType (new_data->getStructureVector ()[StoragePositionType])) return false;
 	return true;
 }
 

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/core/robject.h	2011-03-08 09:38:30 UTC (rev 3470)
@@ -80,7 +80,20 @@
 		MaxKnownDataType = DataLogical
 	};
 
-	#define ROBJECT_TYPE_INTERNAL_MASK (RObject::Container | RObject::Variable | RObject::Workspace | RObject::Environment | RObject::Function)
+/** For passing data between RKStructureGetter and RObject. Be very careful about changing the values in this enum. It is for better readability / searchability of the code, only. */
+	enum {
+		StoragePositionName = 0,
+		StoragePositionType = 1,
+		StoragePositionClass = 2,
+		StoragePositionMeta = 3,
+		StoragePositionDims = 4,
+		StoragePositionChildren = 5,
+		StoragePositionFunArgs = 5,
+		StoragePositionFunValues = 6,
+		StorageSizeBasicInfo = 5,
+	};
+
+#define ROBJECT_TYPE_INTERNAL_MASK (RObject::Container | RObject::Variable | RObject::Workspace | RObject::Environment | RObject::Function)
 /** @returns false if an object of the given old type cannot represent an object of the given new type (e.g. (new_type & RObjectType::Variable), but (old_type & RObjectType::Container)). */
 	static bool isMatchingType (int old_type, int new_type) { return ((old_type & ROBJECT_TYPE_INTERNAL_MASK) == (new_type & ROBJECT_TYPE_INTERNAL_MASK)); };
 	

Modified: trunk/rkward/rkward/rbackend/rkstructuregetter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2011-03-07 14:00:23 UTC (rev 3469)
+++ trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2011-03-08 09:38:30 UTC (rev 3470)
@@ -284,18 +284,18 @@
 	dimdata->setData (dims);
 
 	// store everything we have so far
-	int storage_length = 5;
+	int storage_length = RObject::StorageSizeBasicInfo;
 	if (is_container) {
-		storage_length = 6;
+		storage_length = RObject::StorageSizeBasicInfo + 1;
 	} else if (is_function) {
-		storage_length = 7;
+		storage_length = RObject::StorageSizeBasicInfo + 2;
 	}
 	RData::RDataStorage res (storage_length, 0);
-	res[0] = namedata;
-	res[1] = typedata;
-	res[2] = classdata;
-	res[3] = metadata;
-	res[4] = dimdata;
+	res[RObject::StoragePositionName] = namedata;
+	res[RObject::StoragePositionType] = typedata;
+	res[RObject::StoragePositionClass] = classdata;
+	res[RObject::StoragePositionMeta] = metadata;
+	res[RObject::StoragePositionDims] = dimdata;
 
 	// now add the extra info for containers and functions
 	if (is_container) {
@@ -375,7 +375,7 @@
 
 		RData *childdata = new RData;
 		childdata->setData (children);
-		res[5] = childdata;
+		res[RObject::StoragePositionChildren] = childdata;
 	} else if (is_function) {
 // TODO: get_formals_fun is still the major bottleneck, but no idea, how to improve on this
 		SEXP formals_s = RKRSupport::callSimpleFun (get_formals_fun, value, R_GlobalEnv);
@@ -392,8 +392,8 @@
 
 		UNPROTECT (2); /* names_s, formals_s */
 
-		res[5] = funargsdata;
-		res[6] = funargvaluesdata;
+		res[RObject::StoragePositionFunArgs] = funargsdata;
+		res[RObject::StoragePositionFunValues] = funargvaluesdata;
 	}
 
 	UNPROTECT (1); /* value */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list