DiaDes  0.1
DIAgnosis of Discrete-Event System
IdGenerators.hh
Go to the documentation of this file.
1 
9 #ifndef __DIADES__UTILS__IDGENERATORS__HH__
10 #define __DIADES__UTILS__IDGENERATORS__HH__
11 
12 #include<string>
13 
14 namespace Diades
15 {
16  namespace Utils
17  {
18 
26  template<typename GeneratedType>
28  {
29  public:
34  virtual void init() = 0;
39  virtual GeneratedType another() = 0;
40  };
41 
46  class PrefixedCounterIdGenerator : public IdGenerator<std::string>
47  {
48  public:
49  using BasicString = std::string;
51 
52  private:
54  size_t _initial;
55  size_t _counter;
56 
57  public:
58 
62  PrefixedCounterIdGenerator() = default;
63 
64 
75  PrefixedCounterIdGenerator& operator=(PrefixedCounterIdGenerator const& other) = default;
86  PrefixedCounterIdGenerator& operator=(PrefixedCounterIdGenerator&& other) = default;
87 
91  virtual ~PrefixedCounterIdGenerator() = default;
92 
98  PrefixedCounterIdGenerator(const std::string & prefix) : IdGen(), _prefix(prefix), _initial(0), _counter(0)
99  {
100  }
101 
108  PrefixedCounterIdGenerator(const std::string & prefix, size_t counter) : IdGen(), _prefix(prefix), _initial(counter), _counter(counter)
109  {
110  }
111 
115  virtual void
117  {
118  _counter = _initial;
119 
120  }
121 
127  virtual std::string
129  {
130  return _prefix + std::to_string(_counter++);
131  }
132  };
133 
139  template<typename IncrementableType>
140  class
142  {
143  public:
144 
146 
147  private:
148  IncrementableType _initial;
149  IncrementableType _current;
150  public:
151 
155  IncrementGenerator() = default;
156 
157 
162  IncrementGenerator(IncrementGenerator const& other) = default;
168  IncrementGenerator& operator=(IncrementGenerator const& other) = default;
173  IncrementGenerator(IncrementGenerator&& other) = default;
179  IncrementGenerator& operator=(IncrementGenerator&& other) = default;
180 
184  virtual ~IncrementGenerator() = default;
185 
186 
193  IncrementGenerator(IncrementableType initialValue) : IdGen(), _initial(initialValue), _current(initialValue)
194  {
195  }
196 
201  virtual void
203  {
204  _current = _initial;
205  }
206 
212  virtual IncrementableType
214  {
215  return _current++;
216  }
217 
218  };
219 
220  }
221 }
222 
223 
224 
225 #endif /* __DIADES__UTILS__IDGENERATORS__HH__ */
226 
virtual IncrementableType another()
IncrementGenerator(IncrementableType initialValue)
PrefixedCounterIdGenerator(const std::string &prefix)
Definition: IdGenerators.hh:98
virtual GeneratedType another()=0
Namespace of the Diades project.
PrefixedCounterIdGenerator(const std::string &prefix, size_t counter)