StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Factory.h
1 #ifndef Factory_H
2 #define Factory_H
3 
4 #include "Sti/Base/Named.h"
5 #include <cassert>
6 
16 class BFactory : public Named
17 {
18 protected:
19 
20  BFactory(const string& name);
21 
22  virtual ~BFactory()
23  {;}
24 
25 public:
27  virtual void clear()=0;
28 
30  virtual void reset()=0;
31 
33  virtual void free(void *obj)=0;
34 
36  static void Free(void *obj);
37 
38  void setFastDelete() {fFastDel=1;}
39  void setMaxIncrementCount(int maxCount) {fMaxCount=maxCount;}
40  int getMaxIncrementCount() const {return fMaxCount; }
41  int getCurrentSize() const {return fCurCount; }
42  int getCurrentCount() const {return fCurCount; }
43 protected:
44  int fMaxCount;
45  int fCurCount;
46  int fUseCount;
47  int fFastDel;
48  int fInstCount;
49  int fFreeCount;
50 static double fgTotal;
51 };
52 
53 template <class Abstract>
54 class Factory : public BFactory
55 {
56 public:
57 
58  Factory(const string& name): BFactory(name)
59  {;}
60 
61  virtual ~Factory()
62  {;}
63 
65  virtual void free(Abstract *obj)=0;
66  virtual void free(void *obj)=0;
67 
69  virtual Abstract *getInstance()=0;
70 
71 };
72 
73 inline void BFactory::Free(void *obj)
74 {
75  long *v = ((long*)obj) - 1;
76  if (!*v) v--;
77  assert((*v)&1L);
78  BFactory *f = (BFactory*)((*v)-1);
79  f->free(obj);
80 }
81 
82 #endif
virtual void free(void *obj)=0
Free an object for reuse.
virtual void free(Abstract *obj)=0
Free an object for reuse.
Definition: Named.h:16
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
static void Free(void *obj)
Free an object for reuse.
Definition: Factory.h:73
virtual void reset()=0
Reset this factory.
virtual void clear()=0
Clear/delete all objects owned by this factory.