CountedObject.h
Go to the documentation of this file.
1 #ifndef _utl_CountedObject_h_
2 #define _utl_CountedObject_h_
3 
4 #include <utl/CountedObjectRegistry.h>
5 
6 
7 namespace utl {
8 
29  template<class T>
30  class CountedObject {
31  public:
33  typedef T CountedType;
36 
44 
46  { return fgObjectsCopied; }
47 
49  { return fgObjectsAssigned; }
50 
51  protected:
53  {
54  if (!fgObjectsCreated++)
55  CountedObjectRegistry::RegisterCountedObject<CountedObject<T>>();
56  }
57 
59  {
60  if (!fgObjectsCreated++)
61  CountedObjectRegistry::RegisterCountedObject<CountedObject<T>>();
63  }
64 
66 
68  { ++fgObjectsAssigned; return *this; }
69 
70  private:
75  };
76 
77  template<class T>
79  template<class T>
81  template<class T>
83  template<class T>
85 
86 }
87 
88 
89 #endif
T CountedType
The type of the object we are counting.
Definition: CountedObject.h:33
CountedObject & operator=(const CountedObject &)
Definition: CountedObject.h:67
CountedObject(const CountedObject &)
Definition: CountedObject.h:58
static Counter fgObjectsAssigned
Definition: CountedObject.h:74
static Counter GetObjectsAssigned()
Definition: CountedObject.h:48
CountedObjectRegistry::Counter Counter
The (integer) type used to hold the counter.
Definition: CountedObject.h:35
static Counter GetObjectsCopied()
Definition: CountedObject.h:45
static Counter fgObjectsCreated
Definition: CountedObject.h:71
static Counter GetObjectsCreated()
number of calls to the constructor
Definition: CountedObject.h:38
static Counter GetObjectsExisting()
difference of number of calls to constructor and destructor
Definition: CountedObject.h:42
static Counter GetObjectsDestroyed()
number of calls to the destructor
Definition: CountedObject.h:40
static Counter fgObjectsCopied
Definition: CountedObject.h:73
virtual ~CountedObject()
Definition: CountedObject.h:65
Mix-in class for counting creation and destruction of objects.
Definition: CountedObject.h:30
static Counter fgObjectsDestroyed
Definition: CountedObject.h:72

, generated on Tue Sep 26 2023.