Skip to content

Commit

Permalink
Add generation of getter functions for cpp, add CIM writer to export …
Browse files Browse the repository at this point in the history
…CIM data into several files based on CGMES profiles

Signed-off-by: Thomas Günther <[email protected]>
  • Loading branch information
tom-hg57 committed Oct 27, 2024
1 parent 6c64854 commit 9bb08cd
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 0 deletions.
171 changes: 171 additions & 0 deletions cimgen/languages/cpp/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
}


Expand Down Expand Up @@ -161,6 +164,68 @@ 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_json["is_primitive_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 insert_class_get_fn(text, render):
attribute_txt = render(text)
attribute_json = eval(attribute_txt)
if attribute_json["is_primitive_attribute"] or attribute_json["is_enum_attribute"]:
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() == "":
Expand Down Expand Up @@ -343,6 +408,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_json["is_primitive_attribute"] or attribute_json["is_enum_attribute"]:
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<const BaseClass*>& BaseClass_list)
{
if (const OBJECT_CLASS* element = dynamic_cast<const OBJECT_CLASS*>(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<const BaseClass*>& BaseClass_list)
{
if (const OBJECT_CLASS* element = dynamic_cast<const OBJECT_CLASS*>(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_json["is_primitive_attribute"]:
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<const CLASS*>(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<const CLASS*>(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)
Expand Down
Loading

0 comments on commit 9bb08cd

Please sign in to comment.