oILAB
Loading...
Searching...
No Matches
StaticID.h
Go to the documentation of this file.
1/* This file is part of gbLAB.
2 *
3 * gbLAB is distributed without any warranty under the MIT License.
4 */
5
6
7#ifndef gbLAB_STATICID_H_
8#define gbLAB_STATICID_H_
9
10
11namespace gbLAB
12{
13
14 /************************************************************/
15 /************************************************************/
25 template<typename Derived>
27 {
28
29 // The increment
30 static size_t increment;
31
32 // The incremental counters
33 static size_t count;
34 static bool count_used;
35
36 public:
37
39 const size_t sID;
40
41 /**********************************************************************/
43 {
44 count_used=true;
46 }
47
48 /**********************************************************************/
50 {
51 count_used=true;
53 }
54
55 /**********************************************************************/
56 static size_t nextID()
57 {
58 return count;
59 }
60
61 static size_t& get_count()
62 {
63 return count;
64 }
65
66 /**********************************************************************/
67 static void set_count(const size_t& newCount)
68 {
69 if (newCount<count)
70 {
71 throw std::runtime_error("StaticID error: YOU ARE TRYING TO SET THE COUNTER TO A LOWER VALUE THAN THE CURRENT ONE\n");
72 }
73 count = newCount;
74 count_used=false;
75 }
76
77 /**********************************************************************/
78 static void set_increment(const size_t& newIncrement)
79 {
80 if (newIncrement<1)
81 {
82 throw std::runtime_error("StaticID error: newIncrement MUST BE >=1\n");
83 }
84 if(count_used)
85 {
87 count+=newIncrement;
88 }
89 increment = newIncrement;
90 }
91
92 };
93
94 /* Static data members *****************************/
95 template<typename Derived>
97
98 template<typename Derived>
99 size_t StaticID<Derived>::count = 0;
100
101 template<typename Derived>
103
104} // namespace gbLAB
105#endif
A class template that implements a counter of the number of instances of Derived type that are create...
Definition StaticID.h:27
static size_t count
Definition StaticID.h:33
static void set_count(const size_t &newCount)
Definition StaticID.h:67
static size_t & get_count()
Definition StaticID.h:61
static bool count_used
Definition StaticID.h:34
const size_t sID
The static ID of this.
Definition StaticID.h:39
static size_t nextID()
Definition StaticID.h:56
static size_t increment
Definition StaticID.h:30
static void set_increment(const size_t &newIncrement)
Definition StaticID.h:78
StaticID(const StaticID &)
Definition StaticID.h:49