]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/XML/src/FMI2/fmi2_xml_vendor_annotations.c
Switch to full JavaSE-11+ compatibility
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / XML / src / FMI2 / fmi2_xml_vendor_annotations.c
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 #include <string.h>
17
18 #include "fmi2_xml_parser.h"
19 #include "fmi2_xml_model_description_impl.h"
20
21 static const char* module = "FMI2XML";
22
23
24 int fmi2_xml_handle_VendorAnnotations(fmi2_xml_parser_context_t *context, const char* data) {
25     if(!data) {
26                 jm_log_verbose(context->callbacks, module, "Parsing XML element VendorAnnotations");
27         }
28     else {
29         /* might give out a warning if(data[0] != 0) */
30     }
31     return 0;
32 }
33
34 int fmi2_xml_handle_Annotations(fmi2_xml_parser_context_t *context, const char* data) {
35     if(!data) {
36                 jm_log_verbose(context->callbacks, module, "Parsing XML element Annotations");
37         }
38     else {
39         /* might give out a warning if(data[0] != 0) */
40     }
41     return 0;
42 }
43
44 int fmi2_xml_handle_VariableTool(fmi2_xml_parser_context_t *context, const char* data) {
45     if(!data) {
46                         size_t len;
47             fmi2_xml_model_description_t* md = context->modelDescription;
48             jm_vector(char)* bufName = fmi2_xml_reserve_parse_buffer(context,1,100);
49             jm_string *pvendor;
50                         char* vendor = 0;
51                         
52             if(!bufName) return -1;
53             /* <xs:attribute name="name" type="xs:normalizedString" use="required"> */
54             if( fmi2_xml_set_attr_string(context, fmi2_xml_elmID_Tool, fmi_attr_id_name, 1, bufName))
55                                 return -1;
56             pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor);
57                         len = jm_vector_get_size(char)(bufName);
58             if(pvendor )
59                 *pvendor = vendor = (char*)(context->callbacks->malloc(len + 1));
60                 if(!pvendor || !vendor) {
61                     fmi2_xml_parse_fatal(context, "Could not allocate memory");
62                         return -1;
63                         }
64             memcpy(vendor, jm_vector_get_itemp(char)(bufName,0), len);
65             vendor[len] = 0;
66
67                         context->anyToolName = vendor;
68                         context->anyParent = jm_vector_get_last(jm_named_ptr)(&md->variablesByName).ptr;
69                         context->useAnyHandleFlg = 1;
70     }
71     else {
72         /* don't do anything. might give out a warning if(data[0] != 0) */
73                 context->useAnyHandleFlg = 0;
74         return 0;
75     }
76     return 0;
77 }
78
79 int fmi2_xml_handle_Tool(fmi2_xml_parser_context_t *context, const char* data) {
80     if(!data) {
81                         size_t len;
82             fmi2_xml_model_description_t* md = context->modelDescription;
83             jm_vector(char)* bufName = fmi2_xml_reserve_parse_buffer(context,1,100);
84             jm_string *pvendor;
85                         char* vendor = 0;
86                         
87             if(!bufName) return -1;
88             /* <xs:attribute name="name" type="xs:normalizedString" use="required"> */
89             if( fmi2_xml_set_attr_string(context, fmi2_xml_elmID_Tool, fmi_attr_id_name, 1, bufName))
90                                 return -1;
91             pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor);
92                         len = jm_vector_get_size(char)(bufName);
93             if(pvendor )
94                 *pvendor = vendor = (char*)(context->callbacks->malloc(len + 1));
95                 if(!pvendor || !vendor) {
96                     fmi2_xml_parse_fatal(context, "Could not allocate memory");
97                         return -1;
98                         }
99             memcpy(vendor, jm_vector_get_itemp(char)(bufName,0), len);
100             vendor[len] = 0;
101
102                         context->anyToolName = vendor;
103                         context->anyParent = 0;
104                         context->useAnyHandleFlg = 1;
105     }
106     else {
107         /* don't do anything. might give out a warning if(data[0] != 0) */
108                 context->useAnyHandleFlg = 0;
109         return 0;
110     }
111     return 0;
112 }
113