Skip to content

Commit

Permalink
Refactoring; splitting up modelDescription & terminalsAndIcons parsing (
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon authored Aug 8, 2024
1 parent a952a4c commit 8ec1b43
Show file tree
Hide file tree
Showing 15 changed files with 661 additions and 436 deletions.
6 changes: 3 additions & 3 deletions src/XML/src/FMI/fmi_xml_terminals_and_icons.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ int fmi_xml_handle_fmiTerminalsAndIcons(fmi3_xml_parser_context_t* context, cons
fmi_xml_terminals_and_icons_t* termIcon = context->termIcon;
if (!data) {
int ret;
if (context->currentElmID != fmi3_xml_elmID_none) {
if (context->currentElmID.termIcon != fmi_xml_elmID_termIcon_none) {
fmi3_xml_parse_fatal(context, "fmiTerminalsAndIcons must be the root XML element");
return -1;
}
jm_log_verbose(context->callbacks, module, "Parsing XML element fmiTerminalsAndIcons");

ret = fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_fmiTerminalsAndIcons, fmi_attr_id_fmiVersion, 1 /* required */,
ret = fmi3_xml_parse_attr_as_string(context, FMI_ELM_TERMICON(fmi_xml_elmID_termIcon_fmiTerminalsAndIcons), FMI_ATTR_TERMICON(fmi_attr_id_fmiVersion), 1 /* required */,
&(termIcon->fmi3_xml_standard_version));
if (ret) {
return ret;
Expand Down Expand Up @@ -193,7 +193,7 @@ int fmi_xml_handle_Terminal(fmi3_xml_parser_context_t* context, const char* data
// parse name
jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context, bufIdx++, 100);
if (!bufName) {return -1;}
if (fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Terminal, fmi_attr_id_name, 1 /* required */, bufName)) {return -1;}
if (fmi3_xml_parse_attr_as_string(context, FMI_ELM_TERMICON(fmi_xml_elmID_termIcon_Terminal), FMI_ATTR_TERMICON(fmi_attr_id_name), 1 /* required */, bufName)) {return -1;}

/* Add the name to the terminalsAndIcons-wide set and retrieve the pointer */
if (jm_vector_get_size(char)(bufName)) {
Expand Down
27 changes: 14 additions & 13 deletions src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
extern "C" {
#endif

/* Attributes common to modelDescription.xml & terminalsAndIcons.xml
* are listed in FMI3_XML_ATTRLIST_COMMON in fmi3_xml_parser.h
*/
#define FMI_XML_ATTRLIST_TERM_ICON(EXPAND_XML_ATTRNAME) // XXX: Currently empty, but will be filled
/* Attribute names found in terminalsAndIcons.xml */
#define FMI_XML_ATTRLIST_TERM_ICON(EXPAND_XML_ATTRNAME) \
EXPAND_XML_ATTRNAME(fmiVersion) \
EXPAND_XML_ATTRNAME(name) \
EXPAND_XML_ATTRNAME(description)

/* Element names found in terminalsAndIcons.xml */
#define FMI_XML_ELMLIST_TERM_ICON(EXPAND_XML_ELMNAME) \
EXPAND_XML_ELMNAME(fmiTerminalsAndIcons) \
EXPAND_XML_ELMNAME(Terminals) \
Expand All @@ -36,24 +38,23 @@ extern "C" {
/** \brief Element that can be placed under different parents get alternative names from the info struct */
#define FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_XML_ELMNAME) // TODO: Terminal should go here?

// XXX: fmi3_xml_elmID_none is defined in fmi3_xml_parser.h, not good style
/*
Define XML schema structure. Used to build the 'fmi3_xml_scheme_info_t' type (in fmi3_xml_parser.c).
Define XML schema structure. Used to build the 'fmi_xml_scheme_termIcon_info_t' type (in fmi3_xml_parser.c).
@sib_idx:
the index in a sequence among siblings
@multi_elem:
if the parent can have multiple elements of this type
*/
/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */
#define fmi3_xml_scheme_fmiTerminalsAndIcons {fmi3_xml_elmID_none, fmi3_xml_elmID_none, 0, 0}
/* scheme_ID, super_type, parent_ID, sib_idx, multi_elem */
#define fmi_xml_scheme_termIcon_fmiTerminalsAndIcons {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_none, 0, 0}

#define fmi3_xml_scheme_Terminals {fmi3_xml_elmID_none, fmi3_xml_elmID_fmiTerminalsAndIcons, 1, 0}
#define fmi3_xml_scheme_Terminal {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminals, 0, 1}
#define fmi3_xml_scheme_TerminalMemberVariable {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 0, 1}
#define fmi3_xml_scheme_TerminalStreamMemberVariable {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 1, 1}
#define fmi_xml_scheme_termIcon_Terminals {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_fmiTerminalsAndIcons, 1, 0}
#define fmi_xml_scheme_termIcon_Terminal {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminals, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 0, 1}
#define fmi_xml_scheme_termIcon_TerminalStreamMemberVariable {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 1, 1}
// TODO: How to handle nested Terminals?
#define fmi3_xml_scheme_TerminalGraphicalRepresentation {fmi3_xml_elmID_none, fmi3_xml_elmID_Terminal, 3, 0}
#define fmi_xml_scheme_termIcon_TerminalGraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 3, 0}

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion src/XML/src/FMI2/fmi2_xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ struct fmi2_xml_parser_context_t {
jm_vector(char) elmData;

/**
* Element ID of the last processed sibling, or fmi3_xml_elmID_none if
* Element ID of the last processed sibling, or fmi2_xml_elmID_none if
* no siblings have been processed.
*/
fmi2_xml_elm_enu_t lastElmID;
Expand Down
Loading

0 comments on commit 8ec1b43

Please sign in to comment.