DiaDes  0.1
DIAgnosisofDiscrete-EventSystem
AltaricaModel.hh
Go to the documentation of this file.
1 #ifndef __DIADES__ALTARICA__ALTARICAMODEL__HH
2 #define __DIADES__ALTARICA__ALTARICAMODEL__HH
3 
14 //#include"Variable.hh"
15 //#include"Node.hh"
16 
17 namespace Diades
18 {
19  namespace Altarica
20  {
21 
22 
29  {
30 
31  public:
32  typedef reference_wrapper<AltaricaModel> Reference;
33  typedef reference_wrapper<AltaricaModel const> ConstReference;
35  typedef const AltaricaModel * ConstPointer;
36 
37 
38 
39  private:
40 
57 
58 
64  vector<VariableDecl::Reference> _mainVariableDecl;
65 
74 
82  // VariableFactory _varFactory;
87  public:
91  typedef vector<NodeDecl::Reference> NodeDecls;
95  typedef NodeDecls::const_iterator NodeDeclIterator;
99  typedef unordered_map<Identifier,Domain::ConstReference> DomainDictionary;
103  typedef unordered_map<Identifier,Value::ConstReference> ConstantDictionary;
107  typedef unordered_map<Identifier,NodeDecl::Reference> NodeDeclDictionary;
108 
109  private:
110 
114  DomainDictionary _domainDictionary;
115 
119  vector<Domain::ConstReference> _globalDomains;
120 
121 
122 
126  NodeDecls _nodeDecls;
127  vector<NodeDecl::Reference> _mainNodeDecl;
128 
129  // Node _main;
133  NodeDeclDictionary _nodeDeclOfLabel;
134 
139 
145  ConstantDictionary _constantDictionary;
146 
154  unsigned typeIndex(Domain::DomainType type) const;
155 
156 
157  public:
163  static string typeName() { return "Diades::Altarica::AltaricaModel"; }
165 
166 
167  public:
171 
172  const ConstantDictionary & constants() const
173  {
174  return _constantDictionary;
175  }
176 
177  void addConstant(const Identifier & name, const Value & value)
178  {
179  always_require(Exception, getConstant(name).isNull(),"addConstant: such a constant already exists.");
180  _constantDictionary.insert(make_pair(name,Value::ConstReference(value)));
181  }
182 
183 
184  const Value & getConstant(const Identifier & name) const
185  {
186  ConstantDictionary::const_iterator it = _constantDictionary.find(name);
187  if(it != _constantDictionary.end())
188  {
189  return it->second;
190  }
191  return nullValue();
192  }
193 
195 
196 
197 
201 
208  AltaricaModel(const Identifier & name);
209 
210 
211 
216  ~AltaricaModel();
217 
219 
220 
221 
226 
234  //bool valid() const;
235 
236 
237 
244  const Identifier & name() const
245  {
246  return _name;
247  }
248 
249 
257  bool operator==(const AltaricaModel & model) const
258  {
259  return this == &model;
260  }
261 
269  bool operator!=(const AltaricaModel & model) const
270  {
271  return !(model==(*this));
272  }
274 
275 
280 
284  const Type & nullType() const
285  {
286  return _typeFactory.nullType();
287  }
288 
295  const Type & getBoolean() const
296  {
297  return _typeFactory.getBoolean();
298  }
305  const Type & getIdentifier() const
306  {
307  return _typeFactory.getIdentifier();
308  }
309 
316  const Type & getInteger() const
317  {
318  return _typeFactory.getInteger();
319  }
320 
328  const Type & getStructureType(const Type::StructureFields & fields) const
329  {
330  try
331  {
332  return _typeFactory.getStructureType(fields);
333  }
334  catch(exception & e)
335  {
336  throw(Exception("getStructureType failure",e));
337  }
338  return nullType();
339  }
340 
341 
342 
351  const Type & getArrayType(const Type & type,unsigned size) const
352  {
353  try
354  {
355  return _typeFactory.getArrayType(type,size);
356  }
357  catch(exception & e)
358  {
359  throw(Exception("getArrayType failure",e));
360  }
361  return nullType();
362  }
363 
364 
366  public:
371 
378  const Value & nullValue() const
379  {
380  return _valueFactory.nullValue();
381  }
382 
392  const Value & getValue(const Identifier & value) const
393  {
394  try
395  {
396  return _valueFactory.getValue(value);
397  }
398  catch(exception & e)
399  {
400  throw(Exception("getValue (identifier) failure",e));
401  }
402  return nullValue();
403  }
404 
412  const Value & getValue(bool value) const
413  {
414  return _valueFactory.getValue(value);
415  }
416 
424  const Value & getValue(int value) const
425  {
426  return _valueFactory.getValue(value);
427  }
428 
437  const Value & getValue(const Value::ArrayFields & array) const
438  {
439  try
440  {
441  return _valueFactory.getValue(array);
442  }
443  catch(exception & e)
444  {
445  throw(Exception("getValue (array) failure",e));
446  }
447  return nullValue();
448  }
449 
450 
459  const Value & getValue(const Value::StructureFields & structure) const
460  {
461 
462  try
463  {
464  return _valueFactory.getValue(structure);
465  }
466  catch(exception & e)
467  {
468  throw(Exception("getValue (structure) failure",e));
469  }
470  return nullValue();
471  }
473 
474 
475  public:
480 
481 
485  const Domain & getBooleans() const
486  {
487  return _domainFactory.getBooleans();
488  }
489 
490 
494  const Domain & getIntegers() const
495  {
496  return _domainFactory.getIntegers();
497  }
498 
499 
507  const Domain & newDomain(const Identifier & name, const Domain & associatedDomain, NodeDecl & node);
508 
517  const Domain & newDomain(const Identifier & name, const Value & min,
518  const Value & max, NodeDecl & node);
519 
520 
521 
522 
530  const Domain & newDomain(const Identifier & name, const ValueEnumeration & enumeration, NodeDecl & node);
531 
539  const Domain & newDomain(const Identifier & name, const map<Identifier,Domain::ConstReference> & structure, NodeDecl & node);
540 
549  const Domain & newDomain(const Identifier & name, const Domain & domain, unsigned size, NodeDecl & node);
550 
551 
552 
563  const Domain & getDomain(const Identifier & name, NodeDecl & node);
564 
576  const Domain & getDomain(const NodeDecl & node);
577 
578 
579 
586  const Domain & nullDomain() const
587  {
588  return _domainFactory.nullDomain();
589  }
590 
591 
598  const vector<Domain::ConstReference> & domains() const
599  {
600  return _globalDomains;
601  }
602 
603 
605 
606 
607  public:
612 
613 
625  NodeDecl & node,
626  const set<Identifier> & attributes,
627  VariableDecl & scope)
628  {
629  try
630  {
631  return _varDeclFactory.getNodeVariableDecl(id,node,attributes,scope);
632  }
633  catch(exception & e)
634  {
635  throw(Exception("getVariableDecl failure",e));
636  }
637  return nullVariableDecl();
638  }
639 
640 
641 
642 
643 
656  const set<Identifier> & attributes,
657  VariableDecl & scope)
658  {
659 
660  try
661  {
662  return _varDeclFactory.getVariableDecl(label,domain,type,attributes,scope);
663  }
664  catch(exception & e)
665  {
666  throw(Exception("getVariableDecl failure",e));
667  }
668  return nullVariableDecl();
669  }
670 
678  {
679  return _varDeclFactory.nullVariableDecl();
680  }
681 
689  {
690  return _varDeclFactory.nullVariableDecl();
691  }
692 
693 
694 
696  {
697  return _varDeclFactory;
698  }
699 
700 
702 
703  public:
708 
713  {
714  _mainNodeDecl.clear();
715  _mainNodeDecl.push_back(nullNodeDecl());
716  //_eventFactory.init();
717  //_expressionFactory.init();
718  }
719 
720 
725  void setMainNodeDecl(const Identifier & name)
726  {
727  _mainNodeDecl.clear();
728  _mainNodeDecl.push_back(getNodeDecl(name));
729  _eventFactory.init();
730  _expressionFactory.init();
731  }
732 
741  bool containsNodeDecl(const Identifier & nodeName) const;
742 
751  NodeDecl & getNodeDecl(const Identifier & nodeName);
752 
753 
761  {
762  return _nodeDeclFactory.nullNodeDecl();
763  }
764 
771  const NodeDecl & nullNodeDecl() const
772  {
773  return _nodeDeclFactory.nullNodeDecl();
774  }
775 
776 
777 
782  unsigned numberOfNodeDecls() const
783  {
784  return _nodeDecls.size();
785  }
786 
787 
792  NodeDeclIterator nodeDeclBegin() const
793  {
794  return _nodeDecls.begin();
795  }
796 
801  NodeDeclIterator nodeDeclEnd() const
802  {
803  return _nodeDecls.end();
804  }
805 
807 
812 
818 
826  const Expression & getVarExpression(const NodeDecl & node, const VariableDecl & var)
827  {
828  return _expressionFactory.getVarExpression(node,var);
829  }
830 
831 
832 
833 
841  const Expression & getIdentifierExpression(const NodeDecl & node, const Identifier & id)
842  {
843  return _expressionFactory.getIdentifierExpression(node,id);
844  }
845 
854  {
855  return _expressionFactory.getBooleanExpression(category);
856  }
857 
858 
866  const Expression & getIntegerExpression(int value)
867  {
868  return _expressionFactory.getIntegerExpression(value);
869  }
870 
871 
881  const Expression & getIteExpression(const NodeDecl & node, const Expression & ifE, const Expression & thenE, const Expression & elseE)
882  {
883  return _expressionFactory.getIteExpression(node,ifE,thenE,elseE);
884  }
885 
886 
895  const Expression & getCaseExpression(const NodeDecl & node, const ExprVector & choices,
896  const ExprVector & expressions)
897  {
898  return _expressionFactory.getCaseExpression(node,choices,expressions);
899  }
900 
901 
902 
912  const Expression & getBinaryExpression(const NodeDecl & node, Expression::Category category, const Expression & left, const Expression & right)
913  {
914  return _expressionFactory.getBinaryExpression(node,category,left,right);
915  }
916 
925  const Expression & getUnaryExpression(const NodeDecl & node, Expression::Category category, const Expression & expr)
926  {
927  return _expressionFactory.getUnaryExpression(node,category,expr);
928  }
929 
938  const Expression & getListExpression(const NodeDecl & node,Expression::Category category, const ExprVector & expressions)
939  {
940  return _expressionFactory.getListExpression(node,category,expressions);
941  }
942 
943 
952  const Expression & getStructExpression(const NodeDecl & node,const vector<Identifier> & identifiers,const ExprVector & expressions)
953  {
954  return _expressionFactory.getStructExpression(node,identifiers,expressions);
955  }
956 
958 
963 
970  EventDecl & getEventDecl(const Identifier & id, NodeDecl & owner)
971  {
972  always_require(Exception,owner.owner() == *this,"getEventDecl: the node declaration does belong to this model.");
973  return _eventFactory.getEventDecl(owner,id);
974  }
975 
982  const EventDecl & getEventDecl(const Identifier & id, const NodeDecl & owner) const
983  {
984  always_require(Exception,owner.owner() == *this,"getEventDecl: the node declaration does belong to this model.");
985  return _eventFactory.getEventDecl(owner,id);
986  }
987 
994  const EventDecl & nullEventDecl() const
995  {
996  return _eventFactory.nullEventDecl();
997  }
1005  {
1006  return _eventFactory.nullEventDecl();
1007  }
1009 
1010 
1015 
1020  // Node & getRootNode();
1021  //const Node & getRootNode() const;
1022  //Node & getNode(const string & fullname );
1023  //const Node & getRootNode(const string & fullname) const;
1024 
1032  {
1033  return _mainVariableDecl[0];
1034  }
1035 
1043  {
1044  return _mainVariableDecl[0];
1045  }
1046 
1047 
1048 
1049 
1056  const NodeDecl & mainNodeDecl() const
1057  {
1058  return _mainNodeDecl[0];
1059  }
1067  {
1068  return _mainNodeDecl[0];
1069  }
1071 
1076 
1087  const Domain & domain,
1088  NodeDecl & node)
1089  {
1090  always_require(Exception,!name.str().empty(), "getParameterDecl: the name is empty.");
1091  always_require(Exception,!domain.isNull(),"getParameterDecl: the domain is null.");
1092  return _paramDeclFactory.getParameterDecl(name,domain,node);
1093  }
1094 
1102  {
1103  return _paramDeclFactory.nullParameterDecl();
1104  }
1106  };
1107 
1108  };
1109 };
1110 
1111 #endif
const Domain & getIntegers() const
Definition: Domains.hh:914
const Expression & getIdentifierExpression(const NodeDecl &node, const Identifier &id)
const Identifier & name() const
const Domain & nullDomain() const
Definition: Domains.hh:904
const Type & getIdentifier() const
An Identifier is a reference to a string (IdentifierData) that only contains alpha-numeric characters...
Definition: Identifier.hh:121
const AltaricaModel & owner() const
const Expression & getBinaryExpression(const NodeDecl &node, Expression::Category category, const Expression &left, const Expression &right)
#define always_require(Exception, expr, message)
Definition: Assertion.hh:121
const VariableDeclFactory & variableDeclFactory() const
vector< Domain::ConstReference > _globalDomains
const Expression & getListExpression(const NodeDecl &node, Cat category, const ExprVector &expressions)
const ParameterDecl & nullParameterDecl() const
NodeDeclDictionary _nodeDeclOfLabel
const Domain & nullDomain() const
const Value & getConstant(const Identifier &name) const
const Expression & getListExpression(const NodeDecl &node, Expression::Category category, const ExprVector &expressions)
void setMainNodeDecl(const Identifier &name)
NodeDeclIterator nodeDeclBegin() const
const VariableDecl & nullVariableDecl() const
const Domain & getIntegers() const
unordered_map< Identifier, Domain::ConstReference > DomainDictionary
const Expression & getIdentifierExpression(const NodeDecl &node, const Identifier &id)
const Expression & getBooleanExpression(Expression::Category category)
reference_wrapper< AltaricaModel const > ConstReference
const Type & getBoolean() const
const Type & getInteger() const
Definition: Type.hh:276
const ParameterDecl & getParameterDecl(const Identifier &name, const Domain &domain, NodeDecl &nodeDecl)
bool containsNodeDecl(const Identifier &nodeName) const
VariableDecl & getNodeVariableDecl(const Identifier &label, set< Identifier > &attributes, VariableDecl &scope)
const Value & getValue(const Identifier &value)
This class represents the declaration of an Event in a node declaration.
Definition: EventDecl.hh:43
const string & str() const
Definition: Identifier.hh:409
const vector< Domain::ConstReference > & domains() const
const Expression & getIntegerExpression(int value)
const Type & getInteger() const
vector< NodeDecl::Reference > _mainNodeDecl
ConstantDictionary _constantDictionary
const AltaricaModel * ConstPointer
const Value & getValue(const Value::StructureFields &structure) const
const EventDecl & nullEventDecl() const
Definition: EventDecl.hh:322
const Value & getValue(const Value::ArrayFields &array) const
const Value & nullValue() const
Definition: Value.hh:340
const Expression & getIntegerExpression(int value)
const Type & getArrayType(const Type &itemType, unsigned size)
bool operator==(const AltaricaModel &model) const
Altarica Transition.
vector< ConstReference > ArrayFields
Definition: Value.hh:69
const Type & nullType() const
Definition: Type.hh:268
const Type & getBoolean() const
Definition: Type.hh:272
map< Identifier, ConstReference > StructureFields
Definition: Value.hh:64
const Type & getArrayType(const Type &type, unsigned size) const
ExpressionFactory _expressionFactory
const Expression & getUnaryExpression(const NodeDecl &node, Cat category, const Expression &expr)
NodeDeclIterator nodeDeclEnd() const
VariableDecl & getVariableDecl(const Diades::Utils::Identifier &label, NodeDecl::VarType type, const Domain &domain, const set< Identifier > &attributes, VariableDecl &scope)
Utils::Exception< AltaricaModel > Exception
const Value & getValue(int value) const
reference_wrapper< Value const > ConstReference
Definition: Value.hh:59
const Expression & getVarExpression(const NodeDecl &node, const VariableDecl &var)
const EventDecl & nullEventDecl() const
const VariableDecl & mainVariableDecl() const
const Expression & getIteExpression(const NodeDecl &node, const Expression &ifE, const Expression &thenE, const Expression &elseE)
File that declares an ExpressionFactory.
const VariableDecl & nullVariableDecl() const
const Type & getIdentifier() const
Definition: Type.hh:280
const Domain & getDomain(const Identifier &name, NodeDecl &node)
const Expression & getBooleanExpression(Cat category)
map< Identifier, ConstReference > StructureFields
Definition: Type.hh:64
const Expression & getIteExpression(const NodeDecl &node, const Expression &ifE, const Expression &thenE, const Expression &elseE)
const Expression & getBinaryExpression(const NodeDecl &node, Cat category, const Expression &left, const Expression &right)
Namespace of the Diades project.
bool operator!=(const AltaricaModel &model) const
const Domain & getBooleans() const
const Expression & getStructExpression(const NodeDecl &node, const vector< Identifier > &identifiers, const ExprVector &expressions)
void addConstant(const Identifier &name, const Value &value)
const Domain & newDomain(const Identifier &name, const Domain &associatedDomain, NodeDecl &node)
EventDecl & getEventDecl(const NodeDecl &node, const Identifier &label)
vector< NodeDecl::Reference > NodeDecls
VariableDeclFactory _varDeclFactory
const NodeDecl & mainNodeDecl() const
ExpressionFactory::ExprVector ExprVector
VariableDecl & getNodeVariableDecl(const Identifier &id, NodeDecl &node, const set< Identifier > &attributes, VariableDecl &scope)
VariableDecl & getVariableDecl(const Identifier &label, const Domain &domain, const VariableDecl::VarType &type, const set< Identifier > &attributes, VariableDecl &scope)
const ParameterDecl & getParameterDecl(const Identifier &name, const Domain &domain, NodeDecl &node)
vector< Value::ConstReference > ValueEnumeration
enumeration of Value elements (unicity and sorting is in charge of the user)
Definition: Value.hh:244
const ParameterDecl & nullParameterDecl() const
const EventDecl & getEventDecl(const Identifier &id, const NodeDecl &owner) const
NodeDecls::const_iterator NodeDeclIterator
reference_wrapper< AltaricaModel > Reference
const Value & nullValue() const
const NodeDecl & nullNodeDecl() const
const Expression & getVarExpression(const NodeDecl &node, const VariableDecl &var)
const Domain & getBooleans() const
Definition: Domains.hh:909
EventDecl & getEventDecl(const Identifier &id, NodeDecl &owner)
unordered_map< Identifier, Value::ConstReference > ConstantDictionary
const ConstantDictionary & constants() const
ParameterDeclFactory _paramDeclFactory
const Value & getValue(const Identifier &value) const
const Expression & getUnaryExpression(const NodeDecl &node, Expression::Category category, const Expression &expr)
vector< VariableDecl::Reference > _mainVariableDecl
NodeDecl & getNodeDecl(const Identifier &nodeName)
unordered_map< Identifier, NodeDecl::Reference > NodeDeclDictionary
const Expression & getStructExpression(const NodeDecl &node, const vector< Identifier > &identifiers, const ExprVector &expressions)
const Value & getValue(bool value) const
unsigned typeIndex(Domain::DomainType type) const
const Type & nullType() const
const Type & getStructureType(const Type::StructureFields &fields)
const Type & getStructureType(const Type::StructureFields &fields) const
const Expression & getCaseExpression(const NodeDecl &node, const ExprVector &choices, const ExprVector &expressions)
const Expression & getCaseExpression(const NodeDecl &node, const ExprVector &choices, const ExprVector &expressions)
AltaricaModel(const Identifier &name)