/* * Copyright QTronic GmbH. All rights reserved. */ /* See $PTII/ptolemy/actor/lib/fmi/ma/fmusdk-license.htm for the complete FMUSDK License. */ /* ---------------------------------------------------------------------------* * XmlElement.h * Contains elements classes that describe content of model description of a * FMI 2.0 model. All elements have Element as parent class. Elements have * attributes and other specific content. * * Author: Adrian Tirea * ---------------------------------------------------------------------------*/ #ifndef XML_ELEMENT_H #define XML_ELEMENT_H #include "XmlParser.h" #include "string" #include "vector" #include "map" class Element { public: XmlParser::Elm type; // element type std::map attributes; // map with key one of XmlParser::Att public: virtual ~Element(); virtual void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); virtual void printElement(int indent); const char *getAttributeValue(XmlParser::Att att); // value or NULL if not present int getAttributeInt(XmlParser::Att att, XmlParser::ValueStatus *vs); unsigned int getAttributeUInt(XmlParser::Att att, XmlParser::ValueStatus *vs); double getAttributeDouble(XmlParser::Att att, XmlParser::ValueStatus *vs); bool getAttributeBool(XmlParser::Att att, XmlParser::ValueStatus *vs); template void printListOfElements(int indent, std::vector list); template void deleteListOfElements(std::vector list); }; class ListElement : public Element { public: std::vector list; // list of Element public: ~ListElement(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); }; class Unit : public Element { public: std::vector displayUnits; // list of DisplayUnit Element *baseUnit; // null or BaseUnit public: Unit(); ~Unit(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); }; class SimpleType : public Element { public: Element *typeSpec; // one of RealType, IntegerType etc. public: SimpleType(); ~SimpleType(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); }; class Component : public Element { public: std::vector files; // list of File. Only meaningful for source code FMUs (not .dll). public: ~Component(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); }; class ScalarVariable : public Element { public : Element *typeSpec; // one of Real, Integer, etc std::vector annotations; // list of Annotations //int modelIdx; // only used in fmu10 public: ScalarVariable(); ~ScalarVariable(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); // get the valueReference of current variable. This attribute is mandatory for a variable. fmiValueReference getValueReference(); // returns one of constant, fixed, tunable, discrete, continuous. // If value is missing, the default continuous is returned. // If unknown value, return enu_BAD_DEFINED. XmlParser::Enu getVariability(); // returns one of parameter, calculatedParameter, input, output, local, independent. // If value is missing, the default local is returned. // If unknown value, return enu_BAD_DEFINED. XmlParser::Enu getCausality(); }; class ModelStructure : public Element { private: XmlParser::Elm unknownParentType; // used in handleElement to know in which list next Unknown belongs. public: std::vector outputs; // list of Unknown std::vector derivatives; // list of Unknown std::vector discreteStates; // list of Unknown std::vector initialUnknowns; // list of Unknown public: ~ModelStructure(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); }; class ModelDescription : public Element { public: std::vector unitDefinitions; // list of Units std::vector typeDefinitions; // list of Types Component *modelExchange; // NULL or ModelExchange Component *coSimulation; // NULL or CoSimulation // At least one of CoSimulation, ModelExchange must be present. std::vector logCategories; // list of Category Element *defaultExperiment; // NULL or DefaultExperiment std::vector vendorAnnotations; // list of Tools std::vector modelVariables; // list of ScalarVariable ModelStructure *modelStructure; // not NULL ModelStructure public: ModelDescription(); ~ModelDescription(); void handleElement(XmlParser *parser, const char *childName, int isEmptyElement); void printElement(int indent); // get the SimpleType definition by name, if any. NULL if not found. SimpleType *getSimpleType(const char *name); // get the ScalarVariable by name, if any. NULL if not found. ScalarVariable *getVariable(const char *name); // get description from variable, if not present look for type definition description. const char *getDescriptionForVariable(ScalarVariable *sv); // get attribute from type, if not present look for it inside declared type. // Attributes example: 'min', 'max', 'quantity'. const char * getAttributeFromTypeOrDeclaredType(ScalarVariable *sv, XmlParser::Att a); }; #endif // XML_ELEMENT_H