QwAnalysis
QwObjectCounter.h
Go to the documentation of this file.
1 /**
2  * \file QwObjectCounter.h
3  * \brief Memory management class to count object instantiations
4  *
5  * \author wdconinc
6  * \date Nov 12, 2010
7  */
8 
9 #ifndef QWOBJECTCOUNTER_H_
10 #define QWOBJECTCOUNTER_H_
11 
12 
13 /**
14  * \class QwObjectCounter
15  * \ingroup QwAnalysis
16  *
17  * \brief Memory management structure to count objects
18  *
19  * This memory counter object can be publicly inherited from by Qweak classes.
20  * It applies the "curiously recurring template pattern", and I didn't make up
21  * that name.
22  */
23 template<typename T>
25 
26  public:
27 
28  /// Default constructor
31  ++fObjectsAlive;
32  };
33  /// Copy constructor
36  ++fObjectsAlive;
37  };
38  /// Destructor
39  virtual ~QwObjectCounter() {
40  --fObjectsAlive;
41  };
42 
43 
44  /// Get number of objects ever created
45  static size_t GetObjectsCreated() {
46  return fObjectsCreated;
47  };
48 
49  /// Get number of objects still alive
50  static size_t GetObjectsAlive() {
51  return fObjectsAlive;
52  };
53 
54  private:
55 
56  /// Number of objects ever created
57  static size_t fObjectsCreated;
58  /// Number of objects still alive
59  static size_t fObjectsAlive;
60 
61 };
62 
63 /// Initialize objects ever created counter
64 template<typename T>
66 
67 /// Initialize objects still alive counter
68 template<typename T>
70 
71 #endif /* QWOBJECTCOUNTER_H_ */
static size_t fObjectsCreated
Number of objects ever created.
static size_t fObjectsAlive
Number of objects still alive.
virtual ~QwObjectCounter()
Destructor.
QwObjectCounter(const QwObjectCounter &)
Copy constructor.
QwObjectCounter()
Default constructor.
Memory management structure to count objects.
static size_t GetObjectsAlive()
Get number of objects still alive.
static size_t GetObjectsCreated()
Get number of objects ever created.