Skip to content

Commit

Permalink
Moving actual header to /include + cleanup of imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Meisrimel authored and Peter Meisrimel committed Aug 9, 2024
1 parent 510b5bc commit 863532c
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 64 deletions.
8 changes: 4 additions & 4 deletions Config.cmake/fmixml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ set(FMIXMLHEADERS
src/FMI/fmi_xml_context_impl.h
include/FMI/fmi_xml_terminals_and_icons.h
src/FMI/fmi_xml_terminals_and_icons_impl.h
src/FMI/fmi_xml_terminals_and_icons_scheme.h
include/FMI/fmi_xml_terminals_and_icons_scheme.h

include/FMI1/fmi1_xml_model_description.h
src/FMI1/fmi1_xml_model_description_impl.h
Expand Down Expand Up @@ -140,7 +140,7 @@ set(FMIXMLHEADERS
src/FMI3/fmi3_xml_model_description_impl.h
include/FMI3/fmi3_xml_model_structure.h
src/FMI3/fmi3_xml_model_structure_impl.h
src/FMI3/fmi3_xml_model_description_scheme.h
include/FMI3/fmi3_xml_model_description_scheme.h
src/FMI3/fmi3_xml_parser_util.h
src/FMI3/fmi3_xml_parser.h
include/FMI3/fmi3_xml_type.h
Expand All @@ -149,8 +149,8 @@ set(FMIXMLHEADERS
src/FMI3/fmi3_xml_unit_impl.h
include/FMI3/fmi3_xml_variable.h
src/FMI3/fmi3_xml_variable_impl.h
src/FMI3/fmi3_xml_parser_scheme.h
src/FMI3/fmi3_xml_parser_scheme_base.h
include/FMI3/fmi3_xml_parser_scheme.h
include/FMI3/fmi3_xml_parser_scheme_base.h
src/FMI3/fmi3_xml_parser_context_impl.h
src/
)
Expand Down
1 change: 0 additions & 1 deletion src/XML/include/FMI/fmi_xml_terminals_and_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define FMI_XML_TERMINALS_AND_ICONS_H_

#include <JM/jm_callbacks.h>
#include <JM/jm_named_ptr.h>
#include <FMI3/fmi3_xml_callbacks.h>
#include <FMI2/fmi2_xml_model_description.h>
#include <FMI3/fmi3_xml_model_description.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef FMI_XML_TERMINALS_AND_ICONS_SCEHEME_H
#define FMI_XML_TERMINALS_AND_ICONS_SCEHEME_H

#include "../FMI3/fmi3_xml_parser_scheme_base.h"
#include <FMI3/fmi3_xml_parser_scheme_base.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -38,7 +38,7 @@ extern "C" {
EXPAND_XML_ELMNAME(TerminalGraphicalRepresentation)

/** \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?
#define FMI_XML_ELMLIST_ALT_TERM_ICON(EXPAND_XML_ELMNAME)

/*
Define XML schema structure. Used to build the 'fmi_xml_scheme_termIcon_info_t' type (in fmi3_xml_parser.c).
Expand All @@ -55,7 +55,6 @@ extern "C" {
#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 fmi_xml_scheme_termIcon_TerminalGraphicalRepresentation {fmi_xml_elmID_termIcon_none, fmi_xml_elmID_termIcon_Terminal, 3, 0}

// Attribute enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef FMI3_XML_MODEL_DESCRIPTION_SCHEME_H
#define FMI3_XML_MODEL_DESCRIPTION_SCHEME_H

#include "fmi3_xml_parser_scheme_base.h"
#include <FMI3/fmi3_xml_parser_scheme_base.h>
#include <FMI3/fmi3_enums.h>

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@
*/

/*
This file collects and unifies the XML schemes to be used for parsing.
XML scheme interaction via unified types and APIs.
*/

#ifndef FMI3_XML_XMLPARSER_SCHEME_H
#define FMI3_XML_XMLPARSER_SCHEME_H

#include "../FMI/fmi_xml_terminals_and_icons_scheme.h"
#include "fmi3_xml_model_description_scheme.h"
#include <FMI/fmi_xml_terminals_and_icons_scheme.h>
#include <FMI3/fmi3_xml_model_description_scheme.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Flag for current XML file being handled. */
typedef enum fmi3_xml_type_t {
fmi3_xml_type_modelDescription,
fmi3_xml_type_terminalAndIcons
} fmi3_xml_type_t;

typedef union fmi3_xml_attr_t {
int any; // when used in generic parser/handling context
fmi3_xml_attr_modelDescription_enu_t modelDescription;
Expand All @@ -46,22 +52,16 @@ typedef union fmi3_xml_elm_t {
#define FMI3_ELM(enu) (fmi3_xml_elm_t){.modelDescription = enu}
#define FMI_ELM_TERMICON(enu) (fmi3_xml_elm_t){.termIcon = enu}

// /** Keeps information about the allowed parent element ID, index among siblings in a sequence and if
// multiple elements of this type are allowed in a sequence.
// */
/** Keeps information about the allowed parent element ID, index among siblings in a sequence and if
multiple elements of this type are allowed in a sequence.
*/
typedef struct {
fmi3_xml_elm_t superID; /* ID of super type or NULL if none */
fmi3_xml_elm_t parentID; /* expected parent ID for an element */
int siblingIndex; /* index among siblings */
int multipleAllowed; /* multiple elements of this kind kan come in a sequence as siblings*/
} fmi3_xml_scheme_info_t;

/** Flag for current XML file being handled. */
typedef enum fmi3_xml_type_t {
fmi3_xml_type_modelDescription,
fmi3_xml_type_terminalAndIcons
} fmi3_xml_type_t;

typedef struct fmi3_xml_element_handle_map_t fmi3_xml_element_handle_map_t;
typedef int (*fmi3_xml_element_handle_ft)(fmi3_xml_parser_context_t* context, const char* data);
struct fmi3_xml_element_handle_map_t {
Expand All @@ -74,6 +74,9 @@ jm_string fmi3_xml_get_xml_attr_name(fmi3_xml_parser_context_t* context, const f
fmi3_xml_scheme_info_t fmi3_xml_get_scheme_info(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t enu);
fmi3_xml_element_handle_map_t fmi3_xml_get_element_handle(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t enu);

size_t fmi3_xml_get_attr_enum_size(fmi3_xml_parser_context_t* context);
size_t fmi3_xml_get_elm_enum_size_actual(fmi3_xml_parser_context_t* context);

int fmi3_xml_is_valid_parent(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t child_id, fmi3_xml_elm_t parent_id);
int fmi3_xml_get_super_type_rec(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id);
int fmi3_xml_are_same_type(fmi3_xml_parser_context_t* context, fmi3_xml_elm_t id1, fmi3_xml_elm_t id2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

/*
TODO
Common base functionality for defining a parser scheme, e.g., modelDescription, terminalsAndIcons
*/

#ifndef FMI3_XML_XMLPARSER_SCHEME_BASE_H
Expand Down
7 changes: 3 additions & 4 deletions src/XML/src/FMI/fmi_xml_terminals_and_icons.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
along with this program. If not, contact Modelon AB <http://www.modelon.com>.
*/

#include <stdio.h>

#include "JM/jm_named_ptr.h"
#include <FMI2/fmi2_xml_model_description.h>
#include "../FMI3/fmi3_xml_parser.h"
#include <FMI/fmi_xml_terminals_and_icons.h>
#include "fmi_xml_terminals_and_icons_impl.h"
#include "../FMI3/fmi3_xml_parser_context_impl.h"
#include "../FMI3/fmi3_xml_parser.h"

static const char* module = "FMIXML";

Expand Down
2 changes: 1 addition & 1 deletion src/XML/src/FMI/fmi_xml_terminals_and_icons_scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#include "JM/jm_portability.h"
#include "fmi_xml_terminals_and_icons_scheme.h"
#include <FMI/fmi_xml_terminals_and_icons_scheme.h>

#define ATTR_STR(attr) #attr,
const jm_string fmi_termIcon_xmlAttrNames[fmi_xml_termIcon_attr_number] = {
Expand Down
2 changes: 1 addition & 1 deletion src/XML/src/FMI3/fmi3_xml_model_description_scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#include "JM/jm_portability.h"
#include "fmi3_xml_model_description_scheme.h"
#include <FMI3/fmi3_xml_model_description_scheme.h>

#define ATTR_STR(attr) #attr,
const jm_string fmi3_modelDescription_xmlAttrNames[fmi3_xml_modelDescription_attr_number] = {
Expand Down
34 changes: 2 additions & 32 deletions src/XML/src/FMI3/fmi3_xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#define snprintf _snprintf
#endif

#include "JM/jm_portability.h"
#include "fmi3_xml_parser.h"
#include "fmi3_xml_model_description_impl.h"
#include "../FMI/fmi_xml_terminals_and_icons_impl.h"
#include "fmi3_xml_parser.h"
#include "JM/jm_portability.h"
#include "fmi3_xml_parser_context_impl.h"

static const char* module = "FMI3XML";
Expand Down Expand Up @@ -898,35 +898,6 @@ jm_vector(char)* fmi3_xml_reserve_parse_buffer(fmi3_xml_parser_context_t* contex
return item;
}

// Get size of ATTRIBUTE enum based on xmlType
static size_t fmi3_xml_get_attr_enum_size(fmi3_xml_parser_context_t* context) {
const fmi3_xml_type_t xmlType = context->xmlType;
switch (xmlType) {
case fmi3_xml_type_modelDescription:
return fmi3_xml_get_modelDescription_attr_enum_size();
case fmi3_xml_type_terminalAndIcons:
return fmi_xml_get_termIcon_attr_enum_size();
default:
// erroneous
return 0;
}
}

// Get size of ELEMENT enum based on xmlType
static size_t fmi3_xml_get_elm_enum_size_actual(fmi3_xml_parser_context_t* context) {
const fmi3_xml_type_t xmlType = context->xmlType;
switch (xmlType) {
case fmi3_xml_type_modelDescription:
return fmi3_xml_get_modelDescription_elm_enum_size_actual();
case fmi3_xml_type_terminalAndIcons:
return fmi_xml_get_termIcon_elm_enum_size_actual();
default:
// erroneous
return 0;
}
}

// TODO: Move to better place?
static int fmi3_create_attr_map(fmi3_xml_parser_context_t* context) {
int i;
size_t attrEnumSize = fmi3_xml_get_attr_enum_size(context);
Expand All @@ -945,7 +916,6 @@ static int fmi3_create_attr_map(fmi3_xml_parser_context_t* context) {
return 0;
}

// TODO: Move to better place?
static int fmi3_create_elm_map(fmi3_xml_parser_context_t* context) {
int i;
size_t attrEnumSize = fmi3_xml_get_attr_enum_size(context);
Expand Down
1 change: 0 additions & 1 deletion src/XML/src/FMI3/fmi3_xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <JM/jm_stack.h>
#include <JM/jm_named_ptr.h>
#include <JM/jm_portability.h>
#include <FMI3/fmi3_xml_callbacks.h>

#include <FMI3/fmi3_enums.h>
#include "fmi3_xml_parser_context_impl.h"
Expand Down
4 changes: 2 additions & 2 deletions src/XML/src/FMI3/fmi3_xml_parser_context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <JM/jm_vector.h>
#include <JM/jm_stack.h>

#include <FMI/fmi_xml_terminals_and_icons.h>
#include <FMI3/fmi3_xml_parser_scheme.h>
#include <FMI3/fmi3_xml_model_description.h>
#include "fmi3_xml_parser_scheme.h"
#include <FMI/fmi_xml_terminals_and_icons.h>

#ifdef __cplusplus
extern "C" {
Expand Down
30 changes: 29 additions & 1 deletion src/XML/src/FMI3/fmi3_xml_parser_scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#include "JM/jm_portability.h"
#include "fmi3_xml_parser_scheme.h"
#include <FMI3/fmi3_xml_parser_scheme.h>
#include "fmi3_xml_parser_context_impl.h"

jm_string fmi3_xml_get_xml_attr_name(fmi3_xml_parser_context_t* context, const fmi3_xml_attr_t enu) {
Expand Down Expand Up @@ -93,6 +93,34 @@ fmi3_xml_element_handle_map_t fmi3_xml_get_element_handle(fmi3_xml_parser_contex
return ret;
}

/* Get size of ATTRIBUTE enum based on xmlType */
size_t fmi3_xml_get_attr_enum_size(fmi3_xml_parser_context_t* context) {
const fmi3_xml_type_t xmlType = context->xmlType;
switch (xmlType) {
case fmi3_xml_type_modelDescription:
return fmi3_xml_get_modelDescription_attr_enum_size();
case fmi3_xml_type_terminalAndIcons:
return fmi_xml_get_termIcon_attr_enum_size();
default:
// erroneous
return 0;
}
}

/* Get size of ELEMENT enum based on xmlType */
size_t fmi3_xml_get_elm_enum_size_actual(fmi3_xml_parser_context_t* context) {
const fmi3_xml_type_t xmlType = context->xmlType;
switch (xmlType) {
case fmi3_xml_type_modelDescription:
return fmi3_xml_get_modelDescription_elm_enum_size_actual();
case fmi3_xml_type_terminalAndIcons:
return fmi_xml_get_termIcon_elm_enum_size_actual();
default:
// erroneous
return 0;
}
}

/**
* Returns true if parent element's type or super type (recursively) matches
* the expected type.
Expand Down

0 comments on commit 863532c

Please sign in to comment.