7 #include "Sti/Base/Factory.h"
20 template<
class Object>
33 template<
class Object>
39 int getSize()
const {
return kSize;}
48 template <
class Concrete,
class Abstract>
52 void free(Abstract *obj);
74 template <
class Object>
80 template <
class Object>
83 fNext=*bTop; *bTop=
this;
84 for (
int i=0;i<kSize;i++) {
85 fArr[i].fNext = *hTop;
91 template <
class Object>
94 memset(fChar,0,((
char*)&fObj)-fChar);
98 template <
class Concrete,
class Abstract>
102 this->
setName(
typeid(*this).name());
103 printf(
"*** Factory created *** %s\n",this->
getName().c_str());
105 template <
class Concrete,
class Abstract>
113 template <
class Concrete,
class Abstract>
116 enum {FENCE =
sizeof(double)+2*
sizeof(
long)+1};
118 assert(this->fCurCount < this->fMaxCount);
119 if (this->fFastDel) {
121 char *cBuf =
new char[nBuf];
124 assert(cBuf[nBuf-1]==46);
128 this->fCurCount += fBTop->getSize();
137 h->fLong= ((long)
this)+1;
141 template <
class Concrete,
class Abstract>
147 assert((h->fLong-1)== (
long)
this);
148 h->fNext = fHTop; fHTop=h; this->fUseCount--; this->fFreeCount++;
152 template <
class Concrete,
class Abstract>
160 if (this->fFastDel) {
delete [] d->fBuff;}
else {
delete d;}
164 fBTop=0; fHTop=0; this->fCurCount=0; this->fUseCount=0;
165 printf(
"*** %s::clear() %g MegaBytes Total %g Inst/Free=%d %d\n"
166 ,this->getName().c_str(),sz*1e-6
167 ,this->fgTotal,this->fInstCount,this->fFreeCount);
168 this->fInstCount=0; this->fFreeCount=0;
171 template <
class Concrete,
class Abstract>
174 if (!this->fUseCount)
return;
181 b->reset(&fBTop,&fHTop);
void reset()
Reset this factory.
void free(Abstract *obj)
Free an object for reuse.
void clear()
Clear/delete all objects owned by this factory.
void free(void *obj)
Free an object for reuse.
Abstract * getInstance()
Get a pointer to instance of objects served by this factory.
void setName(const string &newName)
Set the name of the object.
const string & getName() const
Get the name of the object.