Xavi is working rigth now in supporting optional attributes in dynamic types 
(configurations) from ipyclam. For that he needs interface to add and remove 
an attribute by index which does not exist (there is a private AddAtttr_ which 
requires the size of the type as second parameter which is too much an 
implementation detail.

I changed AddAttr_ to use the size already stored in the attribute information 
struct and not requiring the size parameter (patch attached). But, still the 
method names are not ready for a public interface. What about:
        void AddAttribute(unsigned i)
        void AddDynamicTypeAttribute(unsigned i)
        void AddAttributeByIndex(unsigned i)
Any thoughs or preferences?

Note to Xavi: If we can take the size from that description table, there is no 
need to implement a chained method as i told you. (me overdesigning again)

David.


Index: src/Base/DynamicTypeMacros.hxx
===================================================================
--- src/Base/DynamicTypeMacros.hxx	(revisión: 14966)
+++ src/Base/DynamicTypeMacros.hxx	(copia de trabajo)
@@ -275,7 +275,7 @@
 		_new_##NAME(pos, orig);\
 	}\
 	inline void Add##NAME() {\
-		AddAttr_(N, sizeof(TYPE));\
+		AddAttr_(N);\
 	}\
 	template <typename Visitor> \
 	inline void Visit##NAME(Visitor & visitor) { \
Index: src/Base/DynamicType.cxx
===================================================================
--- src/Base/DynamicType.cxx	(revisión: 14966)
+++ src/Base/DynamicType.cxx	(copia de trabajo)
@@ -151,41 +151,41 @@
 }
 
 
-void DynamicType::InformAttr_(unsigned val, const char* name, unsigned size, const char* type, const bool isPtr,
+void DynamicType::InformAttr_(unsigned index, const char* name, unsigned size, const char* type, const bool isPtr,
                             const t_new fnew, const t_new_copy fcopy, const t_destructor fdestr)
 {
-	CLAM_ASSERT(val<numAttr, 
+	CLAM_ASSERT(index<numAttr, 
 		"There are more registered Attributes than the "
 		"number defined in DYN_CLASS_TABLE macro.");
 	CLAM_ASSERT(fnew, "in DT: a dynamic attribute don't have default-constructor !");
 	CLAM_ASSERT(fcopy, "in DT: a dynamic attribute don't have copy constructor !");
 
-	strcpy(typeDescTable[val].id, name);
-	strcpy(typeDescTable[val].type, type);
-	typeDescTable[val].isPointer = isPtr;
-	typeDescTable[val].size = size;
+	strcpy(typeDescTable[index].id, name);
+	strcpy(typeDescTable[index].type, type);
+	typeDescTable[index].isPointer = isPtr;
+	typeDescTable[index].size = size;
 	// default value. This field is used in UpdateData in Fixed offsets mode.
-	typeDescTable[val].offset = -1;  
+	typeDescTable[index].offset = -1;  
 	// references to creation/destruction fuctions of the type/class
-	typeDescTable[val].newObj = fnew;
-	typeDescTable[val].newObjCopy = fcopy;
-	typeDescTable[val].destructObj = fdestr;
+	typeDescTable[index].newObj = fnew;
+	typeDescTable[index].newObjCopy = fcopy;
+	typeDescTable[index].destructObj = fdestr;
 	// informative flags:
 	// flags that will be set at the AddTypedAttr_ 
 	// (the overloaded function that calls this one)
-	typeDescTable[val].isComponent = false;
-	typeDescTable[val].isStorable = false;
-	typeDescTable[val].isDynamicType = false;
+	typeDescTable[index].isComponent = false;
+	typeDescTable[index].isStorable = false;
+	typeDescTable[index].isDynamicType = false;
 
 }
 /////////////////////////////////////////////////////////////////////////////////////////////
 // Main memory management methods: AddAttr_, RemoveAttr_ and UpdateData
 
 
-void DynamicType::AddAttr_ (const unsigned val, const unsigned size)
+void DynamicType::AddAttr_ (const unsigned index)
 {
 	// first we check if there is need to adding the attribute
-	TDynInfo &inf = dynamicTable[val];
+	TDynInfo &inf = dynamicTable[index];
 
 	if (inf.hasBeenAdded) 
 		return;
@@ -194,7 +194,7 @@
 	{
 		inf.hasBeenRemoved = false;
 		++numActiveAttr;
-		dataSize += size;
+		dataSize += typeDescTable[index].size;
 
 		// check if we can unset the global some-removed flag.
 		dynamicTable[numAttr].hasBeenRemoved = false;
@@ -210,7 +210,7 @@
 
 		return;
 	}
-	if (AttrHasData(val)) return;
+	if (AttrHasData(index)) return;
 	
 	// At this point, the actual attribute-adding is necessary
 
@@ -225,8 +225,8 @@
 	}
 
 	++numActiveAttr;
-	dataSize += size;
-	dynamicTable[val].hasBeenAdded = true;
+	dataSize += typeDescTable[index].size;
+	dynamicTable[index].hasBeenAdded = true;
 	dynamicTable[numAttr].hasBeenAdded = true; //this is a global (for all attribute) flag that means that Update is necessary
 	// at this point the data and dynamicTable may contain gaps, 
 	// but they will be compacted at Update() time.
Index: src/Base/DynamicType.hxx
===================================================================
--- src/Base/DynamicType.hxx	(revisión: 14966)
+++ src/Base/DynamicType.hxx	(copia de trabajo)
@@ -165,7 +165,7 @@
 	inline void InformTypedAttr_(unsigned id, const char* name, unsigned size, const char *type, const bool isPtr,
 	                          const t_new, const t_new_copy, const t_destructor, const void* ptr);
 	
-	void AddAttr_ (const unsigned i, const unsigned size);
+	void AddAttr_ (const unsigned i);
 	void RemoveAttr_ (const unsigned id);
 
 public:
_______________________________________________
clam-devel mailing list
clam-devel@lists.clam-project.org
http://lists.clam-project.org/listinfo.cgi/clam-devel-clam-project.org

Reply via email to