Leonardus
counter.h
Go to the documentation of this file.
1
17#pragma once
18
19#include "watermark.h"
20
21
25template <typename T>
26class Counter {
27 static inline size_t total_ = 0;
28 static inline Watermark watermark_ {};
30protected:
33 total_++;
35 }
36
38 Counter( const Counter<T> & /* unused */ ) {
39 total_++;
41 }
42
46 }
47
48
49public:
50 // Delete the remaining ctors, until we need them.
51 Counter<T> & operator=( const Counter<T> & /* unused */ ) = delete;
52 Counter( Counter<T> && /* unused */ ) = delete;
53 Counter<T> & operator=( Counter<T> && /* unused */ ) = delete;
54
55
56public: /* accessor */
58 static size_t getTotalCounter() {
59 return total_;
60 }
61
63 static size_t getAliveCounter() {
64 return watermark_.getCounter();
65 }
66
68 static size_t getWatermarkCounter() {
69 return watermark_.getWatermark();
70 }
71};
Counter base class.
Definition: counter.h:26
static Watermark watermark_
Counter and maximum of objects alive at a point in time.
Definition: counter.h:28
Counter()
Ctor.
Definition: counter.h:32
~Counter()
Dtor.
Definition: counter.h:44
static size_t getTotalCounter()
Static getter for totaly created objects.
Definition: counter.h:58
static size_t getAliveCounter()
Static getter for objects alive.
Definition: counter.h:63
Counter(const Counter< T > &)
Copy ctor.
Definition: counter.h:38
static size_t total_
Number of objects created.
Definition: counter.h:27
static size_t getWatermarkCounter()
Static getter for the object counter watermark.
Definition: counter.h:68
Watermark class.
Definition: watermark.h:26
size_t getWatermark() const
Getter for the watermark.
Definition: watermark.h:37
void dec()
Decrement counter.
Definition: watermark.h:49
size_t getCounter() const
Getter for counter.
Definition: watermark.h:33
void inc()
Increment counter and watermark if neccessary.
Definition: watermark.h:42
The class Watermark.