Embedded Template Library 1.0
Loading...
Searching...
No Matches
instance_count.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2014 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_INSTANCE_COUNT_INCLUDED
32#define ETL_INSTANCE_COUNT_INCLUDED
33
34#include "platform.h"
35
36#include <stdint.h>
37
40
41namespace etl
42{
43 //***************************************************************************
46 //***************************************************************************
47 template <typename T, typename TCounter = int32_t>
49 {
50 public:
51
52 typedef T type;
53 typedef TCounter counter_type;
54
55 //*************************************************************************
57 //*************************************************************************
59 {
60 ++current_instance_count();
61 }
62
63 //*************************************************************************
65 //*************************************************************************
67 {
68 ++current_instance_count();
69 }
70
71 //*************************************************************************
73 //*************************************************************************
75 {
76 return *this;
77 }
78
79 //*************************************************************************
81 //*************************************************************************
83 {
84 --current_instance_count();
85 }
86
87 //*************************************************************************
89 //*************************************************************************
91 {
92 return current_instance_count();
93 }
94
95 //*************************************************************************
97 //*************************************************************************
99 {
100 current_instance_count() = 0;
101 }
102
103 private:
104
105 //*************************************************************************
107 //*************************************************************************
108 static counter_type& current_instance_count()
109 {
110 static counter_type counter = { 0 };
111 return counter;
112 }
113 };
114}
115
116#endif
117
Definition instance_count.h:49
instance_count & operator=(const instance_count &)
Assignment operator.
Definition instance_count.h:74
instance_count(const instance_count &)
Copy construct and add 1.
Definition instance_count.h:66
static void reset_instance_count()
Get how many instances we have.
Definition instance_count.h:98
instance_count()
Construct and add 1.
Definition instance_count.h:58
~instance_count()
Destruct and subtract 1.
Definition instance_count.h:82
static const counter_type & get_instance_count()
Get how many instances we have.
Definition instance_count.h:90
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164