DiaDes  0.1
DIAgnosis of Discrete-Event System
Variable.hh
Go to the documentation of this file.
1 #ifndef __DIADES__ALTARICA__VARIABLE__HH
2 #define __DIADES__ALTARICA__VARIABLE__HH
3 
4 #include<vector>
5 #include "Domains.hh"
10 using namespace std;
11 
12 namespace Diades
13 {
14 
15  namespace Altarica
16  {
17 
20 
21 
22  class Variable;
32  {
33 
34 
35  private:
38  union
39  {
40  map<Identifier,Variable> * _structure;
41  vector<Variable> * _array;
42  } _fields;
43  set<Identifier> _fieldName;
44  set<Identifier> _attrib;
45  void * _scope;
48  unsigned _id;
49  bool _isFree;
50 
55  void createStructureVariables(const set<Identifier> & attributes, const StructureDomainData * domainData);
56 
62  void createArrayVariables(const set<Identifier> & attributes, const ArrayDomainData * domainData);
63 
64 
73  VariableData(const Identifier & label, Domain domain,
74  const set<Identifier> & attributes,
75  unsigned id);
76 
84  VariableData(const Identifier & label,
85  const set<Variable> & variables,
86  unsigned id,
87  Node node);
88 
97  VariableData(const Identifier & label, Domain domain,
98  const set<Identifier> & attributes,
99  unsigned id,
100  Node node);
101 
102 
111  VariableData(const Identifier & label,
112  const set<Variable> & variables,
113  const set<Identifier> & attributes,
114  unsigned id,
115  Node node);
116 
117 
118 
127  VariableData(const Identifier & label, Domain domain,
128  const set<Identifier> & attributes,
129  unsigned id,
130  Variable variable);
131 
132  // /**
133  // Parmetrised constructor
134  // @param label Label of the Variable
135  // @param domain Domain of the Variable
136  // @param fields Fields of the Variable if the Variable is a structure, empty otherwise
137  // @param attributes Attributes of the Variable empty otherwise
138  // @param id the id of the Variable
139  // @param function The scope of the variable
140  // **/
141  // VariableData(const Identifier & label, Domain domain
142  // const vector<Identifier> & attributes,
143  // const vector<Variable> & fields,
144  // unsigned id,
145  // Function function);
146 
147  // /**
148  // Parmetrised constructor
149  // @param label Label of the Variable
150  // @param domain Domain of the Variable
151  // @param fields Fields of the Variable if the Variable is a structure, empty otherwise
152  // @param attributes Attributes of the Variable empty otherwise
153  // @param id the id of the Variable
154  // @param formula The scope of the variable
155  // **/
156  // VariableData(const Identifier & label, Domain domain
157  // const vector<Identifier> & attributes,
158  // const vector<Variable> & fields,
159  // unsigned id,
160  // FirstOrderFormula formula);
161 
162  public:
166  VariableData();
167 
171  ~VariableData();
172 
173 
174  friend class VariableFactory;
175  friend class Variable;
176  };
177 
178 
179  /*********************************************************************************/
180 
188  class Variable
189  {
190 
191  public:
192 
193  typedef set<Identifier>::const_iterator AttributeIterator;
194  typedef set<Identifier>::const_iterator FieldNameIterator;
195 
196  private:
197 
199 
204  Variable(VariableData * data):_data(data){}
205 
206 
207  public:
211  Variable():_data(0){}
212 
217  Variable(const Variable & variable):_data(variable._data){}
218 
225  Variable & operator=(const Variable & variable)
226  {
227  if(this != &variable)
228  {
229  _data = variable._data;
230  }
231  return *this;
232  }
233 
239  bool operator==(const Variable & variable) const
240  {
241  return _data == variable._data;
242  }
243 
249  bool operator!=(const Variable & variable) const
250  {
251  return !( *this == variable);
252  }
253 
259  bool operator<(const Variable & variable) const
260  {
261  return _data < variable._data;
262  }
263 
269  bool operator<=(const Variable & variable) const
270  {
271  return ((*this) == variable) || ((*this) < variable);
272  }
273 
278  bool valid() const
279  {
280  return _data != 0;
281  }
282 
287  Domain domain() const
288  {
289  if(valid()) { return _data->_domain; } return Domain();
290  }
291 
296  Type type() const { if(valid()) { return domain().type(); } return Type(); }
297 
302  bool isSimple() const
303  {
304 
305  return valid() && domain().type().isBasic();
306  }
307 
312  bool isStructure() const
313  {
314  return valid() && domain().type().isStructure();
315  }
316 
321  bool isArray() const
322  {
323  return valid() && domain().type().isArray();
324  }
325 
326 
331  unsigned size() const;
332 
336  DomainCategory category() const { return domain().category(); }
337 
338 
344  bool isFree() const;
345 
346 
350  Value value() const;
351 
352 
360  bool setValue(const Value & value);
361 
368  bool makeFree();
369 
370 
374  ~Variable() { _data = 0; }
375 
380  {
381  if(!valid()) { return ""; } return _data->_label;
382  }
383 
388  AttributeIterator attributeBegin() const;
389 
394  AttributeIterator attributeEnd() const;
395 
396 
397 
403  Variable getField(unsigned index) const;
404 
405 
409  FieldNameIterator fieldBegin() const;
410 
414  FieldNameIterator fieldEnd() const;
420  Variable getField(const Identifier & identifier) const;
421 
427  {
428  if(valid())
429  {
430  return _data->_scopeType;
431  }
432  return NoScope;
433  }
434 
435 
440  Node nodeScope() const;
441 
447  {
448  if(!valid())
449  {
450  return Variable();
451  }
452  if(scopeType() != VariableScp)
453  {
454  return Variable();
455  }
456  return *(static_cast<Variable *>(_data->_scope));
457  }
458 
459  friend ostream & operator<<(ostream & os, const Variable & var)
460  {
461  return os << var.label();
462  }
463 
464  //Function functionScope() const;
465  //FirstOrderFormula firstOrderFormulaScope() const;
466  friend class VariableFactory;
467  friend class VariableData;
468  };
469 
470 
471  /******************************************************************************/
472 
479  {
480  private:
481  unordered_map<Identifier,Variable> _modelVariableOfLabel;
482  vector<Variable> _modelVariables;
483  vector< unordered_map<Identifier,Variable> > _nodeVariables;
484  //vector< unordered_map<Identifier,Variable > > _funcVariables;
485  //vector< unordered_map<Identifier,Variable > > _folVariables;
486  vector<Variable> _internalVariables;
487  set<Identifier> _emptyAttributes;
488  set<Identifier> _emptyFields;
489 
491 
492 
502  Variable newSimpleVariable(const Identifier & label,
503  Domain domain,
504  const set<Identifier> & attributes);
505 
506 
517  Variable newSimpleVariable(const Identifier & label,
518  Domain domain,
519  const set<Identifier> & attributes,
520  Node node);
521 
532  Variable newSimpleVariable(const Identifier & label,
533  Domain domain,
534  const set<Identifier> & attributes,
535  Variable variable);
536 
546  Variable newStructureVariable(const Identifier & label,
547  Domain domain,
548  const set<Identifier> & attributes);
549 
550 
560  Variable newStructureVariable(const Identifier & label,
561  const set<Variable> & variables, Node node);
562 
563 
574  Variable newStructureVariable(const Identifier & label,
575  Domain domain,
576  const set<Identifier> & attributes,
577  Node node);
578 
589  Variable newStructureVariable(const Identifier & label,
590  Domain domain,
591  const set<Identifier> & attributes,
592  Variable variable);
593 
603  Variable newArrayVariable(const Identifier & label,
604  Domain domain,
605  const set<Identifier> & attributes);
606 
617  Variable newArrayVariable(const Identifier & label,
618  Domain domain,
619  const set<Identifier> & attributes,
620  Node node);
631  Variable newArrayVariable(const Identifier & label,
632  Domain domain,
633  const set<Identifier> & attributes,
634  Variable variable);
635  public:
639  VariableFactory();
640 
641 
645  ~VariableFactory();
646 
650  static VariableFactory * factory();
651 
652 
653 
654  const set<Identifier> & emptyAttributes() const
655  {
656  return _emptyAttributes;
657  }
658 
659 
660 
661  const set<Identifier> & emptyFields() const
662  {
663  return _emptyAttributes;
664  }
665 
666 
667 
676  Variable newVariable(const Identifier & label, Domain domain,
677  const set<Identifier> & attributes);
678 
688  Variable newVariable(const Identifier & label, Domain domain,
689  const set<Identifier> & attributes,
690  Node node);
691 
692 
693 
702  Variable newVariable(const Identifier & label, const set<Variable> & variables,
703  Node node);
704 
705 
706 
707 
708 
718  Variable newVariable(const Identifier & label, Domain domain,
719  const set<Identifier> & attributes,
720  Variable variable);
721  };
722 
723 
724 
733  Variable newVariable(const Identifier & label, Domain domain,
734  const set<Identifier> & attributes);
735 
745  Variable newVariable(const Identifier & label, Domain domain,
746  const set<Identifier> & attributes,
747  Node node);
748 
749 
750 
759  Variable newVariable(const Identifier & label, const set<Variable> & variables,
760  Node node);
761 
762 
763 
764 
765 
775  Variable newVariable(const Identifier & label, Domain domain,
776  const set<Identifier> & attributes,
777  Variable variable);
778 
779 
780 
781 
782 
783  };
784 
785 
786 };
787 #endif
VariableData * _data
Definition: Variable.hh:198
friend ostream & operator<<(ostream &os, const Variable &var)
Definition: Variable.hh:459
DomainCategory category() const
Definition: Variable.hh:336
Value _value
The scope type of the variable.
Definition: Variable.hh:47
Identifier label() const
Definition: Variable.hh:379
set< Identifier >::const_iterator FieldNameIterator
iterator on the attributes
Definition: Variable.hh:194
const set< Identifier > & emptyFields() const
Definition: Variable.hh:661
bool operator==(const Variable &variable) const
Definition: Variable.hh:239
vector< Variable > _internalVariables
Definition: Variable.hh:486
set< Identifier > _attrib
Fieldnames of the Variable if the Variable is a structure.
Definition: Variable.hh:44
set< Identifier > _fieldName
Definition: Variable.hh:43
STL namespace.
void * _scope
attributes of the Variable
Definition: Variable.hh:45
static VariableFactory * _variableFactory
Definition: Variable.hh:490
VariableScope _scopeType
The scope of the variable.
Definition: Variable.hh:46
unsigned _id
The current Value of the Variable.
Definition: Variable.hh:48
Variable(VariableData *data)
internal data of a Variable
Definition: Variable.hh:204
Domain _domain
label of the Variable
Definition: Variable.hh:37
bool isStructure() const
Definition: Variable.hh:312
bool _isFree
The id of the Variable.
Definition: Variable.hh:49
bool operator!=(const Variable &variable) const
Definition: Variable.hh:249
Variable variableScope() const
Definition: Variable.hh:446
set< Identifier >::const_iterator AttributeIterator
Definition: Variable.hh:193
const set< Identifier > & emptyAttributes() const
Definition: Variable.hh:654
std::string Identifier
Definition: Type.hh:24
Domain domain() const
Definition: Variable.hh:287
vector< Variable > _modelVariables
Definition: Variable.hh:482
bool operator<=(const Variable &variable) const
Definition: Variable.hh:269
Namespace of the Diades project.
bool operator<(const Variable &variable) const
Definition: Variable.hh:259
vector< unordered_map< Identifier, Variable > > _nodeVariables
Definition: Variable.hh:483
set< Identifier > _emptyAttributes
Definition: Variable.hh:487
Variable newVariable(const Identifier &label, Domain domain, const set< Identifier > &attributes, Variable variable)
Variable & operator=(const Variable &variable)
Definition: Variable.hh:225
bool isSimple() const
Definition: Variable.hh:302
set< Identifier > _emptyFields
Definition: Variable.hh:488
map< Identifier, Variable > * _structure
Definition: Variable.hh:40
unordered_map< Identifier, Variable > _modelVariableOfLabel
Definition: Variable.hh:481
vector< Variable > * _array
Fields of the Variable if the Variable is a structure.
Definition: Variable.hh:41
Variable(const Variable &variable)
Definition: Variable.hh:217
VariableScope scopeType() const
Definition: Variable.hh:426