Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation of string classes #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions cimgen/languages/cpp/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<CLASS*>(BaseClass_ptr1))
Expand All @@ -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<CLASS*>(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

Expand Down Expand Up @@ -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
Expand Down
Loading