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>.
18 #include "fmi1_xml_parser.h"
19 #include "fmi1_xml_model_description_impl.h"
20 #include "fmi1_xml_vendor_annotations_impl.h"
22 static const char* module = "FMI1XML";
24 void fmi1_xml_vendor_free(fmi1_xml_vendor_t* v) {
25 jm_named_vector_free_data(&v->annotations);
26 v->annotations.callbacks->free(v);
29 const char* fmi1_xml_get_vendor_name(fmi1_xml_vendor_t* v) {
33 unsigned int fmi1_xml_get_number_of_vendor_annotations(fmi1_xml_vendor_t* v) {
34 return (unsigned int)jm_vector_get_size(jm_named_ptr)(&v->annotations);
37 fmi1_xml_annotation_t* fmi1_xml_get_vendor_annotation(fmi1_xml_vendor_t* v, unsigned int index) {
38 if(index >= fmi1_xml_get_number_of_vendor_annotations(v)) return 0;
39 return jm_vector_get_item(jm_named_ptr)(&v->annotations, index).ptr;
42 const char* fmi1_xml_get_annotation_name(fmi1_xml_annotation_t* a) {
46 const char* fmi1_xml_get_annotation_value(fmi1_xml_annotation_t* a) {
50 int fmi1_xml_handle_VendorAnnotations(fmi1_xml_parser_context_t *context, const char* data) {
52 jm_log_verbose(context->callbacks, module, "Parsing XML element VendorAnnotations");
55 /* might give out a warning if(data[0] != 0) */
60 int fmi1_xml_handle_Tool(fmi1_xml_parser_context_t *context, const char* data) {
62 fmi1_xml_model_description_t* md = context->modelDescription;
63 jm_vector(char)* bufName = fmi1_xml_reserve_parse_buffer(context,1,100);
64 fmi1_xml_vendor_t* vendor = 0;
65 fmi1_xml_vendor_t dummyV;
68 if(!bufName) return -1;
69 /* <xs:attribute name="name" type="xs:normalizedString" use="required"> */
70 if( fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Tool, fmi_attr_id_name, 1, bufName)) return -1;
71 pvendor = jm_vector_push_back(jm_voidp)(&md->vendorList, vendor);
73 *pvendor = vendor = jm_named_alloc_v(bufName,sizeof(fmi1_xml_vendor_t), dummyV.name - (char*)&dummyV, context->callbacks).ptr;
74 if(!pvendor || !vendor) {
75 fmi1_xml_parse_fatal(context, "Could not allocate memory");
78 jm_vector_init(jm_named_ptr)(&vendor->annotations,0, context->callbacks);
81 /* don't do anything. might give out a warning if(data[0] != 0) */
86 int fmi1_xml_handle_Annotation(fmi1_xml_parser_context_t *context, const char* data) {
88 fmi1_xml_model_description_t* md = context->modelDescription;
89 size_t numVendors = jm_vector_get_size(jm_voidp)(&(md->vendorList));
90 fmi1_xml_vendor_t* vendor =(fmi1_xml_vendor_t*)jm_vector_get_item(jm_voidp)(&(md->vendorList), numVendors-1);
91 jm_vector(char)* bufName = fmi1_xml_reserve_parse_buffer(context,1,100);
92 jm_vector(char)* bufValue = fmi1_xml_reserve_parse_buffer(context,2,100);
93 jm_named_ptr named, *pnamed;
94 fmi1_xml_annotation_t* annotation = 0;
97 if(!bufName || !bufValue ||
98 /* <xs:attribute name="name" type="xs:normalizedString" use="required"/> */
99 fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Annotation, fmi_attr_id_name, 1, bufName) ||
100 /* <xs:attribute name="value" type="xs:string" use="required"/> */
101 fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Annotation, fmi_attr_id_value, 1, bufValue)
104 vallen = jm_vector_get_size(char)(bufValue);
107 pnamed = jm_vector_push_back(jm_named_ptr)(&vendor->annotations, named);
109 if(pnamed) *pnamed = named = jm_named_alloc_v(bufName,sizeof(fmi1_xml_annotation_t)+vallen+1,sizeof(fmi1_xml_annotation_t)+vallen,context->callbacks);
110 annotation = named.ptr;
111 if( !pnamed || !annotation ) {
112 fmi1_xml_parse_fatal(context, "Could not allocate memory");
115 annotation->name = named.name;
117 memcpy(annotation->value,jm_vector_get_itemp(char)(bufValue,0), vallen);
118 annotation->value[vallen] = 0;
121 /* don't do anything. might give out a warning if(data[0] != 0) */