56 for (
unsigned i=0; i <
numAttr; i++)
68 bPreAllocateAllAttributes =
false;
83 bPreAllocateAllAttributes =
false;
89 SelfDeepCopy(prototype);
91 SelfShallowCopy(prototype);
93 SelfSharedCopy(prototype);
96 SelfCopyPrototype(prototype);
108 bPreAllocateAllAttributes = prototype.bPreAllocateAllAttributes;
112 SelfDeepCopy(prototype);
114 SelfCopyPrototype(prototype);
116 # ifdef CLAM_EXTRA_CHECKS_ON_DT
118 # endif //CLAM_EXTRA_CHECKS_ON_DT
127 void DynamicType::RemoveAllMem()
129 # ifdef CLAM_EXTRA_CHECKS_ON_DT
131 # endif //CLAM_EXTRA_CHECKS_ON_DT
135 for (
unsigned i=0; i<
numAttr; i++)
154 void DynamicType::InformAttr_(
unsigned val,
const char* name,
unsigned size,
const char* type,
const bool isPtr,
155 const t_new fnew,
const t_new_copy fcopy,
const t_destructor fdestr)
158 "There are more registered Attributes than the "
159 "number defined in DYN_CLASS_TABLE macro.");
160 CLAM_ASSERT(fnew,
"in DT: a dynamic attribute don't have default-constructor !");
161 CLAM_ASSERT(fcopy,
"in DT: a dynamic attribute don't have copy constructor !");
201 for (
unsigned int j=0; j<
numAttr; j++) {
207 # ifdef CLAM_EXTRA_CHECKS_ON_DT
209 # endif //CLAM_EXTRA_CHECKS_ON_DT
213 if (AttrHasData(val))
return;
234 # ifdef CLAM_EXTRA_CHECKS_ON_DT
236 # endif //CLAM_EXTRA_CHECKS_ON_DT
255 for (
unsigned int j=0; j<
numAttr; j++) {
261 # ifdef CLAM_EXTRA_CHECKS_ON_DT
263 # endif //CLAM_EXTRA_CHECKS_ON_DT
267 if (!AttrHasData(i) || !
data)
return;
287 # ifdef CLAM_EXTRA_CHECKS_ON_DT
289 # endif //CLAM_EXTRA_CHECKS_ON_DT
299 # ifdef CLAM_EXTRA_CHECKS_ON_DT
301 # endif //CLAM_EXTRA_CHECKS_ON_DT
321 UpdateDataByShrinking();
327 UpdateDataGoingToPreAllocatedMode();
333 UpdateDataInPreAllocatedMode();
339 UpdateDataByStandardMode();
341 # ifdef CLAM_EXTRA_CHECKS_ON_DT
343 # endif //CLAM_EXTRA_CHECKS_ON_DT
349 void DynamicType::BeMemoryOwner()
353 char* originalData =
data;
359 memcpy(
dynamicTable, originalTable,
sizeof(TDynInfo)*(numAttr+1));
365 for(
unsigned i=0; i<
numAttr; i++)
370 fnewcp(
data+offs, originalData+originalTable[i].offs);
390 void DynamicType::UpdateDataByShrinking()
393 std::list< std::pair<int,int> > attrList(numAttr);
394 std::list< std::pair<int,int> >::iterator it;
397 for (it=attrList.begin(); it!=attrList.end(); it++)
407 for (it=attrList.begin(); it!=attrList.end(); it++)
428 else if (AttrHasData(j) &&
dynamicTable[j].hasBeenRemoved)
455 void DynamicType::UpdateDataByStandardMode ()
457 char* olddata =
data;
461 for (
unsigned int i=0; i<
numAttr; i++)
469 dest (olddata+inf.offs);
470 inf.hasBeenRemoved =
false;
477 newc(
data+offs,olddata+inf.offs);
478 dest(olddata+inf.offs);
485 if (inf.hasBeenAdded)
489 inf.hasBeenAdded =
false;
504 void DynamicType::UpdateDataGoingToPreAllocatedMode()
507 char* olddata =
data;
521 dest (olddata+inf.offs);
522 inf.hasBeenRemoved =
false;
530 newc(
data+offs,olddata+inf.offs);
531 dest(olddata+inf.offs);
537 if (inf.hasBeenAdded)
541 inf.hasBeenAdded =
false;
554 void DynamicType::UpdateDataInPreAllocatedMode()
559 for (
unsigned int i=0; i<
numAttr; i++)
568 dest (
data+inf.offs);
569 inf.hasBeenRemoved =
false;
576 if (inf.hasBeenAdded)
580 inf.hasBeenAdded =
false;
638 void DynamicType::SelfCopyPrototype(
const DynamicType &prototype)
650 bPreAllocateAllAttributes = prototype.bPreAllocateAllAttributes;
654 void DynamicType::SelfSharedCopy(
const DynamicType &prototype)
656 SelfCopyPrototype(prototype);
658 data = prototype.data;
663 void DynamicType::SelfShallowCopy(
const DynamicType &prototype)
666 !prototype.dynamicTable[prototype.numAttr].hasBeenAdded &&
667 !prototype.dynamicTable[prototype.numAttr].hasBeenRemoved,
668 "making a copy of a non-updated DT is not allowed since the copy share the same dynamic-info"
670 if (
this==&prototype)
return;
672 SelfCopyPrototype(prototype);
680 void* pos = GetPtrToData_(i);
682 fcopy(pos, prototype.GetPtrToData_(i));
686 void DynamicType::SelfDeepCopy(
const DynamicType &prototype)
689 !prototype.dynamicTable[prototype.numAttr].hasBeenAdded &&
690 !prototype.dynamicTable[prototype.numAttr].hasBeenRemoved,
691 "making a copy of a non-updated DT is not allowed since the copy share the same dynamic-info"
693 if (
this==&prototype)
return;
695 SelfCopyPrototype(prototype);
702 Component** copyChildren =
new Component * [prototype.numAttr];
707 copyChildren[i] = static_cast<Component*>(prototype.GetDataAsPtr_(i))->
DeepCopy();
715 void* pos = GetPtrToData_(i);
717 SetDataAsPtr_(i, copyChildren[i]);
723 fcopy(pos, prototype.GetPtrToData_(i));
726 delete [] copyChildren;
733 SelfDeepCopy(source);
735 # ifdef CLAM_EXTRA_CHECKS_ON_DT
737 # endif //CLAM_EXTRA_CHECKS_ON_DT
750 throw ErrDynamicType(
"in FullfilsInvariant: there's no typeDescTable. "
751 "The most likely thing is that the object is "
752 "created with a non-macro-expanded-constructor."
753 "In that case the constructor MUST call the"
754 "MandatoryInit() method (called from constructor). Check it !");
759 unsigned auxAllocatedSize=0;
760 bool someAdded =
false, someRemoved =
false;
761 int incData=0, decData=0;
766 for (
unsigned i=0; i<
numAttr; i++)
777 if (dyninfo.
offs < -1)
778 throw ErrDynamicType(
"in FullfilsInvariant: a dynamic offset < -1");
781 no data (offs==-1) but do has the hasBeenRemoved flag set. Class: ",
GetClassName() );
785 data (offs>0) but do has the hasBeenAdded flag set. Class: ",
GetClassName() );
787 if (dyninfo.
offs >= 0)
791 if (usedblock[j])
throw ErrDynamicType(
"in FullfilsInvariant: overlaped area in data table");
792 else usedblock[j]=
true;
797 if (!
data)
throw ErrDynamicType(
"in FullfilsInvariant: An attr. has data but data==0");
802 else if (dyninfo.
offs != -1)
803 throw ErrDynamicType(
" in FullfilsInvariant: attribute not informed with dynamic offset <> -1");
806 if (!bPreAllocateAllAttributes) {
807 if (auxAllocatedSize+incData-decData !=
dataSize)
809 if (auxAllocatedSize + incData - decData !=
dataSize)
812 if (auxAllocatedSize > allocatedDataSize)
816 if (
dynamicTable[numAttr].hasBeenRemoved != someRemoved)
826 std::cout <<std::endl<<
"Class Name: "<<
GetClassName() <<
" at: " <<
this <<std::endl <<
"[#attr.], dyn_offs,statc_offs,name,type,{comp,dynType,ptr,strble},exist,size,Ptr"\
827 << std::endl <<
"------------------------------------------------------------------------------"<<std::endl;
830 for (
unsigned i=0; i<
numAttr; i++)
835 std::cout << std::endl;
837 else std::cout <<
" -";
839 else std::cout <<
"-";
842 std::cout <<
" [" <<i<<
"] ";
844 std::cout << dyninf.
offs <<
" , "<<attr->
offset<<
" , "<<attr->
id<<
" , "<<attr->
type<<
" , {"\
849 std::cout << GetPtrToData_(i);
853 std::cout<<std::endl;
858 #endif// CLAM_USE_XML