Skip to content

Commit

Permalink
adding a global state var for the xml parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Nov 11, 2023
1 parent e346ab5 commit fcb7b86
Show file tree
Hide file tree
Showing 56 changed files with 265 additions and 157 deletions.
3 changes: 3 additions & 0 deletions xml_converter/generators/cpp_templates/attribute_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

{% if type == "Enum" %}
#include "waypoint.pb.h"

Expand Down Expand Up @@ -33,6 +35,7 @@
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
{{class_name}}* value,
bool* is_set);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using namespace std;
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_{{attribute_name}}(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
{{class_name}}* value,
bool* is_set) {
{{class_name}} {{attribute_name}};
Expand Down
12 changes: 6 additions & 6 deletions xml_converter/generators/cpp_templates/class_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ string {{cpp_class}}::classname() {
return "{{xml_class_name}}";
}
{% if cpp_class == "Category": %}
void {{cpp_class}}::init_from_xml(rapidxml::xml_node<>* node, vector<XMLError*>* errors, string base_dir) {
void {{cpp_class}}::init_from_xml(rapidxml::xml_node<>* node, vector<XMLError*>* errors, XMLParseState* state) {
for (rapidxml::xml_attribute<>* attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) {
bool is_icon_value = this->default_icon.init_xml_attribute(attribute, errors);
bool is_trail_value = this->default_trail.init_xml_attribute(attribute, errors);
bool is_icon_value = this->default_icon.init_xml_attribute(attribute, errors, state);
bool is_trail_value = this->default_trail.init_xml_attribute(attribute, errors, state);

if (init_xml_attribute(attribute, errors, base_dir)) {
if (init_xml_attribute(attribute, errors, state)) {
}
else if (is_icon_value || is_trail_value) {
}
Expand All @@ -34,13 +34,13 @@ string {{cpp_class}}::classname() {
}
{% endif %}

bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vector<XMLError*>* errors, string base_dir) {
bool {{cpp_class}}::init_xml_attribute(rapidxml::xml_attribute<>* attribute, vector<XMLError*>* errors, XMLParseState* state) {
string attributename;
attributename = normalize(get_attribute_name(attribute));
{% for n, attribute_variable in enumerate(attribute_variables) %}
{% for i, value in enumerate(attribute_variable.xml_fields) %}
{{ "if" if i == n == 0 else "else if" }} (attributename == "{{value}}") {
{{attribute_variable.deserialize_xml_function}}(attribute, errors, {% if attribute_variable.uses_file_path %}base_dir, {% endif %}&(this->{{attribute_variable.attribute_name}}), &(this->{{attribute_variable.attribute_flag_name}}){% for side_effect in attribute_variable.deserialize_xml_side_effects %}, &(this->{{side_effect}}){% endfor %});
{{attribute_variable.deserialize_xml_function}}(attribute, errors, state, &(this->{{attribute_variable.attribute_name}}), &(this->{{attribute_variable.attribute_flag_name}}){% for side_effect in attribute_variable.deserialize_xml_side_effects %}, &(this->{{side_effect}}){% endfor %});
}
{% endfor %}
{% endfor %}
Expand Down
14 changes: 7 additions & 7 deletions xml_converter/generators/cpp_templates/class_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@

class {{cpp_class}} : public Parseable {
public:
{% for attribute_variable in attribute_variables: %}
{% if attribute_variable.is_component == false: %}
{% for attribute_variable in attribute_variables %}
{% if attribute_variable.is_component == false %}
{{attribute_variable.cpp_type}} {{attribute_variable.attribute_name}};
{% endif %}
{% endfor %}
{% for attribute_variable in attribute_variables: %}
{% if attribute_variable.is_component == false: %}
{% for attribute_variable in attribute_variables %}
{% if attribute_variable.is_component == false %}
bool {{attribute_variable.attribute_flag_name}} = false;
{% endif %}
{% endfor %}
{% if cpp_class == "Category": %}
{% if cpp_class == "Category" %}
std::map<std::string, Category> children;
Icon default_icon;
Trail default_trail;

void init_from_xml(rapidxml::xml_node<>* node, std::vector<XMLError*>* errors, std::string base_dir = "");
void init_from_xml(rapidxml::xml_node<>* node, std::vector<XMLError*>* errors, XMLParseState* state);
{% endif %}
virtual std::vector<std::string> as_xml() const;
virtual std::string classname();
bool init_xml_attribute(rapidxml::xml_attribute<>* attribute, std::vector<XMLError*>* errors, std::string base_dir = "");
bool init_xml_attribute(rapidxml::xml_attribute<>* attribute, std::vector<XMLError*>* errors, XMLParseState* state);
waypoint::{{cpp_class}} as_protobuf() const;
void parse_protobuf(waypoint::{{cpp_class}} proto_{{cpp_class_header}});
{% if attributes_of_type_marker_category %}
Expand Down
3 changes: 2 additions & 1 deletion xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,15 @@ def generate_cpp_variable_data(

cpp_includes.hpp_absolute_includes.add("string")
cpp_includes.hpp_absolute_includes.add("vector")
cpp_includes.hpp_absolute_includes.add("functional")
cpp_includes.hpp_relative_includes.add("rapidxml-1.13/rapidxml.hpp")
cpp_includes.hpp_relative_includes.add("parseable.hpp")
cpp_includes.hpp_relative_includes.add("waypoint.pb.h")
cpp_includes.hpp_relative_includes.add("state_structs/xml_parse_state.hpp")
cpp_includes.hpp_forward_declarations.add("XMLError")

cpp_includes.cpp_absolute_includes.add("iosfwd")
cpp_includes.cpp_absolute_includes.add("string")
cpp_includes.hpp_absolute_includes.add("functional")
cpp_includes.cpp_relative_includes.add("rapidxml-1.13/rapidxml.hpp")
cpp_includes.cpp_relative_includes.add("string_helper.hpp")
cpp_includes.cpp_relative_includes.add("rapid_helpers.hpp")
Expand Down
2 changes: 2 additions & 0 deletions xml_converter/src/attribute/bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using namespace std;
void xml_attribute_to_bool(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
bool* value,
bool* is_set) {
if (get_attribute_value(input) == "0" || get_attribute_value(input) == "false") {
Expand Down Expand Up @@ -58,6 +59,7 @@ string bool_to_xml_attribute(const string& attribute_name, const bool* value) {
void inverted_xml_attribute_to_bool(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
bool* value,
bool* is_set) {
if (get_attribute_value(input) == "0" || get_attribute_value(input) == "false") {
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

void xml_attribute_to_bool(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
bool* value,
bool* is_set);

Expand All @@ -21,6 +23,7 @@ std::string bool_to_xml_attribute(
void inverted_xml_attribute_to_bool(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
bool* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int convert_color_channel_float_to_int(float input) {
void xml_attribute_to_color(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
Color* value,
bool* is_set) {
Color color;
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

namespace waypoint {
class RGBAColor;
}
Expand All @@ -22,6 +24,7 @@ class Color {
void xml_attribute_to_color(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
Color* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/cull_chirality_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_cull_chirality(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
CullChirality* value,
bool* is_set) {
CullChirality cull_chirality;
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/cull_chirality_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

#include "waypoint.pb.h"

class XMLError;
Expand All @@ -17,6 +19,7 @@ enum CullChirality {
void xml_attribute_to_cull_chirality(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
CullChirality* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/euler_rotation_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using namespace std;
void xml_attribute_to_euler_rotation(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
EulerRotation* value,
bool* is_set) {
EulerRotation euler_rotation;
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/euler_rotation_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;
namespace waypoint {
class EulerRotation;
Expand All @@ -23,6 +25,7 @@ class EulerRotation {
void xml_attribute_to_euler_rotation(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
EulerRotation* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/festival_filter_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_festival_filter(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
FestivalFilter* value,
bool* is_set) {
FestivalFilter festival_filter;
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/festival_filter_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;
namespace waypoint {
class FestivalFilter;
Expand All @@ -27,6 +29,7 @@ class FestivalFilter {
void xml_attribute_to_festival_filter(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
FestivalFilter* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_float(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
float* value,
bool* is_set) {
*value = std::stof(get_attribute_value(input));
Expand Down
2 changes: 2 additions & 0 deletions xml_converter/src/attribute/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

void xml_attribute_to_float(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
float* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using namespace std;
void xml_attribute_to_image(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
Image* value,
bool* is_set) {
value->path = get_attribute_value(input);
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

namespace waypoint {
class TexturePath;
}
Expand All @@ -19,6 +21,7 @@ class Image {
void xml_attribute_to_image(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
Image* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using namespace std;
void xml_attribute_to_int(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
int* value,
bool* is_set) {
try {
Expand Down
2 changes: 2 additions & 0 deletions xml_converter/src/attribute/int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

void xml_attribute_to_int(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
int* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/map_type_filter_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_map_type_filter(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
MapTypeFilter* value,
bool* is_set) {
MapTypeFilter map_type_filter;
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/map_type_filter_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;
namespace waypoint {
class MapTypeFilter;
Expand Down Expand Up @@ -44,6 +46,7 @@ class MapTypeFilter {
void xml_attribute_to_map_type_filter(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
MapTypeFilter* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/marker_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
void xml_attribute_to_marker_category(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
MarkerCategory* value,
bool* is_set) {
value->category = get_attribute_value(input);
Expand Down
3 changes: 3 additions & 0 deletions xml_converter/src/attribute/marker_category.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <vector>

#include "../rapidxml-1.13/rapidxml.hpp"
#include "../state_structs/xml_parse_state.hpp"

class XMLError;

namespace waypoint {
class Category;
}
Expand All @@ -19,6 +21,7 @@ class MarkerCategory {
void xml_attribute_to_marker_category(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
MarkerCategory* value,
bool* is_set);

Expand Down
1 change: 1 addition & 0 deletions xml_converter/src/attribute/mount_filter_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace std;
void xml_attribute_to_mount_filter(
rapidxml::xml_attribute<>* input,
std::vector<XMLError*>* errors,
XMLParseState* state,
MountFilter* value,
bool* is_set) {
MountFilter mount_filter;
Expand Down
Loading

0 comments on commit fcb7b86

Please sign in to comment.