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

Migrating xml attribute writing code to have pointers passed in #188

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
};
{% endif %}
{{class_name}} parse_{{attribute_name}}(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);
std::string stringify_{{attribute_name}}({{class_name}} attribute_value);
std::string {{attribute_name}}_to_xml_attribute(const std::string& attribute_name, const {{class_name}}* value);
{% if type == "Enum":%}
waypoint::{{class_name}} to_proto_{{attribute_name}}({{class_name}} attribute_value);
{% else: %}
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 @@ -70,7 +70,7 @@ vector<string> {{cpp_class}}::as_xml() 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.default_xml_field}}=\"" + stringify_{{attribute_variable.class_name}}(this->{{attribute_variable.attribute_name}}) + "\"");
xml_node_contents.push_back({{attribute_variable.class_name}}_to_xml_attribute("{{attribute_variable.default_xml_field}}", &this->{{attribute_variable.attribute_name}}));
}
{% endif %}
{% endfor %}
Expand Down
9 changes: 4 additions & 5 deletions xml_converter/generators/cpp_templates/compoundvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ using namespace std;
return {{attribute_name}};
}
{% if xml_bundled_components != [] %}

string stringify_{{attribute_name}}({{class_name}} attribute_value) {
string {{attribute_name}}_to_xml_attribute(const std::string& attribute_name, const {{class_name}}* value) {
string output;
{% for n, attribute_variable in enumerate(attribute_variables) %}
{% if attribute_variable.attribute_name in xml_bundled_components %}
{% if n == 0: %}
output = to_string(attribute_value.{{attribute_variable.attribute_name}});
output = to_string(value->{{attribute_variable.attribute_name}});
{% else %}
output = output + "," + to_string(attribute_value.{{attribute_variable.attribute_name}});
output = output + "," + to_string(value->{{attribute_variable.attribute_name}});
{% endif %}
{% endif %}
{% endfor %}
return output;
return " " + attribute_name + "=\"" + output + "\"";
}
{% endif %}

Expand Down
16 changes: 7 additions & 9 deletions xml_converter/generators/cpp_templates/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ using namespace std;
return {{attribute_name}};
}

