Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
StaticID.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_STATICID_H_
9#define model_STATICID_H_
10
11#include <iostream>
12
13namespace model
14{
15
16 /************************************************************/
17 /************************************************************/
27 template<typename Derived>
29 {
30
31 // The increment
32 static size_t increment;
33
34 // The incremental counters
35 static size_t count;
36 static bool count_used;
37
38 public:
39
41 const size_t sID;
42
43 StaticID() : sID(count)
44 {
45 count_used=true;
46 count+=increment;
47 }
48
49 StaticID(const StaticID&) : sID(count)
50 {
51 count_used=true;
52 count+=increment;
53 }
54
55 static size_t nextID()
56 {
57 return count;
58 }
59
60 static size_t& get_count()
61 {
62 return count;
63 }
64
65 static void set_count(const size_t& newCount)
66 {
67// model_checkInput(newCount>=count && "YOU ARE TRYING TO SET THE COUNTER TO A LOWER VALUE THAN THE CURRENT ONE.");
68 if(newCount<count)
69 {
70 std::cout<<"newCount="<<newCount<<std::endl;
71 std::cout<<"count="<<count<<std::endl;
72 throw std::runtime_error("StaticID::set_count newCount<count");
73 }
74// assert(newCount>=count && "YOU ARE TRYING TO SET THE COUNTER TO A LOWER VALUE THAN THE CURRENT ONE.");
75 count = newCount;
76 count_used=false;
77 }
78
79 static void force_count(const size_t& newCount)
80 {
81 count = newCount;
82 count_used=false;
83 }
84
85 static void set_increment(const size_t& newIncrement)
86 {
87// model_checkInput(newIncrement>=1 && "newIncrement MUST BE >=1.");
88// assert(newIncrement>=1 && "newIncrement MUST BE >=1.");
89 if(newIncrement<1)
90 {
91 throw std::runtime_error("StaticID::set_count newIncrement<1");
92 }
93 if(count_used)
94 {
95 count-=increment;
96 count+=newIncrement;
97 }
98 increment = newIncrement;
99 }
100 };
101
102 template<typename Derived>
103 size_t StaticID<Derived>::increment = 1;
104
105 template<typename Derived>
106 size_t StaticID<Derived>::count = 0;
107
108 template<typename Derived>
109 bool StaticID<Derived>::count_used = false;
110
111} // namespace model
112#endif
StaticID(const StaticID &)
Definition StaticID.h:49
static void set_count(const size_t &newCount)
Definition StaticID.h:65
static size_t nextID()
Definition StaticID.h:55
static void force_count(const size_t &newCount)
Definition StaticID.h:79
static size_t & get_count()
Definition StaticID.h:60
const size_t sID
The static ID of this.
Definition StaticID.h:41
static void set_increment(const size_t &newIncrement)
Definition StaticID.h:85