]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/XML/src/FMI2/fmi2_xml_variable_impl.h
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / XML / src / FMI2 / fmi2_xml_variable_impl.h
1 /*
2     Copyright (C) 2012 Modelon AB
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the BSD style license.
6
7      This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10     FMILIB_License.txt file for more details.
11
12     You should have received a copy of the FMILIB_License.txt file
13     along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15
16 #ifndef FMI2_XML_VARIABLEIMPL_H
17 #define FMI2_XML_VARIABLEIMPL_H
18
19 #include <JM/jm_vector.h>
20
21 #include <FMI2/fmi2_xml_model_description.h>
22
23 #include "fmi2_xml_type_impl.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /* General variable type is convenien to unify all the variable list operations */
30 struct fmi2_xml_variable_t {
31     fmi2_xml_variable_type_base_t* typeBase; /** \brief Type information of the variable */
32
33     const char* description;                             /** \brief Associate description */
34
35         size_t originalIndex;                                   /** \brief Index in the model description */
36
37     /* NB: before parsing of <ModelVariables> has finished,
38            derivativeOf and previous are stored as integer indices cast to pointers,
39            until they can be looked up */
40     fmi2_xml_variable_t *derivativeOf;      /** \brief Only for continuous Real variables. If non-NULL, the variable that this is the derivative of. */
41     fmi2_xml_variable_t *previous;          /** \brief If non-NULL, the variable that holds the value of this variable at the previous super-dense time instant. */
42
43     fmi2_value_reference_t vr;                          /** \brief Value reference */
44     char aliasKind;
45     char initial;
46     char variability;
47     char causality;
48     char reinit; /** \brief Only for continuous Real variables */
49     char canHandleMultipleSetPerTimeInstant;
50
51     char name[1];
52 };
53
54 static int fmi2_xml_compare_vr (const void* first, const void* second) {
55     fmi2_xml_variable_t* a = *(fmi2_xml_variable_t**)first;
56     fmi2_xml_variable_t* b = *(fmi2_xml_variable_t**)second;
57     fmi2_base_type_enu_t at = fmi2_xml_get_variable_base_type(a);
58     fmi2_base_type_enu_t bt = fmi2_xml_get_variable_base_type(b);
59         if(at == fmi2_base_type_enum) at = fmi2_base_type_int;
60         if(bt == fmi2_base_type_enum) bt = fmi2_base_type_int;
61     if(at!=bt) return at - bt;
62     if(a->vr < b->vr) return -1;
63     if(a->vr > b->vr) return 1;
64     return ((int)a->aliasKind - (int)b->aliasKind);
65 }
66
67 #ifdef __cplusplus
68 }
69 #endif
70
71 #endif /* FMI2_XML_VARIABLEIMPL_H */