-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpccInstanceCounterPattern.h
More file actions
46 lines (31 loc) · 1.3 KB
/
cpccInstanceCounterPattern.h
File metadata and controls
46 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* *****************************************
* File: cpccInstanceCounterPattern.h
* Purpose: Portable (cross-platform), light-weight, file system library
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2015 StarMessage software.
* License: Free for opensource projects.
* Commercial license for closed source projects.
* Web: http://www.starmessagesoftware.com/cpcclibrary/
* Download: https://code.google.com/p/cpcc/
* https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include <atomic>
/** Abstract base class to perform instance counting.
Counts how many objects of a specific class were created.
Special functions onFirstCreate(), onLastDestroy can be overwritten
to allow clildren classes perform initialization/finalisation.
*/
class cpccInstanceCounterPattern
{
private:
std::atomic<int> &_nCount;
public: // ctor/dtor
explicit cpccInstanceCounterPattern(std::atomic<int> &aStaticCounter): _nCount(aStaticCounter) { ++_nCount; }
~cpccInstanceCounterPattern(void) { --_nCount; }
public: // functions
const int getInstancesCount(void) { return _nCount; }
};