Skip to content

Commit

Permalink
adding ability to specify proto writing side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Dec 31, 2023
1 parent 681672f commit cad15fb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions xml_converter/doc/menu/display_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ custom_functions:
read.proto:
function: proto_display_name_to_display_name_and_name
side_effects: [Name]
write.proto:
function: display_name_and_name_to_proto_display_name
side_effects: [Name]

---
A human readable name of this category.
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/generators/cpp_templates/class_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ waypoint::{{cpp_class}} {{cpp_class}}::as_protobuf(ProtoWriterState* state) cons
{% else %}
std::function<void({{attribute_variable.protobuf_cpp_type}})> setter = [&proto_{{cpp_class_header}}]({{attribute_variable.protobuf_cpp_type}} val) { proto_{{cpp_class_header}}.{{attribute_variable.mutable_proto_drilldown_calls}}set_{{attribute_variable.protobuf_field}}(val); };
{% endif %}
{{attribute_variable.serialize_proto_function}}(this->{{attribute_variable.attribute_name}}, state, setter);
{{attribute_variable.serialize_proto_function}}(this->{{attribute_variable.attribute_name}}, state, setter{% for side_effect in attribute_variable.serialize_proto_side_effects %}, &(this->{{side_effect}}){% endfor %});
}
{% endif %}
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AttributeVariable:

# The function name and additional side effect pointers for proto serialization.
serialize_proto_function: str
# serialize_proto_side_effects: List[str]
serialize_proto_side_effects: List[str]

# The function name and additional side effect pointers for proto deserialization.
deserialize_proto_function: str
Expand Down Expand Up @@ -321,7 +321,7 @@ def generate_cpp_variable_data(
deserialize_xml_function="xml_attribute_to_" + component_class_name,
deserialize_xml_side_effects=[],
serialize_proto_function="to_proto_" + component_class_name,
# serialize_proto_side_effects=[],
serialize_proto_side_effects=[],
deserialize_proto_function="from_proto_" + component_class_name,
deserialize_proto_side_effects=[],
)
Expand Down Expand Up @@ -398,7 +398,7 @@ def generate_cpp_variable_data(
deserialize_xml_function=deserialize_xml_function,
deserialize_xml_side_effects=deserialize_xml_side_effects,
serialize_proto_function=serialize_proto_function,
# serialize_proto_side_effects=serialize_proto_side_effects,
serialize_proto_side_effects=serialize_proto_side_effects,
deserialize_proto_function=deserialize_proto_function,
deserialize_proto_side_effects=deserialize_proto_side_effects,

Expand Down
10 changes: 10 additions & 0 deletions xml_converter/src/attribute/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ void proto_display_name_to_display_name_and_name(
*name = normalize(input);
*is_name_set = true;
}


void display_name_and_name_to_proto_display_name(
std::string value,
ProtoWriterState* state,
std::function<void(std::string)> setter,
const std::string* name,
const bool* is_name_set) {
setter(value);
}
8 changes: 8 additions & 0 deletions xml_converter/src/attribute/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ void proto_display_name_to_display_name_and_name(
bool* is_display_name_set,
std::string* name,
bool* is_name_set);

void display_name_and_name_to_proto_display_name(
std::string input,
ProtoWriterState* state,
std::function<void(std::string)> setter,
const std::string* name,
const bool* is_name_set);

#define do_nothing(...)
2 changes: 1 addition & 1 deletion xml_converter/src/category_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ waypoint::Category Category::as_protobuf(ProtoWriterState* state) const {
}
if (this->display_name_is_set) {
std::function<void(std::string)> setter = [&proto_category](std::string val) { proto_category.set_name(val); };
string_to_proto(this->display_name, state, setter);
display_name_and_name_to_proto_display_name(this->display_name, state, setter, &(this->name), &(this->name_is_set));
}
if (this->is_separator_is_set) {
std::function<void(bool)> setter = [&proto_category](bool val) { proto_category.set_is_separator(val); };
Expand Down

0 comments on commit cad15fb

Please sign in to comment.