From 338ea62a70b15f17ad36fd2429df0f840d5a86ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 19:39:44 +0100 Subject: [PATCH 1/4] Revert: Simplify create_assign function in cpp/lang_pack.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Günther --- cimgen/languages/cpp/lang_pack.py | 35 ++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/cimgen/languages/cpp/lang_pack.py b/cimgen/languages/cpp/lang_pack.py index 0522108e..0f22dea9 100644 --- a/cimgen/languages/cpp/lang_pack.py +++ b/cimgen/languages/cpp/lang_pack.py @@ -281,8 +281,9 @@ def create_assign(text, render): if label_without_keyword == "switch": label_without_keyword = "_switch" - assign = ( - """ + if not _attribute_is_primitive_string(attribute_json): + assign = ( + """ bool assign_CLASS_LABEL(std::stringstream &buffer, BaseClass* BaseClass_ptr1) { if (CLASS* element = dynamic_cast(BaseClass_ptr1)) @@ -294,12 +295,30 @@ def create_assign(text, render): return true; } return false; +}""".replace( # noqa: E101,W191 + "CLASS", attribute_json["domain"] + ) + .replace("LABEL", attribute_json["label"]) + .replace("LBL_WO_KEYWORD", label_without_keyword) + ) + else: # _attribute_is_primitive_string + assign = """ +bool assign_CLASS_LABEL(std::stringstream &buffer, BaseClass* BaseClass_ptr1) +{ + if (CLASS* element = dynamic_cast(BaseClass_ptr1)) + { + element->LABEL = buffer.str(); + if (buffer.fail()) + return false; + else + return true; + } + return false; }""".replace( # noqa: E101,W191 "CLASS", attribute_json["domain"] + ).replace( + "LABEL", attribute_json["label"] ) - .replace("LABEL", attribute_json["label"]) - .replace("LBL_WO_KEYWORD", label_without_keyword) - ) return assign @@ -387,6 +406,12 @@ def _attribute_is_primitive_or_datatype(attribute: dict) -> bool: return attribute["is_primitive_attribute"] or attribute["is_datatype_attribute"] +def _attribute_is_primitive_string(attribute: dict) -> bool: + return attribute["is_primitive_attribute"] and ( + attribute["attribute_class"] not in ("Float", "Decimal", "Integer", "Boolean") + ) + + # The code below this line is used after the main cim_generate phase to generate # two include files. They are called CIMClassList.hpp and IEC61970.hpp, and # contain the list of the class files and the list of define functions that add From 85518082906a04b00cd2c96b0abd8d1db97d115c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sun, 27 Oct 2024 21:24:27 +0100 Subject: [PATCH 2/4] Improve generated cpp classes: add rdfid to BaseClass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Günther --- cimgen/languages/cpp/static/BaseClass.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cimgen/languages/cpp/static/BaseClass.hpp b/cimgen/languages/cpp/static/BaseClass.hpp index 7af998c6..680172a8 100644 --- a/cimgen/languages/cpp/static/BaseClass.hpp +++ b/cimgen/languages/cpp/static/BaseClass.hpp @@ -12,10 +12,14 @@ class BaseClass { + std::string rdfid; public: enum cgmesProfile {EQ = 0, SSH = 1, TP = 2, SV = 3, DY = 4, GL = 5, DI = 6}; virtual ~BaseClass(); + void setRdfid(const std::string& id) { rdfid = id; } + std::string getRdfid() const { return rdfid; } + static const char debugName[]; virtual const char* debugString() const; From aebcf0c65c3e58f06d3e067ef88ae0781164492f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sun, 27 Oct 2024 21:53:05 +0100 Subject: [PATCH 3/4] Add generation of CGMESProfile class for cpp, add profile URIs and cim namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Günther --- cimgen/languages/cpp/lang_pack.py | 19 ++- cimgen/languages/cpp/static/BaseClass.cpp | 3 + cimgen/languages/cpp/static/BaseClass.hpp | 7 +- .../cpp_cgmesProfile_header_template.mustache | 30 +++++ .../cpp_cgmesProfile_object_template.mustache | 110 ++++++++++++++++++ .../templates/cpp_header_template.mustache | 5 + .../templates/cpp_object_template.mustache | 29 +++++ 7 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 cimgen/languages/cpp/templates/cpp_cgmesProfile_header_template.mustache create mode 100644 cimgen/languages/cpp/templates/cpp_cgmesProfile_object_template.mustache diff --git a/cimgen/languages/cpp/lang_pack.py b/cimgen/languages/cpp/lang_pack.py index 0f22dea9..755757df 100644 --- a/cimgen/languages/cpp/lang_pack.py +++ b/cimgen/languages/cpp/lang_pack.py @@ -11,14 +11,14 @@ def location(version): # NOSONAR # Setup called only once: make output directory, create base class, create profile class, etc. # This just makes sure we have somewhere to write the classes. # cgmes_profile_details contains index, names and uris for each profile. -# We don't use that here because we aren't exporting into -# separate profiles. +# We use that to create the header data for the profiles. def setup(output_path: str, cgmes_profile_details: list, cim_namespace: str): # NOSONAR if not os.path.exists(output_path): os.makedirs(output_path) else: for filename in os.listdir(output_path): os.remove(os.path.join(output_path, filename)) + _create_cgmes_profile(output_path, cgmes_profile_details, cim_namespace) base = {"base_class": "BaseClass", "class_location": location} @@ -43,6 +43,10 @@ def setup(output_path: str, cgmes_profile_details: list, cim_namespace: str): # {"filename": "cpp_string_header_template.mustache", "ext": ".hpp"}, {"filename": "cpp_string_object_template.mustache", "ext": ".cpp"}, ] +profile_template_files = [ + {"filename": "cpp_cgmesProfile_header_template.mustache", "ext": ".hpp"}, + {"filename": "cpp_cgmesProfile_object_template.mustache", "ext": ".cpp"}, +] def get_class_location(class_name, class_map, version): # NOSONAR @@ -92,6 +96,16 @@ def _write_templated_file(class_file, class_details, template_filename): file.write(output) +def _create_cgmes_profile(output_path: str, profile_details: list, cim_namespace: str): + for template_info in profile_template_files: + class_file = os.path.join(output_path, "CGMESProfile" + template_info["ext"]) + class_details = { + "profiles": profile_details, + "cim_namespace": cim_namespace, + } + _write_templated_file(class_file, class_details, template_info["filename"]) + + # This function just allows us to avoid declaring a variable called 'switch', # which is in the definition of the ExcBBC class. def label(text, render): @@ -421,6 +435,7 @@ def _attribute_is_primitive_string(attribute: dict) -> bool: "assignments", "BaseClass", "BaseClassDefiner", + "CGMESProfile", "CIMClassList", "CIMFactory", "CIMNamespaces", diff --git a/cimgen/languages/cpp/static/BaseClass.cpp b/cimgen/languages/cpp/static/BaseClass.cpp index ff3a94a5..5baf1c2c 100644 --- a/cimgen/languages/cpp/static/BaseClass.cpp +++ b/cimgen/languages/cpp/static/BaseClass.cpp @@ -4,6 +4,9 @@ using namespace CIMPP; BaseClass::~BaseClass() {} +std::list BaseClass::getPossibleProfilesForClass() const { return {}; } +std::map> BaseClass::getPossibleProfilesForAttributes() const { return {}; } + const char BaseClass::debugName[] = "BaseClass"; const char* BaseClass::debugString() const { diff --git a/cimgen/languages/cpp/static/BaseClass.hpp b/cimgen/languages/cpp/static/BaseClass.hpp index 680172a8..a5b797f3 100644 --- a/cimgen/languages/cpp/static/BaseClass.hpp +++ b/cimgen/languages/cpp/static/BaseClass.hpp @@ -5,16 +5,18 @@ #define CGMES_BUILD #endif +#include +#include #include #include #include "BaseClassDefiner.hpp" +#include "CGMESProfile.hpp" class BaseClass { std::string rdfid; public: - enum cgmesProfile {EQ = 0, SSH = 1, TP = 2, SV = 3, DY = 4, GL = 5, DI = 6}; virtual ~BaseClass(); void setRdfid(const std::string& id) { rdfid = id; } @@ -23,6 +25,9 @@ class BaseClass static const char debugName[]; virtual const char* debugString() const; + virtual std::list getPossibleProfilesForClass() const; + virtual std::map> getPossibleProfilesForAttributes() const; + static void addConstructToMap(std::unordered_map& factory_map); static void addPrimitiveAssignFnsToMap(std::unordered_map& assign_map); static void addClassAssignFnsToMap(std::unordered_map& assign_map); diff --git a/cimgen/languages/cpp/templates/cpp_cgmesProfile_header_template.mustache b/cimgen/languages/cpp/templates/cpp_cgmesProfile_header_template.mustache new file mode 100644 index 00000000..41200a10 --- /dev/null +++ b/cimgen/languages/cpp/templates/cpp_cgmesProfile_header_template.mustache @@ -0,0 +1,30 @@ +#ifndef CGMESPROFILE_HPP +#define CGMESPROFILE_HPP +/* +Generated from the CGMES files via cimgen: https://github.com/sogno-platform/cimgen +*/ + +#include +#include + +enum class CGMESProfile : unsigned short +{ +{{#profiles}} + {{short_name}}, +{{/profiles}} +}; + +const CGMESProfile UnknownProfile = static_cast(-1); + +const std::list& getProfileList(); + +std::string getProfileShortName(CGMESProfile profile); +std::string getProfileLongName(CGMESProfile profile); +const std::list& getProfileURIs(CGMESProfile profile); + +CGMESProfile getProfileFromShortName(const std::string& name); +CGMESProfile getProfileFromLongName(const std::string& name); + +std::string getCimNamespace(); + +#endif // CGMESPROFILE_HPP diff --git a/cimgen/languages/cpp/templates/cpp_cgmesProfile_object_template.mustache b/cimgen/languages/cpp/templates/cpp_cgmesProfile_object_template.mustache new file mode 100644 index 00000000..a5e013a1 --- /dev/null +++ b/cimgen/languages/cpp/templates/cpp_cgmesProfile_object_template.mustache @@ -0,0 +1,110 @@ +/* +Generated from the CGMES files via cimgen: https://github.com/sogno-platform/cimgen +*/ +#include "CGMESProfile.hpp" + +#include +#include +#include + +static const std::list ProfileList = +{ +{{#profiles}} + CGMESProfile::{{short_name}}, +{{/profiles}} +}; + +static const std::map ProfileShortNames = +{ +{{#profiles}} + { CGMESProfile::{{short_name}}, "{{short_name}}" }, +{{/profiles}} +}; + +static const std::map ProfileLongNames = +{ +{{#profiles}} + { CGMESProfile::{{short_name}}, "{{long_name}}" }, +{{/profiles}} +}; + +static const std::map> ProfileURIs = +{ +{{#profiles}} + { CGMESProfile::{{short_name}}, { {{#uris}}"{{uri}}", {{/uris}}} }, +{{/profiles}} +}; + +static const std::string CimNamespace = "{{cim_namespace}}"; + +const std::list& +getProfileList() +{ + return ProfileList; +} + +std::string +getProfileShortName(CGMESProfile profile) +{ + auto it = ProfileShortNames.find(profile); + if (it != ProfileShortNames.end()) + { + return it->second; + } + return ""; // unknown profile +} + +std::string +getProfileLongName(CGMESProfile profile) +{ + auto it = ProfileLongNames.find(profile); + if (it != ProfileLongNames.end()) + { + return it->second; + } + return ""; // unknown profile +} + +const std::list& +getProfileURIs(CGMESProfile profile) +{ + static std::list empty_list; + auto it = ProfileURIs.find(profile); + if (it != ProfileURIs.end()) + { + return it->second; + } + return empty_list; // unknown profile +} + +CGMESProfile +getProfileFromShortName(const std::string& name) +{ + for (const auto& profile : ProfileShortNames) + { + if (name == profile.second) + { + return profile.first; + } + } + return UnknownProfile; +} + +CGMESProfile +getProfileFromLongName(const std::string& name) +{ + for (const auto& profile : ProfileLongNames) + { + if (name == profile.second) + { + return profile.first; + } + } + return UnknownProfile; +} + +std::string +getCimNamespace() +{ + return CimNamespace; +} diff --git a/cimgen/languages/cpp/templates/cpp_header_template.mustache b/cimgen/languages/cpp/templates/cpp_header_template.mustache index 2d8322de..58a15482 100644 --- a/cimgen/languages/cpp/templates/cpp_header_template.mustache +++ b/cimgen/languages/cpp/templates/cpp_header_template.mustache @@ -5,11 +5,13 @@ Generated from the CGMES files via cimgen: https://github.com/sogno-platform/cim */ #include +#include #include #include #include "{{sub_class_of}}.hpp" #include "BaseClassDefiner.hpp" +#include "CGMESProfile.hpp" {{#langPack._create_attribute_includes}}{{attributes}}{{/langPack._create_attribute_includes}} namespace CIMPP { @@ -33,6 +35,9 @@ namespace CIMPP static const char debugName[]; const char* debugString() const override; + std::list getPossibleProfilesForClass() const override; + std::map> getPossibleProfilesForAttributes() const override; + static void addConstructToMap(std::unordered_map& factory_map); static void addPrimitiveAssignFnsToMap(std::unordered_map& assign_map); static void addClassAssignFnsToMap(std::unordered_map& assign_map); diff --git a/cimgen/languages/cpp/templates/cpp_object_template.mustache b/cimgen/languages/cpp/templates/cpp_object_template.mustache index eec1a96b..845dd25e 100644 --- a/cimgen/languages/cpp/templates/cpp_object_template.mustache +++ b/cimgen/languages/cpp/templates/cpp_object_template.mustache @@ -15,6 +15,35 @@ using namespace CIMPP; {{class_name}}::{{class_name}}(){{#langPack.create_nullptr_assigns}} {{attributes}} {{/langPack.create_nullptr_assigns}} {}; {{class_name}}::~{{class_name}}() {}; +static const std::list PossibleProfilesForClass = +{ +{{#class_origin}} + CGMESProfile::{{origin}}, +{{/class_origin}} +}; + +static const std::map> PossibleProfilesForAttributes = +{ +{{#attributes}} + { "cim:{{about}}", { {{#attr_origin}}CGMESProfile::{{origin}}, {{/attr_origin}}} }, +{{/attributes}} +}; + +std::list +{{class_name}}::getPossibleProfilesForClass() const +{ + return PossibleProfilesForClass; +} + +std::map> +{{class_name}}::getPossibleProfilesForAttributes() const +{ + auto map = PossibleProfilesForAttributes; + auto&& parent_map = {{sub_class_of}}::getPossibleProfilesForAttributes(); + map.insert(parent_map.begin(), parent_map.end()); + return map; +} + {{#attributes}} {{#langPack.create_assign}}{{.}}{{/langPack.create_assign}} {{/attributes}} From 2ead869896bdee4407a27a071b244ad65c584786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sun, 27 Oct 2024 23:27:09 +0100 Subject: [PATCH 4/4] Add generation of getter functions for cpp (this will be used by CIM writer to export CIM data into several files based on CGMES profiles) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Günther --- cimgen/languages/cpp/lang_pack.py | 141 ++++++++++++++++++ cimgen/languages/cpp/static/BaseClass.cpp | 3 + cimgen/languages/cpp/static/BaseClass.hpp | 7 + .../templates/cpp_header_template.mustache | 3 + .../templates/cpp_object_template.mustache | 38 +++++ 5 files changed, 192 insertions(+) diff --git a/cimgen/languages/cpp/lang_pack.py b/cimgen/languages/cpp/lang_pack.py index 755757df..40cf466c 100644 --- a/cimgen/languages/cpp/lang_pack.py +++ b/cimgen/languages/cpp/lang_pack.py @@ -58,6 +58,9 @@ def get_class_location(class_name, class_map, version): # NOSONAR "label": "{{#langPack.label}}{{label}}{{/langPack.label}}", "insert_assign": "{{#langPack.insert_assign_fn}}{{.}}{{/langPack.insert_assign_fn}}", "insert_class_assign": "{{#langPack.insert_class_assign_fn}}{{.}}{{/langPack.insert_class_assign_fn}}", + "insert_get": "{{#langPack.insert_get_fn}}{{.}}{{/langPack.insert_get_fn}}", + "insert_class_get": "{{#langPack.insert_class_get_fn}}{{.}}{{/langPack.insert_class_get_fn}}", + "insert_enum_get": "{{#langPack.insert_enum_get_fn}}{{.}}{{/langPack.insert_enum_get_fn}}", } @@ -160,6 +163,38 @@ def insert_class_assign_fn(text, render): ) +def insert_get_fn(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + if not _attribute_is_primitive_or_datatype(attribute_json): + return "" + label = attribute_json["label"] + class_name = attribute_json["domain"] + return ' get_map.emplace("cim:' + class_name + "." + label + '", &get_' + class_name + "_" + label + ");\n" + + +def insert_class_get_fn(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + if _attribute_is_primitive_or_datatype_or_enum(attribute_json): + return "" + if not attribute_json["is_used"]: + return "" + label = attribute_json["label"] + class_name = attribute_json["domain"] + return ' get_map.emplace("cim:' + class_name + "." + label + '", &get_' + class_name + "_" + label + ");\n" + + +def insert_enum_get_fn(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + if not attribute_json["is_enum_attribute"]: + return "" + label = attribute_json["label"] + class_name = attribute_json["domain"] + return ' get_map.emplace("cim:' + class_name + "." + label + '", &get_' + class_name + "_" + label + ");\n" + + def create_nullptr_assigns(text, render): attributes_txt = render(text) if attributes_txt.strip() == "": @@ -337,6 +372,112 @@ def create_assign(text, render): return assign +def create_class_get(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + if _attribute_is_primitive_or_datatype_or_enum(attribute_json): + return "" + if not attribute_json["is_used"]: + return "" + if attribute_json["is_list_attribute"]: + get = """ +bool get_OBJECT_CLASS_LABEL(const BaseClass* BaseClass_ptr1, std::list& BaseClass_list) +{ + if (const OBJECT_CLASS* element = dynamic_cast(BaseClass_ptr1)) + { + std::copy(element->LABEL.begin(), element->LABEL.end(), std::back_inserter(BaseClass_list)); + return !BaseClass_list.empty(); + } + return false; +}""".replace( # noqa: E101,W191 + "OBJECT_CLASS", attribute_json["domain"] + ).replace( + "LABEL", attribute_json["label"] + ) + else: + get = """ +bool get_OBJECT_CLASS_LABEL(const BaseClass* BaseClass_ptr1, std::list& BaseClass_list) +{ + if (const OBJECT_CLASS* element = dynamic_cast(BaseClass_ptr1)) + { + if (element->LABEL != 0) + { + BaseClass_list.push_back(element->LABEL); + return true; + } + } + return false; +}""".replace( # noqa: E101,W191 + "OBJECT_CLASS", attribute_json["domain"] + ).replace( + "LABEL", attribute_json["label"] + ) + + return get + + +def create_get(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + get = "" + if not _attribute_is_primitive_or_datatype(attribute_json): + return "" + label_without_keyword = attribute_json["label"] + if label_without_keyword == "switch": + label_without_keyword = "_switch" + + get = ( + """ +bool get_CLASS_LABEL(const BaseClass* BaseClass_ptr1, std::stringstream& buffer) +{ + if (const CLASS* element = dynamic_cast(BaseClass_ptr1)) + { + buffer << element->LBL_WO_KEYWORD; + if (!buffer.str().empty()) + { + return true; + } + } + buffer.setstate(std::ios::failbit); + return false; +}""".replace( # noqa: E101,W191 + "CLASS", attribute_json["domain"] + ) + .replace("LABEL", attribute_json["label"]) + .replace("LBL_WO_KEYWORD", label_without_keyword) + ) + + return get + + +def create_enum_get(text, render): + attribute_txt = render(text) + attribute_json = eval(attribute_txt) + if not attribute_json["is_enum_attribute"]: + return "" + + get = """ +bool get_CLASS_LABEL(const BaseClass* BaseClass_ptr1, std::stringstream& buffer) +{ + if (const CLASS* element = dynamic_cast(BaseClass_ptr1)) + { + buffer << element->LABEL; + if (!buffer.str().empty()) + { + return true; + } + } + buffer.setstate(std::ios::failbit); + return false; +}""".replace( # noqa: E101,W191 + "CLASS", attribute_json["domain"] + ).replace( + "LABEL", attribute_json["label"] + ) + + return get + + def attribute_decl(text, render): attribute_txt = render(text) attribute_json = eval(attribute_txt) diff --git a/cimgen/languages/cpp/static/BaseClass.cpp b/cimgen/languages/cpp/static/BaseClass.cpp index 5baf1c2c..cc93fcd5 100644 --- a/cimgen/languages/cpp/static/BaseClass.cpp +++ b/cimgen/languages/cpp/static/BaseClass.cpp @@ -16,6 +16,9 @@ const char* BaseClass::debugString() const void BaseClass::addConstructToMap(std::unordered_map& factory_map) {} void BaseClass::addPrimitiveAssignFnsToMap(std::unordered_map& assign_map) {} void BaseClass::addClassAssignFnsToMap(std::unordered_map& assign_map) {} +void BaseClass::addPrimitiveGetFnsToMap(std::map& get_map) const {} +void BaseClass::addClassGetFnsToMap(std::map& get_map) const {} +void BaseClass::addEnumGetFnsToMap(std::map& get_map) const {} const BaseClassDefiner BaseClass::declare() { diff --git a/cimgen/languages/cpp/static/BaseClass.hpp b/cimgen/languages/cpp/static/BaseClass.hpp index a5b797f3..f761249c 100644 --- a/cimgen/languages/cpp/static/BaseClass.hpp +++ b/cimgen/languages/cpp/static/BaseClass.hpp @@ -13,6 +13,10 @@ #include "BaseClassDefiner.hpp" #include "CGMESProfile.hpp" +class BaseClass; +typedef bool (*class_get_function)(const BaseClass*, std::list&); +typedef bool (*get_function)(const BaseClass*, std::stringstream&); + class BaseClass { std::string rdfid; @@ -31,6 +35,9 @@ class BaseClass static void addConstructToMap(std::unordered_map& factory_map); static void addPrimitiveAssignFnsToMap(std::unordered_map& assign_map); static void addClassAssignFnsToMap(std::unordered_map& assign_map); + virtual void addPrimitiveGetFnsToMap(std::map& get_map) const; + virtual void addClassGetFnsToMap(std::map& get_map) const; + virtual void addEnumGetFnsToMap(std::map& get_map) const; static const CIMPP::BaseClassDefiner declare(); }; #endif // BASECLASS_HPP diff --git a/cimgen/languages/cpp/templates/cpp_header_template.mustache b/cimgen/languages/cpp/templates/cpp_header_template.mustache index 58a15482..b163f9dc 100644 --- a/cimgen/languages/cpp/templates/cpp_header_template.mustache +++ b/cimgen/languages/cpp/templates/cpp_header_template.mustache @@ -41,6 +41,9 @@ namespace CIMPP static void addConstructToMap(std::unordered_map& factory_map); static void addPrimitiveAssignFnsToMap(std::unordered_map& assign_map); static void addClassAssignFnsToMap(std::unordered_map& assign_map); + void addPrimitiveGetFnsToMap(std::map& get_map) const override; + void addClassGetFnsToMap(std::map& get_map) const override; + void addEnumGetFnsToMap(std::map& get_map) const override; static const BaseClassDefiner declare(); }; diff --git a/cimgen/languages/cpp/templates/cpp_object_template.mustache b/cimgen/languages/cpp/templates/cpp_object_template.mustache index 845dd25e..d09c2ce4 100644 --- a/cimgen/languages/cpp/templates/cpp_object_template.mustache +++ b/cimgen/languages/cpp/templates/cpp_object_template.mustache @@ -4,6 +4,8 @@ Generated from the CGMES files via cimgen: https://github.com/sogno-platform/cim #include "{{class_name}}.hpp" #include +#include +#include #include {{#attributes}} @@ -52,6 +54,18 @@ std::map> {{#langPack.create_class_assign}}{{.}}{{/langPack.create_class_assign}} {{/attributes}} +{{#attributes}} +{{#langPack.create_get}}{{.}}{{/langPack.create_get}} +{{/attributes}} + +{{#attributes}} +{{#langPack.create_class_get}}{{.}}{{/langPack.create_class_get}} +{{/attributes}} + +{{#attributes}} +{{#langPack.create_enum_get}}{{.}}{{/langPack.create_enum_get}} +{{/attributes}} + const char {{class_name}}::debugName[] = "{{class_name}}"; const char* {{class_name}}::debugString() const { @@ -77,6 +91,30 @@ void {{class_name}}::addClassAssignFnsToMap(std::unordered_map& get_map) const +{ + {{sub_class_of}}::addPrimitiveGetFnsToMap(get_map); +{{#attributes}} +{{> insert_get}} +{{/attributes}} +} + +void {{class_name}}::addClassGetFnsToMap(std::map& get_map) const +{ + {{sub_class_of}}::addClassGetFnsToMap(get_map); +{{#attributes}} +{{> insert_class_get}} +{{/attributes}} +} + +void {{class_name}}::addEnumGetFnsToMap(std::map& get_map) const +{ + {{sub_class_of}}::addEnumGetFnsToMap(get_map); +{{#attributes}} +{{> insert_enum_get}} +{{/attributes}} +} + const BaseClassDefiner {{class_name}}::declare() { return BaseClassDefiner({{class_name}}::addConstructToMap, {{class_name}}::addPrimitiveAssignFnsToMap, {{class_name}}::addClassAssignFnsToMap, {{class_name}}::debugName);