1 /* -------------------------------------------------------------------------
\r
3 * A parser for file modelVariables.xml of an FMU.
\r
4 * Supports "FMI for Model Exchange 1.0" and "FMI for Co-Simulation 1.0".
\r
5 * Copyright 2011 QTronic GmbH. All rights reserved.
\r
6 * -------------------------------------------------------------------------*/
\r
11 // define XML_STATIC before including expat.h
\r
12 // to prevent error when linking with libexpatMT.lib
\r
17 typedef unsigned int fmiValueReference;
\r
18 #define fmiUndefinedValueReference (fmiValueReference)(-1)
\r
20 #define SIZEOF_ELM 31
\r
21 extern const char *elmNames[SIZEOF_ELM];
\r
23 #define SIZEOF_ATT 47
\r
24 extern const char *attNames[SIZEOF_ATT];
\r
26 #define SIZEOF_ENU 13
\r
27 extern const char *enuNames[SIZEOF_ENU];
\r
31 elm_fmiModelDescription,elm_UnitDefinitions,elm_BaseUnit,elm_DisplayUnitDefinition,elm_TypeDefinitions,
\r
32 elm_Type,elm_RealType,elm_IntegerType,elm_BooleanType,elm_StringType,elm_EnumerationType,elm_Item,
\r
33 elm_DefaultExperiment,elm_VendorAnnotations,elm_Tool,elm_Annotation,elm_ModelVariables,elm_ScalarVariable,
\r
34 elm_DirectDependency,elm_Name,elm_Real,elm_Integer,elm_Boolean,elm_String,elm_Enumeration,
\r
35 elm_Implementation,elm_CoSimulation_StandAlone,elm_CoSimulation_Tool,elm_Model,elm_File,elm_Capabilities
\r
40 att_fmiVersion,att_displayUnit,att_gain,att_offset,att_unit,att_name,att_description,att_quantity,att_relativeQuantity,
\r
41 att_min,att_max,att_nominal,att_declaredType,att_start,att_fixed,att_startTime,att_stopTime,att_tolerance,att_value,
\r
42 att_valueReference,att_variability,att_causality,att_alias,att_modelName,att_modelIdentifier,att_guid,att_author,
\r
43 att_version,att_generationTool,att_generationDateAndTime,att_variableNamingConvention,att_numberOfContinuousStates,
\r
44 att_numberOfEventIndicators,att_input,
\r
45 att_canHandleVariableCommunicationStepSize,att_canHandleEvents,att_canRejectSteps,att_canInterpolateInputs,
\r
46 att_maxOutputDerivativeOrder,att_canRunAsynchronuously,att_canSignalEvents,att_canBeInstantiatedOnlyOncePerProcess,
\r
47 att_canNotUseMemoryManagementFunctions,att_entryPoint,att_manualStart,att_type
\r
50 // Enumeration values
\r
52 enu_flat,enu_structured,enu_constant,enu_parameter,enu_discrete,enu_continuous,
\r
53 enu_input,enu_output,enu_internal,enu_none,enu_noAlias,enu_alias,enu_negatedAlias
\r
56 // AST node for element
\r
57 // DisplayUnitDefinition, RealType, IntegerType, BooleanType, StringType, DefaultExperiment,
\r
58 // Item, Annotation, Name, Real, Integer, Boolean, String, Enumeration, Capabilities, File
\r
60 Elm type; // element type
\r
61 const char** attributes; // null or n attribute value strings
\r
62 int n; // size of attributes, even number
\r
65 // AST node for element that has a list of elements
\r
66 // BaseUnit, EnumerationType, Tool, DirectDependency, Model
\r
68 Elm type; // element type
\r
69 const char** attributes; // null or n attribute value strings
\r
70 int n; // size of attributes, even number
\r
71 Element** list; // null-terminated array of pointers to elements, not null
\r
74 // AST node for element Type
\r
76 Elm type; // element type
\r
77 const char** attributes; // null or n attribute value strings
\r
78 int n; // size of attributes, an even number
\r
79 Element* typeSpec; // one of RealType, IntegerType etc.
\r
82 // AST node for element ScalarVariable
\r
84 Elm type; // element type
\r
85 const char** attributes; // null or n attribute value strings
\r
86 int n; // size of attributes, even number
\r
87 Element* typeSpec; // one of Real, Integer, etc
\r
88 Element** directDependencies; // null or null-terminated list of Name
\r
91 // AST node for element CoSimulation_StandAlone and CoSimulation_Tool
\r
93 Elm type; // one of elm_CoSimulation_StandAlone and elm_CoSimulation_Tool
\r
94 const char** attributes; // null or n attribute value strings
\r
95 int n; // size of attributes, even number
\r
96 Element* capabilities; // a set of capability attributes
\r
97 ListElement* model; // non-NULL to support tool coupling, NULL for standalone
\r
100 // AST node for element ModelDescription
\r
102 Elm type; // element type
\r
103 const char** attributes; // null or n attribute value strings
\r
104 int n; // size of attributes, even number
\r
105 ListElement** unitDefinitions; // NULL or null-terminated list of BaseUnits
\r
106 Type** typeDefinitions; // NULL or null-terminated list of Types
\r
107 Element* defaultExperiment; // NULL or DefaultExperiment
\r
108 ListElement** vendorAnnotations; // NULL or null-terminated list of Tools
\r
109 ScalarVariable** modelVariables; // NULL or null-terminated list of ScalarVariable
\r
110 CoSimulation* cosimulation; // NULL if this ModelDescription is for model exchange only
\r
111 } ModelDescription;
\r
113 // types of AST nodes used to represent an element
\r
120 astModelDescription
\r
123 // Possible results when retrieving an attribute value from an element
\r
130 // Public methods: Parsing and low-level AST access
\r
131 ModelDescription* parse(const char* xmlPath);
\r
132 const char* getString(void* element, Att a);
\r
133 double getDouble (void* element, Att a, ValueStatus* vs);
\r
134 int getInt (void* element, Att a, ValueStatus* vs);
\r
135 unsigned int getUInt (void* element, Att a, ValueStatus* vs);
\r
136 char getBoolean (void* element, Att a, ValueStatus* vs);
\r
137 Enu getEnumValue (void* element, Att a, ValueStatus* vs);
\r
138 void freeElement (void* element);
\r
140 // Convenience methods for AST access. To be used afer successful validation only.
\r
141 const char* getModelIdentifier(ModelDescription* md);
\r
142 int getNumberOfStates(ModelDescription* md);
\r
143 int getNumberOfEventIndicators(ModelDescription* md);
\r
144 const char* getName(void* element);
\r
145 Enu getCausality(void* scalarVariable);
\r
146 Enu getVariability(void* scalarVariable);
\r
147 Enu getAlias(void* scalarVariable);
\r
148 fmiValueReference getValueReference(void* scalarVariable);
\r
149 ScalarVariable* getVariableByName(ModelDescription* md, const char* name);
\r
150 ScalarVariable* getVariable(ModelDescription* md, fmiValueReference vr, Elm type);
\r
151 Type* getDeclaredType(ModelDescription* md, const char* declaredType);
\r
152 const char* getString2(ModelDescription* md, void* sv, Att a);
\r
153 const char * getDescription(ModelDescription* md, ScalarVariable* sv);
\r
154 const char * getVariableAttributeString(ModelDescription* md, fmiValueReference vr, Elm type, Att a);
\r
155 double getVariableAttributeDouble(ModelDescription* md, fmiValueReference vr, Elm type, Att a, ValueStatus* vs);
\r
156 double getNominal(ModelDescription* md, fmiValueReference vr);
\r
158 #endif // xml_parser_h
\r