Skip to content

Commit

Permalink
Merge pull request #255 from AsherGlick/xml_write_side_effects
Browse files Browse the repository at this point in the history
Adding functionality to make use of xml write side effects
  • Loading branch information
AsherGlick authored Jan 1, 2024
2 parents 478aa62 + 309d1b5 commit 3cf2a6a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions xml_converter/doc/trail_data/trail_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ custom_functions:
read.xml:
function: xml_attribute_to_trail_data
side_effects: [Map ID]
write.xml:
function: trail_data_to_xml_attribute
side_effects: [Map ID]
---

The coordinates of each point along a trail path.
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 @@ -65,7 +65,7 @@ vector<string> {{cpp_class}}::as_xml(XMLWriterState* state) const {
{% for attribute_variable in attribute_variables %}
{% if attribute_variable.write_to_xml == true %}
if (this->{{attribute_variable.attribute_flag_name}}) {
xml_node_contents.push_back({{attribute_variable.serialize_xml_function}}("{{attribute_variable.default_xml_field}}", state, &this->{{attribute_variable.attribute_name}}));
xml_node_contents.push_back({{attribute_variable.serialize_xml_function}}("{{attribute_variable.default_xml_field}}", state, &this->{{attribute_variable.attribute_name}}{% for side_effect in attribute_variable.serialize_xml_side_effects %}, &(this->{{side_effect}}){% endfor %}));
}
{% endif %}
{% endfor %}
Expand Down
12 changes: 6 additions & 6 deletions xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AttributeVariable:

# The function name and additional side effect pointers for xml serialization.
serialize_xml_function: str
# serialize_xml_side_effects: List[str]
serialize_xml_side_effects: List[str]

# The function name and additional side effect pointers for xml deserialization.
deserialize_xml_function: str
Expand Down Expand Up @@ -309,7 +309,7 @@ def generate_cpp_variable_data(
is_component=True,

serialize_xml_function=component_class_name + "_to_xml_attribute",
# serialize_xml_side_effects=[],
serialize_xml_side_effects=[],
deserialize_xml_function="xml_attribute_to_" + component_class_name,
deserialize_xml_side_effects=[],
serialize_proto_function="to_proto_" + component_class_name,
Expand Down Expand Up @@ -386,7 +386,7 @@ def generate_cpp_variable_data(
side_effects=side_effects,

serialize_xml_function=serialize_xml_function,
# serialize_xml_side_effects=serialize_xml_side_effects,
serialize_xml_side_effects=serialize_xml_side_effects,
deserialize_xml_function=deserialize_xml_function,
deserialize_xml_side_effects=deserialize_xml_side_effects,
serialize_proto_function=serialize_proto_function,
Expand Down Expand Up @@ -480,7 +480,7 @@ def write_attribute(output_directory: str, data: Dict[str, Document]) -> List[st
deserialize_xml_function="",
serialize_proto_function="",
deserialize_proto_function="",
# serialize_xml_side_effects=[],
serialize_xml_side_effects=[],
deserialize_xml_side_effects=[],
# serialize_proto_side_effects=[],
deserialize_proto_side_effects=[],
Expand Down Expand Up @@ -515,7 +515,7 @@ def write_attribute(output_directory: str, data: Dict[str, Document]) -> List[st
deserialize_xml_function="",
serialize_proto_function="",
deserialize_proto_function="",
# serialize_xml_side_effects=[],
serialize_xml_side_effects=[],
deserialize_xml_side_effects=[],
# serialize_proto_side_effects=[],
deserialize_proto_side_effects=[],
Expand Down Expand Up @@ -543,7 +543,7 @@ def write_attribute(output_directory: str, data: Dict[str, Document]) -> List[st
deserialize_xml_function="",
serialize_proto_function="",
deserialize_proto_function="",
# serialize_xml_side_effects=[],
serialize_xml_side_effects=[],
deserialize_xml_side_effects=[],
# serialize_proto_side_effects=[],
deserialize_proto_side_effects=[],
Expand Down
4 changes: 3 additions & 1 deletion xml_converter/src/attribute/trail_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ void xml_attribute_to_trail_data(
string trail_data_to_xml_attribute(
const string& attribute_name,
XMLWriterState* state,
const TrailData* value) {
const TrailData* value,
const int* map_id_value,
const bool* is_map_id_set) {
return " " + attribute_name + "=\"" + "temp_name_of_trail.trl" + "\"";
}

Expand Down
4 changes: 3 additions & 1 deletion xml_converter/src/attribute/trail_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ void xml_attribute_to_trail_data(
std::string trail_data_to_xml_attribute(
const std::string& attribute_name,
XMLWriterState* state,
const TrailData* value);
const TrailData* value,
const int* map_id_value,
const bool* is_map_id_set);

void proto_to_trail_data(
waypoint::TrailData input,
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/trail_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ vector<string> Trail::as_xml(XMLWriterState* state) const {
xml_node_contents.push_back(image_to_xml_attribute("Texture", state, &this->texture));
}
if (this->trail_data_is_set) {
xml_node_contents.push_back(trail_data_to_xml_attribute("TrailData", state, &this->trail_data));
xml_node_contents.push_back(trail_data_to_xml_attribute("TrailData", state, &this->trail_data, &(this->map_id), &(this->map_id_is_set)));
}
if (this->trail_scale_is_set) {
xml_node_contents.push_back(float_to_xml_attribute("TrailScale", state, &this->trail_scale));
Expand Down

0 comments on commit 3cf2a6a

Please sign in to comment.