diff --git a/xml_converter/src/packaging_protobin.cpp b/xml_converter/src/packaging_protobin.cpp index 45033a01..a5129bdb 100644 --- a/xml_converter/src/packaging_protobin.cpp +++ b/xml_converter/src/packaging_protobin.cpp @@ -9,10 +9,8 @@ #include "category_gen.hpp" #include "parseable.hpp" #include "string_helper.hpp" -#include "waypoint.pb.h" #include "string_hierarchy.hpp" - -#include // For TextProtos +#include "waypoint.pb.h" using namespace std; @@ -84,38 +82,35 @@ struct MaybeCategory { }; MaybeCategory build_category_objects( const Category* category, - const StringHierarchy &category_filter, - const std::map> &category_to_pois, - vector &category_vector -) { + const StringHierarchy& category_filter, + const std::map>& category_to_pois, + vector* category_vector) { waypoint::Category category_proto = category->as_protobuf(); bool has_valid_contents = false; vector categories_to_write; for (map::const_iterator it = category->children.begin(); it != category->children.end(); it++) { - // This is currently a copy operation which is kind expensive - category_vector.push_back(it->first); + category_vector->push_back(it->first); - if (category_filter.in_hierarchy(category_vector)) { + if (category_filter.in_hierarchy(*category_vector)) { MaybeCategory child_category = build_category_objects( &it->second, category_filter, category_to_pois, - category_vector - ); + category_vector); if (child_category.is_category) { has_valid_contents = true; category_proto.add_children()->MergeFrom(child_category.category); } } - category_vector.pop_back(); + category_vector->pop_back(); } // This is a pretty expensive operation - string full_category_name = join(category_vector, "."); + string full_category_name = join(*category_vector, "."); auto iterator = category_to_pois.find(full_category_name); if (iterator != category_to_pois.end()) { for (size_t i = 0; i < iterator->second.size(); i++) { @@ -123,14 +118,14 @@ MaybeCategory build_category_objects( if (parsed_poi->classname() == "POI") { Icon* icon = dynamic_cast(parsed_poi); - if (category_filter.in_hierarchy(split(icon->category.category,"."))) { + if (category_filter.in_hierarchy(split(icon->category.category, "."))) { category_proto.add_icon()->MergeFrom(icon->as_protobuf()); has_valid_contents = true; } } else if (parsed_poi->classname() == "Trail") { Trail* trail = dynamic_cast(parsed_poi); - if (category_filter.in_hierarchy(split(trail->category.category,"."))) { + if (category_filter.in_hierarchy(split(trail->category.category, "."))) { category_proto.add_trail()->MergeFrom(trail->as_protobuf()); has_valid_contents = true; } @@ -138,7 +133,6 @@ MaybeCategory build_category_objects( else { std::cout << "Unknown type" << std::endl; } - } } @@ -148,14 +142,11 @@ MaybeCategory build_category_objects( return return_value; } - - void _write_protobuf_file( - const string &filepath, - const StringHierarchy &category_filter, + const string& filepath, + const StringHierarchy& category_filter, const map* marker_categories, - const std::map> &category_to_pois -){ + const std::map>& category_to_pois) { ofstream outfile; outfile.open(filepath, ios::out | ios::binary); @@ -170,8 +161,7 @@ void _write_protobuf_file( category_object, category_filter, category_to_pois, - category_vector - ); + &category_vector); if (maybe_category.is_category) { output_message.add_category()->MergeFrom(maybe_category.category); @@ -183,11 +173,10 @@ void _write_protobuf_file( } void write_protobuf_file( - const string &filepath, - const StringHierarchy &category_filter, + const string& filepath, + const StringHierarchy& category_filter, const map* marker_categories, - const vector* parsed_pois -) { + const vector* parsed_pois) { std::map> category_to_pois; for (size_t i = 0; i < parsed_pois->size(); i++) { @@ -209,18 +198,15 @@ void write_protobuf_file( filepath, category_filter, marker_categories, - category_to_pois - ); + category_to_pois); } // Write protobuf per map id void write_protobuf_file_per_map_id( - const string &proto_directory, - const StringHierarchy &category_filter, + const string& proto_directory, + const StringHierarchy& category_filter, const map* marker_categories, - const vector* parsed_pois -) { - + const vector* parsed_pois) { std::map>> mapid_to_category_to_pois; for (size_t i = 0; i < parsed_pois->size(); i++) { @@ -239,15 +225,12 @@ void write_protobuf_file_per_map_id( } for (auto iterator = mapid_to_category_to_pois.begin(); iterator != mapid_to_category_to_pois.end(); iterator++) { - string output_filepath = proto_directory + "/" + to_string(iterator->first) + ".data"; _write_protobuf_file( output_filepath, category_filter, marker_categories, - iterator->second - ); + iterator->second); } } - diff --git a/xml_converter/src/packaging_protobin.hpp b/xml_converter/src/packaging_protobin.hpp index c537c8bd..a62c02b7 100644 --- a/xml_converter/src/packaging_protobin.hpp +++ b/xml_converter/src/packaging_protobin.hpp @@ -7,8 +7,8 @@ #include "category_gen.hpp" #include "parseable.hpp" -#include "waypoint.pb.h" #include "string_hierarchy.hpp" +#include "waypoint.pb.h" void read_protobuf_file( std::string proto_filepath, @@ -16,13 +16,13 @@ void read_protobuf_file( std::vector* parsed_pois); void write_protobuf_file( - const std::string &proto_directory, - const StringHierarchy &category_filter, + const std::string& proto_directory, + const StringHierarchy& category_filter, const std::map* marker_categories, const std::vector* parsed_pois); void write_protobuf_file_per_map_id( - const std::string &proto_directory, - const StringHierarchy &category_filter, + const std::string& proto_directory, + const StringHierarchy& category_filter, const std::map* marker_categories, const std::vector* parsed_pois); diff --git a/xml_converter/src/string_helper.cpp b/xml_converter/src/string_helper.cpp index a236f6fc..ac18c2e6 100644 --- a/xml_converter/src/string_helper.cpp +++ b/xml_converter/src/string_helper.cpp @@ -48,12 +48,12 @@ vector split(string input, string delimiter) { return output; } -string join(const vector &input, string delimiter) { +string join(const vector& input, string delimiter) { string result; - for(size_t i = 0; i < input.size(); i++) { + for (size_t i = 0; i < input.size(); i++) { result += input[i]; // Don't add delimiter after the last element - if(i < input.size() - 1) { + if (i < input.size() - 1) { result += delimiter; } } diff --git a/xml_converter/src/string_helper.hpp b/xml_converter/src/string_helper.hpp index 68aa5e1c..22bcb4ab 100644 --- a/xml_converter/src/string_helper.hpp +++ b/xml_converter/src/string_helper.hpp @@ -12,7 +12,7 @@ bool normalized_matches_any(std::string test, std::vector list); std::string lowercase(std::string); std::vector split(std::string input, std::string delimiter); -std::string join(const std::vector &input, std::string delimiter); +std::string join(const std::vector& input, std::string delimiter); std::string normalize(std::string input_string);