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:
36
39 total_++;
41 }
42
43
45 Counter( const Counter<T> & /* unused */ ) {
46 total_++;
48 }
49
50
54 }
55
56public:
57
58 Counter<T> & operator=( const Counter<T> & /* unused */ ) = delete;
59 Counter( Counter<T> && /* unused */ ) = delete;
60 Counter<T> & operator=( Counter<T> && /* unused */ ) = delete;
61
62public: /* accessor */
63
65 static size_t getTotalCounter() {
66 return total_;
67 }
68
69
71 static size_t getAliveCounter() {
72 return watermark_.getCounter();
73 }
74
75
77 static size_t getWatermarkCounter() {
78 return watermark_.getWatermark();
79 }
80
81};
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:38
~Counter()
Dtor.
Definition counter.h:52
static size_t getTotalCounter()
Static getter for totaly created objects.
Definition counter.h:65
static size_t getAliveCounter()
Static getter for objects alive.
Definition counter.h:71
Counter(const Counter< T > &)
Copy ctor.
Definition counter.h:45
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:77
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.