Leonardus
Loading...
Searching...
No Matches
counter.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Medium
20#include "watermark.h"
21
22
23// IDEA: This class is not thread-safe. Concurrent access to the counters may lead to race conditions.
24
29template <typename T>
30class Counter {
31
32 static inline size_t total_ = 0;
33 static inline Watermark watermark_ {};
35protected:
38 total_++;
40 }
41
42
44 Counter( const Counter<T> & /* unused */ ) {
45 total_++;
47 }
48
49
53 }
54
55
56public:
57 Counter<T> & operator=( const Counter<T> & /* unused */ ) = delete;
58 Counter( Counter<T> && /* unused */ ) = delete;
59 Counter<T> & operator=( Counter<T> && /* unused */ ) = delete;
60
61
62public: /* accessor */
64 static size_t getTotalCounter() {
65 return total_;
66 }
67
68
70 static size_t getAliveCounter() {
71 return watermark_.getCounter();
72 }
73
74
76 static size_t getWatermarkCounter() {
77 return watermark_.getWatermark();
78 }
79
80};
Counter base class.
Definition counter.h:30
static Watermark watermark_
Counter and maximum of objects alive at a point in time.
Definition counter.h:33
Counter()
Ctor.
Definition counter.h:37
~Counter()
Dtor.
Definition counter.h:51
static size_t getTotalCounter()
Static getter for totaly created objects.
Definition counter.h:64
static size_t getAliveCounter()
Static getter for objects alive.
Definition counter.h:70
Counter(const Counter< T > &)
Copy ctor.
Definition counter.h:44
static size_t total_
Number of objects created.
Definition counter.h:32
static size_t getWatermarkCounter()
Static getter for the object counter watermark.
Definition counter.h:76
Watermark class.
Definition watermark.h:28
size_t getWatermark() const
Getter for the watermark.
Definition watermark.h:40
void dec()
Decrement counter.
Definition watermark.h:53
size_t getCounter() const
Getter for counter.
Definition watermark.h:36
void inc()
Increment counter and watermark if neccessary.
Definition watermark.h:45
The class Watermark.