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