XmlElement.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright QTronic GmbH. All rights reserved.
  3. */
  4. /* ---------------------------------------------------------------------------*
  5. * XmlElement.h
  6. * Contains elements classes that describe content of model description of a
  7. * FMI 2.0 model. All elements have Element as parent class. Elements have
  8. * attributes and other specific content.
  9. *
  10. * Author: Adrian Tirea
  11. * ---------------------------------------------------------------------------*/
  12. #ifndef XML_ELEMENT_H
  13. #define XML_ELEMENT_H
  14. #include <map>
  15. #include <vector>
  16. #include "XmlParser.h"
  17. class Element {
  18. public:
  19. XmlParser::Elm type; // element type
  20. std::map<XmlParser::Att, char*> attributes; // map with key one of XmlParser::Att
  21. public:
  22. virtual ~Element();
  23. virtual void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  24. virtual void printElement(int indent);
  25. const char *getAttributeValue(XmlParser::Att att); // value or NULL if not present
  26. int getAttributeInt(XmlParser::Att att, XmlParser::ValueStatus *vs);
  27. unsigned int getAttributeUInt(XmlParser::Att att, XmlParser::ValueStatus *vs);
  28. double getAttributeDouble(XmlParser::Att att, XmlParser::ValueStatus *vs);
  29. bool getAttributeBool(XmlParser::Att att, XmlParser::ValueStatus *vs);
  30. template <typename T> void printListOfElements(int indent, const std::vector<T *> &list);
  31. template <typename T> void deleteListOfElements(const std::vector<T *> &list);
  32. };
  33. class ListElement : public Element {
  34. public:
  35. std::vector<Element*> list; // list of Element
  36. public:
  37. ~ListElement();
  38. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  39. void printElement(int indent);
  40. };
  41. class Unit : public Element {
  42. public:
  43. std::vector<Element *> displayUnits; // list of DisplayUnit
  44. Element *baseUnit; // null or BaseUnit
  45. public:
  46. Unit();
  47. ~Unit();
  48. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  49. void printElement(int indent);
  50. };
  51. class SimpleType : public Element {
  52. public:
  53. Element *typeSpec; // one of RealType, IntegerType etc.
  54. public:
  55. SimpleType();
  56. ~SimpleType();
  57. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  58. void printElement(int indent);
  59. };
  60. class Component : public Element {
  61. public:
  62. std::vector<Element *> files; // list of File. Only meaningful for source code FMUs (not .dll).
  63. public:
  64. ~Component();
  65. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  66. void printElement(int indent);
  67. };
  68. class ScalarVariable : public Element {
  69. public :
  70. Element *typeSpec; // one of Real, Integer, etc
  71. std::vector<Element *> annotations; // list of Annotations
  72. // int modelIdx; // only used in fmu10
  73. public:
  74. ScalarVariable();
  75. ~ScalarVariable();
  76. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  77. void printElement(int indent);
  78. // get the valueReference of current variable. This attribute is mandatory for a variable.
  79. fmi2ValueReference getValueReference();
  80. // returns one of constant, fixed, tunable, discrete, continuous.
  81. // If value is missing, the default continuous is returned.
  82. // If unknown value, return enu_BAD_DEFINED.
  83. XmlParser::Enu getVariability();
  84. // returns one of parameter, calculatedParameter, input, output, local, independent.
  85. // If value is missing, the default local is returned.
  86. // If unknown value, return enu_BAD_DEFINED.
  87. XmlParser::Enu getCausality();
  88. };
  89. class ModelStructure : public Element {
  90. private:
  91. XmlParser::Elm unknownParentType; // used in handleElement to know in which list next Unknown belongs.
  92. public:
  93. std::vector<Element *> outputs; // list of Unknown
  94. std::vector<Element *> derivatives; // list of Unknown
  95. std::vector<Element *> discreteStates; // list of Unknown
  96. std::vector<Element *> initialUnknowns; // list of Unknown
  97. public:
  98. ModelStructure();
  99. ~ModelStructure();
  100. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  101. void printElement(int indent);
  102. };
  103. class ModelDescription : public Element {
  104. public:
  105. std::vector<Unit *> unitDefinitions; // list of Units
  106. std::vector<SimpleType *> typeDefinitions; // list of Types
  107. Component *modelExchange; // NULL or ModelExchange
  108. Component *coSimulation; // NULL or CoSimulation
  109. // At least one of CoSimulation, ModelExchange must be present.
  110. std::vector<Element *> logCategories; // list of Category
  111. Element *defaultExperiment; // NULL or DefaultExperiment
  112. std::vector<Element *> vendorAnnotations; // list of Tools
  113. std::vector<ScalarVariable *> modelVariables; // list of ScalarVariable
  114. ModelStructure *modelStructure; // not NULL ModelStructure
  115. public:
  116. ModelDescription();
  117. ~ModelDescription();
  118. void handleElement(XmlParser *parser, const char *childName, int isEmptyElement);
  119. void printElement(int indent);
  120. // get the SimpleType definition by name, if any. NULL if not found.
  121. SimpleType *getSimpleType(const char *name);
  122. // get the ScalarVariable by name, if any. NULL if not found.
  123. ScalarVariable *getVariable(const char *name);
  124. // get the ScalarVariable by vr and type. NULL if not found.
  125. ScalarVariable *getVariable(fmi2ValueReference vr, XmlParser::Elm type);
  126. // get description from variable, if not present look for type definition description.
  127. const char *getDescriptionForVariable(ScalarVariable *sv);
  128. // get attribute from type, if not present look for it inside declared type.
  129. // Attributes example: 'min', 'max', 'quantity'.
  130. const char *getAttributeFromTypeOrDeclaredType(ScalarVariable *sv, XmlParser::Att a);
  131. };
  132. #endif // XML_ELEMENT_H