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
26template <typename T>
27class Counter {
28 static inline size_t total_ = 0;
29 static inline Watermark watermark_ {};
31protected:
34 total_++;
36 }
37
39 Counter( const Counter<T> & /* unused */ ) {
40 total_++;
42 }
43
47 }
48
49
50public:
51 // Delete the remaining ctors, until we need them.
52 Counter<T> & operator=( const Counter<T> & /* unused */ ) = delete;
53 Counter( Counter<T> && /* unused */ ) = delete;
54 Counter<T> & operator=( Counter<T> && /* unused */ ) = delete;
55
56
57public: /* accessor */
59 static size_t getTotalCounter() {
60 return total_;
61 }
62
64 static size_t getAliveCounter() {
65 return watermark_.getCounter();
66 }
67
69 static size_t getWatermarkCounter() {
70 return watermark_.getWatermark();
71 }
72};
Counter base class.
Definition counter.h:27
static Watermark watermark_
Counter and maximum of objects alive at a point in time.
Definition counter.h:29
Counter()
Ctor.
Definition counter.h:33
~Counter()
Dtor.
Definition counter.h:45
static size_t getTotalCounter()
Static getter for totaly created objects.
Definition counter.h:59
static size_t getAliveCounter()
Static getter for objects alive.
Definition counter.h:64
Counter(const Counter< T > &)
Copy ctor.
Definition counter.h:39
static size_t total_
Number of objects created.
Definition counter.h:28
static size_t getWatermarkCounter()
Static getter for the object counter watermark.
Definition counter.h:69
Watermark class.
Definition watermark.h:28
size_t getWatermark() const
Getter for the watermark.
Definition watermark.h:39
void dec()
Decrement counter.
Definition watermark.h:53
size_t getCounter() const
Getter for counter.
Definition watermark.h:35
void inc()
Increment counter and watermark if neccessary.
Definition watermark.h:44
The class Watermark.