2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
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.
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>.
16 #ifndef FMI1_XML_TYPEIMPL_H
17 #define FMI1_XML_TYPEIMPL_H
19 #include <JM/jm_named_ptr.h>
20 #include <JM/jm_string_set.h>
21 #include <FMI1/fmi1_xml_model_description.h>
23 #include "fmi1_xml_parser.h"
29 /** \defgroup Type definitions supporting structures
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.
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
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.
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;
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 */
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*/
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*/
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;
77 typedef struct fmi1_xml_real_type_props_t {
78 fmi1_xml_variable_type_base_t typeBase;
81 fmi1_xml_display_unit_t* displayUnit;
86 } fmi1_xml_real_type_props_t;
88 typedef struct fmi1_xml_integer_type_props_t {
89 fmi1_xml_variable_type_base_t typeBase;
95 } fmi1_xml_integer_type_props_t;
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;
100 typedef struct fmi1_xml_enum_type_item_t {
102 char itemDesciption[1];
103 } fmi1_xml_enum_type_item_t;
105 typedef struct fmi1_xml_enum_type_props_t {
106 fmi1_xml_variable_type_base_t typeBase;
111 jm_vector(jm_named_ptr) enumItems;
112 } fmi1_xml_enum_type_props_t;
114 typedef struct fmi1_xml_variable_start_real_t {
115 fmi1_xml_variable_type_base_t typeBase;
117 } fmi1_xml_variable_start_real_t ;
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;
123 } fmi1_xml_variable_start_integer_t ;
125 typedef struct fmi1_xml_variable_start_string_t {
126 fmi1_xml_variable_type_base_t typeBase;
128 } fmi1_xml_variable_start_string_t;
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;
133 if(typeBase->structKind == kind) return typeBase;
134 typeBase = typeBase->baseTypeStruct;
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;
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;
149 struct fmi1_xml_type_definitions_t {
150 jm_vector(jm_named_ptr) typeDefinitions;
152 jm_string_set quantities;
154 fmi1_xml_variable_type_base_t* typePropsList;
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;
163 extern void fmi1_xml_init_type_definitions(fmi1_xml_type_definitions_t* td, jm_callbacks* cb) ;
165 extern void fmi1_xml_free_type_definitions_data(fmi1_xml_type_definitions_t* td);
167 extern void fmi1_xml_init_integer_typedef(fmi1_xml_integer_typedef_t* type);
169 extern void fmi1_xml_init_enum_typedef(fmi1_xml_enumeration_typedef_t* type, jm_callbacks* cb);
171 extern void fmi1_xml_free_enum_type(jm_named_ptr named);
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);
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);
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);
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);
181 extern int fmi1_check_last_elem_is_specific_type(fmi1_xml_parser_context_t *context);
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);
185 extern void* fmi1_xml_variable_type_create(fmi1_xml_parser_context_t* context, size_t size, jm_vector(jm_named_ptr)* typeList );
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 );
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 );
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);
197 #endif /* FMI1_XML_TYPEIMPL_H */