Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Sep 22, 2023
1 parent c4b38d4 commit b8e7a89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 49 deletions.
63 changes: 23 additions & 40 deletions xml_converter/src/packaging_protobin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include "category_gen.hpp"
#include "parseable.hpp"
#include "string_helper.hpp"
#include "waypoint.pb.h"
#include "string_hierarchy.hpp"

#include <google/protobuf/text_format.h> // For TextProtos
#include "waypoint.pb.h"

using namespace std;

Expand Down Expand Up @@ -84,61 +82,57 @@ struct MaybeCategory {
};
MaybeCategory build_category_objects(
const Category* category,
const StringHierarchy &category_filter,
const std::map<string, std::vector<Parseable*>> &category_to_pois,
vector<string> &category_vector
) {
const StringHierarchy& category_filter,
const std::map<string, std::vector<Parseable*>>& category_to_pois,
vector<string>* category_vector) {
waypoint::Category category_proto = category->as_protobuf();
bool has_valid_contents = false;

vector<waypoint::Category> categories_to_write;

for (map<string, Category>::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++) {
Parseable* parsed_poi = iterator->second[i];

if (parsed_poi->classname() == "POI") {
Icon* icon = dynamic_cast<Icon*>(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<Trail*>(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;
}
}
else {
std::cout << "Unknown type" << std::endl;
}

}
}

Expand All @@ -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<string, Category>* marker_categories,
const std::map<string, std::vector<Parseable*>> &category_to_pois
){
const std::map<string, std::vector<Parseable*>>& category_to_pois) {
ofstream outfile;
outfile.open(filepath, ios::out | ios::binary);

Expand All @@ -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);
Expand All @@ -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<string, Category>* marker_categories,
const vector<Parseable*>* parsed_pois
) {
const vector<Parseable*>* parsed_pois) {
std::map<string, std::vector<Parseable*>> category_to_pois;

for (size_t i = 0; i < parsed_pois->size(); i++) {
Expand All @@ -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<string, Category>* marker_categories,
const vector<Parseable*>* parsed_pois
) {

const vector<Parseable*>* parsed_pois) {
std::map<int, std::map<string, std::vector<Parseable*>>> mapid_to_category_to_pois;

for (size_t i = 0; i < parsed_pois->size(); i++) {
Expand All @@ -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);
}
}

10 changes: 5 additions & 5 deletions xml_converter/src/packaging_protobin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

#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,
std::map<std::string, Category>* marker_categories,
std::vector<Parseable*>* 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<std::string, Category>* marker_categories,
const std::vector<Parseable*>* 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<std::string, Category>* marker_categories,
const std::vector<Parseable*>* parsed_pois);
6 changes: 3 additions & 3 deletions xml_converter/src/string_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ vector<string> split(string input, string delimiter) {
return output;
}

string join(const vector<string> &input, string delimiter) {
string join(const vector<string>& 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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion xml_converter/src/string_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool normalized_matches_any(std::string test, std::vector<std::string> list);
std::string lowercase(std::string);

std::vector<std::string> split(std::string input, std::string delimiter);
std::string join(const std::vector<std::string> &input, std::string delimiter);
std::string join(const std::vector<std::string>& input, std::string delimiter);

std::string normalize(std::string input_string);

Expand Down

0 comments on commit b8e7a89

Please sign in to comment.