string stringify_{{attribute_name}}({{class_name}} attribute_value) {
string {{attribute_name}}_to_xml_attribute(const std::string& attribute_name, const {{class_name}}* value) {
{% for n, attribute_variable in enumerate(attribute_variables) %}
{% for i, value in enumerate(attribute_variable.xml_fields) %}
{%-if i == 0 and n == 0:%}
if (attribute_value == {{class_name}}::{{attribute_variable.attribute_name}}) {
return "{{value}}";
}
{% else: %}
else if (attribute_value == {{class_name}}::{{attribute_variable.attribute_name}}) {
return "{{value}}";
}
if (*value == {{class_name}}::{{attribute_variable.attribute_name}}) {
{% else %}
else if (*value == {{class_name}}::{{attribute_variable.attribute_name}}) {
{% endif %}
return " " + attribute_name + "=\"" + "{{value}}" + "\"";
}
{% endfor %}
{% endfor %}
else {
return "{{class_name}}::{{attribute_variables[0].xml_fields[0]}}";
return " " + attribute_name + "=\"" + "{{class_name}}::{{attribute_variables[0].xml_fields[0]}}" + "\"";
}
}

Expand Down
6 changes: 3 additions & 3 deletions xml_converter/generators/cpp_templates/multiflagvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ using namespace std;
return {{attribute_name}};
}

string stringify_{{attribute_name}}({{class_name}} attribute_value) {
string {{attribute_name}}_to_xml_attribute(const std::string& attribute_name, const {{class_name}}* value) {
string output = "";
{% for n, attribute_variable in enumerate(attribute_variables)%}
if (attribute_value.{{attribute_variable.attribute_name}} == true) {
if (value->{{attribute_variable.attribute_name}} == true) {
output = output + "{{attribute_variable.xml_fields[0]}}";
}
{% endfor %}
return output;
return " " + attribute_name + "=\"" + output + "\"";
}

waypoint::{{class_name}}* to_proto_{{attribute_name}}({{class_name}} attribute_value) {
Expand Down
12 changes: 6 additions & 6 deletions xml_converter/src/attribute/bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ bool parse_bool(rapidxml::xml_attribute<>* input, vector<XMLError*>* errors) {
}

////////////////////////////////////////////////////////////////////////////////
// stringify_bool
// bool_to_xml_attribute
//
// Converts a bool into a stringy value so that it can be saved to xml.
// Converts a bool into a fully qualified xml attribute string.
////////////////////////////////////////////////////////////////////////////////
string stringify_bool(bool attribute_value) {
if (attribute_value) {
return "true";
string bool_to_xml_attribute(const string& attribute_name, const bool* value) {
if (value) {
return " " + attribute_name + "=\"true\"";
}
else {
return "false";
return " " + attribute_name + "=\"false\"";
}
}
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class XMLError;

bool parse_bool(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);

std::string stringify_bool(bool attribute_value);
std::string bool_to_xml_attribute(const std::string& attribute_name, const bool* value);

// Zero Cost Abstraction identity functions to make parsing and writing protobufs more uniform
inline bool const& from_proto_bool(const bool& x) {
Expand Down
15 changes: 8 additions & 7 deletions xml_converter/src/attribute/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,26 @@ Color parse_color(rapidxml::xml_attribute<>* input, vector<XMLError*>* errors) {
}

////////////////////////////////////////////////////////////////////////////////
// stringify_color
// color_to_xml_attribute
//
// Converts a Color into a stringy value so it can be saved to xml.
// Converts a color into a fully qualified xml attribute string.
////////////////////////////////////////////////////////////////////////////////
string stringify_color(Color attribute_value) {
string color_to_xml_attribute(const string& attribute_name, const Color* value) {
std::stringstream stream;
std::string hex_string = "#";

stream << std::hex << convert_color_channel_float_to_int(attribute_value.red);
stream << std::hex << convert_color_channel_float_to_int((*value).red);
hex_string += stream.str();

stream << std::hex << convert_color_channel_float_to_int(attribute_value.green);
stream << std::hex << convert_color_channel_float_to_int((*value).green);
hex_string += stream.str();

stream << std::hex << convert_color_channel_float_to_int(attribute_value.blue);
stream << std::hex << convert_color_channel_float_to_int((*value).blue);
hex_string += stream.str();

std::string rgb = hex_string;
return rgb;

return " " + attribute_name + "=\"" + rgb + "\"";
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Color {

Color parse_color(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);

std::string stringify_color(Color attribute_value);
std::string color_to_xml_attribute(const std::string& attribute_name, const Color* value);

waypoint::RGBAColor* to_proto_color(Color attribute_value);

Expand Down
16 changes: 8 additions & 8 deletions xml_converter/src/attribute/cull_chirality_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ CullChirality parse_cull_chirality(rapidxml::xml_attribute<>* input, vector<XMLE
return cull_chirality;
}

string stringify_cull_chirality(CullChirality attribute_value) {
if (attribute_value == CullChirality::none) {
return "none";
string cull_chirality_to_xml_attribute(const std::string& attribute_name, const CullChirality* value) {
if (*value == CullChirality::none) {
return " " + attribute_name + "=\"" + "none" + "\"";
}
else if (attribute_value == CullChirality::clockwise) {
return "clockwise";
else if (*value == CullChirality::clockwise) {
return " " + attribute_name + "=\"" + "clockwise" + "\"";
}
else if (attribute_value == CullChirality::counter_clockwise) {
return "counterclockwise";
else if (*value == CullChirality::counter_clockwise) {
return " " + attribute_name + "=\"" + "counterclockwise" + "\"";
}
else {
return "CullChirality::none";
return " " + attribute_name + "=\"" + "CullChirality::none" + "\"";
}
}

Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/cull_chirality_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ enum CullChirality {
none,
};
CullChirality parse_cull_chirality(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);
std::string stringify_cull_chirality(CullChirality attribute_value);
std::string cull_chirality_to_xml_attribute(const std::string& attribute_name, const CullChirality* value);
waypoint::CullChirality to_proto_cull_chirality(CullChirality attribute_value);
CullChirality from_proto_cull_chirality(waypoint::CullChirality proto_cull_chirality);
11 changes: 5 additions & 6 deletions xml_converter/src/attribute/euler_rotation_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ EulerRotation parse_euler_rotation(rapidxml::xml_attribute<>* input, vector<XMLE
}
return euler_rotation;
}

string stringify_euler_rotation(EulerRotation attribute_value) {
string euler_rotation_to_xml_attribute(const std::string& attribute_name, const EulerRotation* value) {
string output;
output = to_string(attribute_value.x_rotation);
output = output + "," + to_string(attribute_value.y_rotation);
output = output + "," + to_string(attribute_value.z_rotation);
return output;
output = to_string(value->x_rotation);
output = output + "," + to_string(value->y_rotation);
output = output + "," + to_string(value->z_rotation);
return " " + attribute_name + "=\"" + output + "\"";
}

waypoint::EulerRotation* to_proto_euler_rotation(EulerRotation attribute_value) {
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/euler_rotation_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class EulerRotation {
}
};
EulerRotation parse_euler_rotation(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);
std::string stringify_euler_rotation(EulerRotation attribute_value);
std::string euler_rotation_to_xml_attribute(const std::string& attribute_name, const EulerRotation* value);
waypoint::EulerRotation* to_proto_euler_rotation(EulerRotation attribute_value);
EulerRotation from_proto_euler_rotation(waypoint::EulerRotation proto_euler_rotation);
18 changes: 9 additions & 9 deletions xml_converter/src/attribute/festival_filter_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ FestivalFilter parse_festival_filter(rapidxml::xml_attribute<>* input, vector<XM
return festival_filter;
}

string stringify_festival_filter(FestivalFilter attribute_value) {
string festival_filter_to_xml_attribute(const std::string& attribute_name, const FestivalFilter* value) {
string output = "";
if (attribute_value.dragonbash == true) {
if (value->dragonbash == true) {
output = output + "dragonbash";
}
if (attribute_value.festival_of_the_four_winds == true) {
if (value->festival_of_the_four_winds == true) {
output = output + "festivalofthefourwinds";
}
if (attribute_value.halloween == true) {
if (value->halloween == true) {
output = output + "halloween";
}
if (attribute_value.lunar_new_year == true) {
if (value->lunar_new_year == true) {
output = output + "lunarnewyear";
}
if (attribute_value.super_adventure_festival == true) {
if (value->super_adventure_festival == true) {
output = output + "superadventurefestival";
}
if (attribute_value.wintersday == true) {
if (value->wintersday == true) {
output = output + "wintersday";
}
if (attribute_value.none == true) {
if (value->none == true) {
output = output + "none";
}
return output;
return " " + attribute_name + "=\"" + output + "\"";
}

waypoint::FestivalFilter* to_proto_festival_filter(FestivalFilter attribute_value) {
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/festival_filter_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class FestivalFilter {
}
};
FestivalFilter parse_festival_filter(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);
std::string stringify_festival_filter(FestivalFilter attribute_value);
std::string festival_filter_to_xml_attribute(const std::string& attribute_name, const FestivalFilter* value);
waypoint::FestivalFilter* to_proto_festival_filter(FestivalFilter attribute_value);
FestivalFilter from_proto_festival_filter(waypoint::FestivalFilter proto_festival_filter);
9 changes: 5 additions & 4 deletions xml_converter/src/attribute/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../rapid_helpers.hpp"
#include "../rapidxml-1.13/rapidxml.hpp"

using namespace std;
////////////////////////////////////////////////////////////////////////////////
// parse_float
//
Expand All @@ -16,10 +17,10 @@ float parse_float(rapidxml::xml_attribute<>* input, std::vector<XMLError*>*) {
}

////////////////////////////////////////////////////////////////////////////////
// stringify_float
// float_to_xml_attribute
//
// Converts a float into a stringy value so that it can be saved to xml.
// Converts a float into a fully qualified xml attribute string.
////////////////////////////////////////////////////////////////////////////////
std::string stringify_float(float attribute_value) {
return std::to_string(attribute_value);
string float_to_xml_attribute(const string& attribute_name, const float* value) {
return " " + attribute_name + "=\"" + to_string(*value) + "\"";
}
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class XMLError;

float parse_float(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);

std::string stringify_float(float attribute_value);
std::string float_to_xml_attribute(const std::string& attribute_name, const float* value);

// Zero Cost Abstraction identity functions to make parsing and writing protobufs more uniform
inline float const& from_proto_float(const float& x) {
Expand Down
8 changes: 4 additions & 4 deletions xml_converter/src/attribute/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Image parse_image(rapidxml::xml_attribute<>* input, vector<XMLError*>*) {
}

////////////////////////////////////////////////////////////////////////////////
// stringify_image
// image_to_xml_attribute
//
// Converts an Image into a stringy value representing the path to the image.
// Converts an image into a fully qualified xml attribute string.
////////////////////////////////////////////////////////////////////////////////
string stringify_image(Image attribute_value) {
return attribute_value.path;
string image_to_xml_attribute(const string& attribute_name, const Image* value) {
return " " + attribute_name + "=\"" + value->path + "\"";
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Image {

Image parse_image(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);

std::string stringify_image(Image attribute_value);
std::string image_to_xml_attribute(const std::string& attribute_name, const Image* value);

waypoint::TexturePath* to_proto_image(Image attribute_value);

Expand Down
8 changes: 4 additions & 4 deletions xml_converter/src/attribute/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ int parse_int(rapidxml::xml_attribute<>* input, vector<XMLError*>* errors) {
}

////////////////////////////////////////////////////////////////////////////////
// stringify_int
// int_to_xml_attribute
//
// Converts an int into a stringy value so that it can be saved to xml.
// Converts an int a fully qualified xml attribute string.
////////////////////////////////////////////////////////////////////////////////
string stringify_int(int attribute_value) {
return to_string(attribute_value);
string int_to_xml_attribute(const string& attribute_name, const int* value) {
return " " + attribute_name + "=\"" + to_string(*value) + "\"";
}
2 changes: 1 addition & 1 deletion xml_converter/src/attribute/int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class XMLError;

int parse_int(rapidxml::xml_attribute<>* input, std::vector<XMLError*>* errors);

std::string stringify_int(int attribute_value);
std::string int_to_xml_attribute(const std::string& attribute_name, const int* value);

// Zero Cost Abstraction identity functions to make parsing and writing protobufs more uniform
inline int const& from_proto_int(const int& x) {
Expand Down
Loading