]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/XML/src/FMI1/fmi1_xml_type_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 / FMI1 / fmi1_xml_type_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 FMI1_XML_TYPEIMPL_H
17 #define FMI1_XML_TYPEIMPL_H
18
19 #include <JM/jm_named_ptr.h>
20 #include <JM/jm_string_set.h>
21 #include <FMI1/fmi1_xml_model_description.h>
22
23 #include "fmi1_xml_parser.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /** \defgroup Type definitions supporting structures
30
31   For each basic type there is exactly one instance of
32   fmi1_xml_variable_type_base_t with structKind=fmi1_xml_type_struct_enu_base.
33   Those instances have baseTypeStruct = NULL.
34
35   Each type definition creates 1 or 2 instances:
36   (1)  instance with structKind=fmi1_xml_type_struct_enu_typedef
37     that gives the name & description of the type. baseType is a
38     pointer to either  fmi1_xml_type_struct_enu_base or fmi1_xml_type_struct_enu_props
39   (2)  optionally, an instance with the structKind=fmi1_xml_type_contrain_properties
40     providing information on min/max/quantity/etc. baseType is a pointer
41     to structKind=fmi1_xml_type_struct_enu_base
42
43    Each variable definition may create none, 1 or 2 instances:
44     (1) fmi1_xml_type_struct_enu_start providing the start value
45     (2) structKind=fmi1_xml_type_struct_enu_props  providing information on min/max/quantity/etc.
46     baseType is a pointer to either fmi1_xml_type_struct_enu_base or fmi1_xml_type_struct_enu_typedef.
47  */
48
49 typedef enum {
50     fmi1_xml_type_struct_enu_base,
51     fmi1_xml_type_struct_enu_typedef,
52     fmi1_xml_type_struct_enu_props,
53     fmi1_xml_type_struct_enu_start
54 } fmi1_xml_type_struct_kind_enu_t;
55
56
57
58 typedef struct fmi1_xml_variable_type_base_t fmi1_xml_variable_type_base_t;
59 struct fmi1_xml_variable_type_base_t {
60     fmi1_xml_variable_type_base_t* baseTypeStruct; /* The fmi1_xml_variable_type_base structs are put on a list that provide needed info on a variable */
61
62     fmi1_xml_variable_type_base_t* next;    /** dynamically allocated fmi1_xml_variable_type_base structs are put on a linked list to prevent memory leaks*/
63
64     char structKind; /* one of fmi1_xml_type_contrains_kind.*/
65     char baseType;   /* one of fmi1_xml_base_type */
66     char relativeQuantity; /* only used for fmi1_xml_type_struct_enu_props (in fmi1_xml_real_type_props_t) */
67     char isFixed;   /* only used for fmi1_xml_type_struct_enu_start*/
68 };
69
70 /* Variable type definition is general and is used for all types*/
71 struct fmi1_xml_variable_typedef_t {
72     fmi1_xml_variable_type_base_t typeBase;
73     jm_string description;
74     char typeName[1];
75 };
76
77 typedef struct fmi1_xml_real_type_props_t {
78     fmi1_xml_variable_type_base_t typeBase;
79     jm_string quantity;
80
81     fmi1_xml_display_unit_t* displayUnit;
82
83     double typeMin;
84     double typeMax;
85     double typeNominal;
86 } fmi1_xml_real_type_props_t;
87
88 typedef struct fmi1_xml_integer_type_props_t {
89     fmi1_xml_variable_type_base_t typeBase;
90
91     jm_string  quantity;
92
93     int typeMin;
94     int typeMax;
95 } fmi1_xml_integer_type_props_t;
96
97 typedef fmi1_xml_variable_type_base_t fmi1_xml_string_type_props_t;
98 typedef fmi1_xml_variable_type_base_t fmi1_xml_bool_type_props_t;
99
100 typedef struct fmi1_xml_enum_type_item_t {
101     jm_string itemName;
102     char itemDesciption[1];
103 } fmi1_xml_enum_type_item_t;
104
105 typedef struct fmi1_xml_enum_type_props_t {
106     fmi1_xml_variable_type_base_t typeBase;
107
108     jm_string quantity;
109     int typeMin;
110     int typeMax;
111     jm_vector(jm_named_ptr) enumItems;
112 } fmi1_xml_enum_type_props_t;
113
114 typedef struct fmi1_xml_variable_start_real_t {
115     fmi1_xml_variable_type_base_t typeBase;
116     double start;
117 } fmi1_xml_variable_start_real_t ;
118
119 /* fmi1_xml_variable_start_integer is used for boolean and enums as well*/
120 typedef struct fmi1_xml_variable_start_integer_t {
121     fmi1_xml_variable_type_base_t typeBase;
122     int start;
123 } fmi1_xml_variable_start_integer_t ;
124
125 typedef struct fmi1_xml_variable_start_string_t {
126     fmi1_xml_variable_type_base_t typeBase;
127     char start[1];
128 } fmi1_xml_variable_start_string_t;
129
130 static fmi1_xml_variable_type_base_t* fmi1_xml_find_type_struct(fmi1_xml_variable_type_base_t* type, fmi1_xml_type_struct_kind_enu_t kind) {
131     fmi1_xml_variable_type_base_t* typeBase = type;
132     while(typeBase) {
133         if(typeBase->structKind == kind) return typeBase;
134         typeBase = typeBase->baseTypeStruct;
135     }
136     return 0;
137 }
138
139 static fmi1_xml_variable_type_base_t* fmi1_xml_find_type_props(fmi1_xml_variable_type_base_t* type) {
140     fmi1_xml_variable_type_base_t* typeBase = type;
141     while(typeBase) {
142         if((typeBase->structKind == fmi1_xml_type_struct_enu_base)
143                         || (typeBase->structKind == fmi1_xml_type_struct_enu_props)) return typeBase;
144         typeBase = typeBase->baseTypeStruct;
145     }   
146     return 0;
147 }
148
149 struct fmi1_xml_type_definitions_t {
150     jm_vector(jm_named_ptr) typeDefinitions;
151
152     jm_string_set quantities;
153
154     fmi1_xml_variable_type_base_t* typePropsList;
155
156     fmi1_xml_real_type_props_t defaultRealType;
157     fmi1_xml_enum_type_props_t defaultEnumType;
158     fmi1_xml_integer_type_props_t defaultIntegerType;
159     fmi1_xml_bool_type_props_t defaultBooleanType;
160     fmi1_xml_string_type_props_t defaultStringType;
161 };
162
163 extern void fmi1_xml_init_type_definitions(fmi1_xml_type_definitions_t* td, jm_callbacks* cb) ;
164
165 extern void fmi1_xml_free_type_definitions_data(fmi1_xml_type_definitions_t* td);
166
167 extern void fmi1_xml_init_integer_typedef(fmi1_xml_integer_typedef_t* type);
168
169 extern void fmi1_xml_init_enum_typedef(fmi1_xml_enumeration_typedef_t* type, jm_callbacks* cb);
170
171 extern void fmi1_xml_free_enum_type(jm_named_ptr named);
172
173 fmi1_xml_variable_type_base_t* fmi1_xml_alloc_variable_type_props(fmi1_xml_type_definitions_t* td, fmi1_xml_variable_type_base_t* base, size_t typeSize);
174
175 fmi1_xml_variable_type_base_t* fmi1_xml_alloc_variable_type_start(fmi1_xml_type_definitions_t* td,fmi1_xml_variable_type_base_t* base, size_t typeSize);
176
177 fmi1_xml_real_type_props_t* fmi1_xml_parse_real_type_properties(fmi1_xml_parser_context_t* context, fmi1_xml_elm_enu_t elmID);
178
179 fmi1_xml_integer_type_props_t *fmi1_xml_parse_integer_type_properties(fmi1_xml_parser_context_t* context, fmi1_xml_elm_enu_t elmID);
180
181 extern int fmi1_check_last_elem_is_specific_type(fmi1_xml_parser_context_t *context);
182
183 extern jm_named_ptr fmi1_xml_variable_type_alloc(fmi1_xml_parser_context_t* context, jm_vector(char)* name, jm_vector(char)* description, size_t size);
184
185 extern void* fmi1_xml_variable_type_create(fmi1_xml_parser_context_t* context, size_t size, jm_vector(jm_named_ptr)* typeList );
186
187 extern fmi1_xml_real_typedef_t* fmi1_xml_variable_type_create_real(fmi1_xml_parser_context_t* context, fmi1_xml_elm_enu_t elmID, jm_vector(jm_named_ptr)* typeList );
188
189 extern fmi1_xml_integer_typedef_t* fmi1_xml_variable_type_create_integer(fmi1_xml_parser_context_t* context, fmi1_xml_elm_enu_t elmID, jm_vector(jm_named_ptr)* typeList );
190
191 fmi1_xml_variable_type_base_t* fmi1_get_declared_type(fmi1_xml_parser_context_t *context, fmi1_xml_elm_enu_t elmID, fmi1_xml_variable_type_base_t* defaultType);
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif /* FMI1_XML_TYPEIMPL_H */