DiaDes  0.1
DIAgnosisofDiscrete-EventSystem
Value.hh
Go to the documentation of this file.
1 #ifndef __DIADES__SDMDL__VALUE__HH
2 #define __DIADES__SDMDL__VALUE__HH
3 
4 #include<string>
5 #include<vector>
6 #include<unordered_map>
9 
10 
11 namespace Diades
12 {
13  namespace Sdmdl
14  {
15 
16 
17  class ValueFactory;
18 
25  class Value
26  {
27  public:
28  static std::string typeName() { return "Diades::Sdmdl::Value"; }
30 
31  public:
32  typedef std::reference_wrapper<Value const> ConstReference;
33  typedef std::reference_wrapper<Value> Reference;
34  typedef std::vector<ConstReference> ValueVector;
35  typedef Value * Pointer;
36 
37 
38  private:
39 
43  unsigned _id;
44 
45 
50 
51 
52 
56  std::string _label;
57 
58  private:
59 
65  Value(ValueFactory & owner):_id(0),_owner(owner),_label("__null__diades__sdmdl_value"){}
66 
67 
68 
76  Value(const std::string & label, unsigned id, ValueFactory & owner):_id(id),_owner(owner),
77  _label(label){}
78 
79 
80  public:
81 
86  ~Value(){}
87 
94  bool isNull() const;
95 
102  unsigned id() const
103  {
104  return _id;
105  }
106 
113  const std::string & label() const
114  {
115  return _label;
116  }
117 
118 
119 
127  bool operator == (const Value & val) const
128  { return this == &val; }
129 
130 
138  bool operator != (const Value & val) const { return !(*this == val); }
139 
140 
149  bool operator < (const Value & val) const
150  {
151  require(Exception,&_owner == &val._owner,"operator<: not the same owner");
152  return label() < val.label();
153  }
154 
155 
162  const ValueFactory & owner() const
163  {
164  return _owner;
165  }
166 
167 
176  friend ostream & operator << (ostream & os, const Value & val);
177 
178 
179 
180  friend class ValueFactory;
181  };
182 
183 
188 
189 
198  {
199 
200  public:
201  static std::string typeName() { return "Diades::Sdmdl::ValueFactory"; }
203 
204 
205  private:
209  std::unordered_map<std::string,Value::Pointer> _dictionary;
210 
211 
212 
216  ValueVector _nullValue;
217 
218 
219 
220  public:
221 
226  ValueFactory():_dictionary(),_nullValue()
227  {
228  reset();
229  }
230 
231 
232 
238  {
239  clear();
240  }
241 
242 
247  void reset();
248 
249 
254  void clear();
255 
256 
264  bool operator==(const ValueFactory & factory) const
265  {
266  return this == &factory;
267  }
268 
269 
277  const Value & newValue(const std::string & label);
278 
286  const Value & getValue(const std::string & label) const;
287 
294  const Value & nullValue() const
295  {
296  return _nullValue[0];
297  }
298 
299  };
300 
301 
302 
303 
304 
305  };
306 };
307 
308 
309 
310 
311 #endif
static std::string typeName()
Definition: Value.hh:201
std::vector< ConstReference > ValueVector
Definition: Value.hh:34
ValueFactory & _owner
Definition: Value.hh:49
bool operator==(const ValueFactory &factory) const
Definition: Value.hh:264
Value * Pointer
Definition: Value.hh:35
friend ostream & operator<<(ostream &os, const Value &val)
std::string _label
Definition: Value.hh:56
ValueVector _nullValue
Definition: Value.hh:216
bool operator<(const Value &val) const
Definition: Value.hh:149
std::unordered_map< std::string, Value::Pointer > _dictionary
Definition: Value.hh:209
Diades::Utils::Exception< ValueFactory > Exception
Definition: Value.hh:202
Value(const std::string &label, unsigned id, ValueFactory &owner)
Definition: Value.hh:76
std::reference_wrapper< Value const > ConstReference
Definition: Value.hh:32
unsigned _id
Definition: Value.hh:43
bool isNull() const
#define require(Exception, expr, message)
Definition: Assertion.hh:89
Namespace of the Diades project.
bool operator!=(const Value &val) const
Definition: Value.hh:138
const std::string & label() const
Definition: Value.hh:113
bool operator==(const Value &val) const
Definition: Value.hh:127
const ValueFactory & owner() const
Definition: Value.hh:162
Diades::Utils::Exception< Value > Exception
Definition: Value.hh:29
static std::string typeName()
Definition: Value.hh:28
Value(ValueFactory &owner)
Definition: Value.hh:65
const Value & nullValue() const
Definition: Value.hh:294
unsigned id() const
Definition: Value.hh:102
std::reference_wrapper< Value > Reference
Definition: Value.hh:33