Go to the documentation of this file.
40 #define __COMMON_DYNAMIC_TYPE(CLASS_NAME,N) \
42 virtual const char* GetClassName() const { \
45 enum { eNumAttr= N }; \
46 CLAM::DynamicType& GetDynamicTypeCopy(const bool shareData=false, const bool deep=false) const\
48 return *new CLASS_NAME(*this, shareData, deep); \
53 static bool staticTableInitialized = false;\
54 static TAttr staticTypeDescTable[N+1];\
55 typeDescTable = staticTypeDescTable;\
56 if(!staticTableInitialized)\
58 staticTableInitialized=true;\
62 maxAttrSize = N ? (typeDescTable[N-1].offset+typeDescTable[N-1].size) : 0;\
67 const std::type_info & GetTypeId(unsigned n) const \
69 return GetChainedTypeId((AttributePosition<0>*)NULL,n); \
72 template <typename Visitor> \
73 void VisitAll (Visitor & visitor) { \
74 VisitChainedAttr((AttributePosition<0>*)NULL, visitor); \
78 RemoveChainedAttr((AttributePosition<0>*)NULL); \
82 AddChainedAttr((AttributePosition<0>*)NULL); \
87 InformChainedAttr((AttributePosition<0>*)NULL); \
88 DynamicType::InformAll(); \
92 virtual void StoreDynAttributes(CLAM::Storage & s) const { \
93 StoreChainedAttr((AttributePosition<0>*)NULL,s); \
96 virtual void LoadDynAttributes(CLAM::Storage & s) { \
99 LoadChainedAttr((AttributePosition<0>*)NULL,s); \
103 template <unsigned int NAttrib> \
104 class AttributePosition : public CLAM::DynamicType::AttributePositionBase<NAttrib> { \
106 typedef StaticBool<!(NAttrib>=N)> InboundsCheck; \
111 template <unsigned int NAttrib> \
112 void CheckAttribute (StaticFalse*inRange,AttributePosition<NAttrib>*a) { \
113 AttributePosition<(NAttrib)-1>* previous; \
114 previous->CompilationError_AttributePositionOutOfBounds(); \
120 template <unsigned int NAttrib> \
121 void CheckAttribute (StaticTrue*inRange,AttributePosition<NAttrib>*a) { \
122 a->CompilationError_AttributeNotDefined(); \
132 template <unsigned int NAttrib> \
133 void RemoveChainedAttr (AttributePosition<NAttrib>*a) { \
134 typedef typename AttributePosition<NAttrib>::InboundsCheck InboundsCheck; \
135 CheckAttribute ((InboundsCheck*)NULL, \
136 (AttributePosition<NAttrib>*)NULL); \
139 template <unsigned int NAttrib> \
140 void AddChainedAttr (AttributePosition<NAttrib>*a) { \
141 typedef typename AttributePosition<NAttrib>::InboundsCheck InboundsCheck; \
142 CheckAttribute ((InboundsCheck*)NULL, \
143 (AttributePosition<NAttrib>*)NULL); \
146 template <unsigned int NAttrib> \
147 void InformChainedAttr (AttributePosition<NAttrib>*a) { \
148 typedef typename AttributePosition<NAttrib>::InboundsCheck InboundsCheck; \
149 CheckAttribute ((InboundsCheck*)NULL, \
150 (AttributePosition<NAttrib>*)NULL); \
153 template <unsigned int NAttrib> \
154 void StoreChainedAttr (AttributePosition<NAttrib>*a,CLAM::Storage & s) const { \
155 typedef typename AttributePosition<NAttrib>::InboundsCheck InboundsCheck; \
156 CheckAttribute ((InboundsCheck*)NULL, \
157 (AttributePosition<NAttrib>*)NULL); \
160 template <unsigned int NAttrib> \
161 void LoadChainedAttr (AttributePosition<NAttrib>*a,CLAM::Storage & s) { \
162 typedef typename AttributePosition<NAttrib>::InboundsCheck InboundsCheck; \
163 CheckAttribute ((InboundsCheck*)NULL, \
164 (AttributePosition<NAttrib>*)NULL); \
168 template <typename Visitor> \
169 void VisitChainedAttr (AttributePosition<N>*, Visitor & visitor) { \
172 void RemoveChainedAttr (AttributePosition<N>*) { \
175 void AddChainedAttr (AttributePosition<N>*) { \
178 void InformChainedAttr (AttributePosition<N>*) { \
181 void StoreChainedAttr (AttributePosition<N>*pos, CLAM::Storage &s) const { \
184 void LoadChainedAttr (AttributePosition<N>*pos, CLAM::Storage &s) { \
187 const std::type_info & GetChainedTypeId(AttributePosition<N>*pos, unsigned n) const \
189 return typeid(void); \
194 #define DYNAMIC_TYPE(CLASS_NAME, N)\
196 CLASS_NAME() : CLAM::DynamicType(N)\
201 CLASS_NAME(const CLASS_NAME& prototype, const bool shareData=false, const bool deep=true)\
202 : CLAM::DynamicType(prototype, shareData, deep) { \
203 CopyInit(prototype);\
205 __COMMON_DYNAMIC_TYPE(CLASS_NAME,N); \
208 #define DYNAMIC_TYPE_USING_INTERFACE(CLASS_NAME, N, INTERFACE_NAME)\
210 CLASS_NAME() : INTERFACE_NAME(N)\
215 CLASS_NAME(const CLASS_NAME& prototype, const bool shareData=false, const bool deep=true)\
216 : INTERFACE_NAME(prototype, shareData, deep) { \
217 CopyInit(prototype); \
219 __COMMON_DYNAMIC_TYPE(CLASS_NAME,N); \
222 #define __COMMON_DYN_ATTRIBUTE(N,ACCESS,TYPE,NAME) \
224 static void* _new_##NAME(void* p)\
226 return static_cast<void*> (new(p) TYPE());\
229 static void* _new_##NAME(void* pos, void* orig)\
231 TYPE* typed = static_cast< TYPE*>(orig);\
232 return static_cast<void*>( new(pos) TYPE(*typed) );\
235 static void _destructor_##NAME(void* p)\
238 static_cast<__Ty*>(p)->~__Ty();\
242 struct {} CLAM_compile_time_error_Duplicated_Attribute_Index_##N;\
245 inline TYPE& Get##NAME() const {\
246 CLAM_DEBUG_ASSERT((N<numAttr), \
247 "There are more registered Attributes than the number " \
248 "defined in the DYNAMIC_TYPE macro.");\
249 CLAM_ASSERT(ExistAttr(N),\
250 "You are trying to access attribute " #NAME \
251 " that is not Added or not Updated.");\
252 CLAM_DEBUG_ASSERT(data, \
253 "No data allocated for the accessed dynamic type:" #NAME );\
254 void *p=data + dynamicTable[N].offs;\
255 return *static_cast<TYPE*>(p); \
259 inline void Set##NAME(TYPE const & arg) {\
260 CLAM_DEBUG_ASSERT((N<numAttr), \
261 "There are more registered Attributes than the number " \
262 "defined in the DYNAMIC_TYPE macro.");\
263 CLAM_ASSERT(ExistAttr(N),\
264 "You are trying to access attribute " #NAME \
265 " that is not Added or not Updated.");\
266 CLAM_DEBUG_ASSERT(data, \
267 "No data allocated for the accessed dynamic type." #NAME );\
268 void* orig = (void*)(&arg);\
269 char* pos = data+dynamicTable[N].offs;\
270 _destructor_##NAME(pos);\
271 _new_##NAME(pos, orig);\
273 inline void Add##NAME() {\
274 AddAttr_(N, sizeof(TYPE));\
276 template <typename Visitor> \
277 inline void Visit##NAME(Visitor & visitor) { \
279 visitor.Accept(#NAME,Get##NAME()); \
281 inline void Remove##NAME() { \
284 inline bool Has##NAME() const { \
285 return ExistAttr(N); \
288 inline void Inform##NAME() {\
289 InformTypedAttr_(N, #NAME, sizeof(TYPE), #TYPE, false, _new_##NAME, _new_##NAME, _destructor_##NAME, (TYPE*)0);\
291 static inline int GetSize##NAME() { return sizeof(TYPE); } \
292 static inline const char* GetType##NAME() { return #TYPE; } \
293 static inline int GetId##NAME() { return N;}\
297 template <typename Visitor> \
298 void VisitChainedAttr(AttributePosition<N>*, Visitor & visitor) { \
299 Visit##NAME(visitor); \
300 VisitChainedAttr((AttributePosition<(N)+1>*)NULL, visitor); \
302 void RemoveChainedAttr(AttributePosition<N>*) { \
304 RemoveChainedAttr((AttributePosition<(N)+1>*)NULL); \
306 void AddChainedAttr(AttributePosition<N>*) { \
308 AddChainedAttr((AttributePosition<(N)+1>*)NULL); \
310 void InformChainedAttr(AttributePosition<N>*) { \
312 InformChainedAttr((AttributePosition<(N)+1>*)NULL); \
314 void StoreChainedAttr(AttributePosition<N>*, CLAM::Storage & s) const { \
316 StoreChainedAttr((AttributePosition<(N)+1>*)NULL,s); \
318 void LoadChainedAttr(AttributePosition<N>*, CLAM::Storage & s) { \
320 LoadChainedAttr((AttributePosition<(N)+1>*)NULL,s); \
322 const std::type_info & GetChainedTypeId(AttributePosition<N>*, unsigned n) const { \
323 if (n==N) return typeid(TYPE); \
324 return GetChainedTypeId((AttributePosition<(N)+1>*)NULL,n); \
328 #define DYN_ATTRIBUTE(N,ACCESS,TYPE,NAME) \
329 __COMMON_DYN_ATTRIBUTE(N,ACCESS,TYPE,NAME) \
331 void Store##NAME(CLAM::Storage & s) const { \
333 StoreAttribute((CLAM::TypeInfo<TYPE >::StorableAsLeaf*)NULL, s, Get##NAME(), #NAME); \
336 bool Load##NAME(CLAM::Storage & s) { \
338 if (!LoadAttribute((CLAM::TypeInfo<TYPE >::StorableAsLeaf*)NULL, s, obj, #NAME)) { \
348 #define DYN_CONTAINER_ATTRIBUTE(N,ACCESS,TYPE,NAME,ENAME) \
349 __COMMON_DYN_ATTRIBUTE(N,ACCESS,TYPE,NAME) \
351 void Store##NAME(CLAM::Storage & s) const { \
353 StoreIterableAttribute(s, Get##NAME(), #NAME, #ENAME); \
356 bool Load##NAME(CLAM::Storage & s) { \
359 if (! LoadIterableAttribute(s, Get##NAME(), #NAME, #ENAME)) { \