Skip to content

Commit

Permalink
Changed names of variables to be more descriptive. Edited search for …
Browse files Browse the repository at this point in the history
…file by suffix function to return relative paths
  • Loading branch information
klingbolt committed Nov 13, 2024
1 parent 43acbc4 commit 628e590
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ expected_stdout: |
Please remove one of the packs or edit the name of the packs' top level category before running the program again.
If you want to bypass this stop, use '--allow-duplicates'.
The following top level categories were found in more than one pack:
mycategory in files
pack/xml_file.xml
pack3/xml_file.xml
pack2/markers.bin
"mycategory" in files:
pack/xml_file.xml
pack2/markers.bin
pack3/xml_file.xml
expected_stderr: |
expected_returncode: 0
68 changes: 34 additions & 34 deletions xml_converter/src/xml_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool filename_comp(string a, string b) {
return lowercase(a) < lowercase(b);
}

// Searchs for files within a directory with a suffix and returns their relative paths.
vector<string> get_files_by_suffix(string directory, string suffix) {
vector<string> files;
DIR* dir = opendir(directory.c_str());
Expand All @@ -49,11 +50,11 @@ vector<string> get_files_by_suffix(string directory, string suffix) {
// Default: markerpacks have all xml files in the first directory
for (string subfile : subfiles) {
cout << subfile << " found in subfolder" << endl;
files.push_back(subfile);
files.push_back(join_file_paths(filename, subfile));
}
}
else if (has_suffix(filename, suffix)) {
files.push_back(path);
files.push_back(filename);
}
}
}
Expand All @@ -66,58 +67,58 @@ map<string, vector<string>> read_taco_directory(
string input_path,
map<string, Category>* marker_categories,
vector<Parseable*>* parsed_pois) {
map<string, vector<string>> category_to_filepath;
map<string, vector<string>> top_level_category_file_locations;
if (!filesystem::exists(input_path)) {
cout << "Error: " << input_path << " is not an existing directory or file" << endl;
}
else if (filesystem::is_directory(input_path)) {
string directory_name = filesystem::path(input_path).filename();
vector<string> xml_files = get_files_by_suffix(input_path, ".xml");
for (const string& path : xml_files) {
set<string> category_names = (parse_xml_file(path, input_path, marker_categories, parsed_pois));
string relative_path = directory_name + path.substr(input_path.size());
for (set<string>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_filepath[*it].push_back(relative_path);
set<string> top_level_category_names = parse_xml_file(join_file_paths(input_path, path), input_path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}
}
}
else if (filesystem::is_regular_file(input_path)) {
set<string> category_names = parse_xml_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois);
set<string> top_level_category_names = parse_xml_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois);
string filename = filesystem::path(input_path).filename();
for (set<string>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_filepath[*it].push_back(filename);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(filename);
}
}
return category_to_filepath;
return top_level_category_file_locations;
}

map<string, vector<string>> read_burrito_directory(
string input_path,
map<string, Category>* marker_categories,
vector<Parseable*>* parsed_pois) {
map<string, vector<string>> category_to_filepath;
map<string, vector<string>> top_level_category_file_locations;
if (!filesystem::exists(input_path)) {
cout << "Error: " << input_path << " is not an existing directory or file" << endl;
}
else if (filesystem::is_directory(input_path)) {
string directory_name = filesystem::path(input_path).filename();
vector<string> burrito_files = get_files_by_suffix(input_path, ".bin");
for (const string& path : burrito_files) {
set<string> category_names = read_protobuf_file(path, input_path, marker_categories, parsed_pois);
string relative_path = directory_name + path.substr(input_path.size());
for (set<string>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_filepath[*it].push_back(relative_path);
set<string> top_level_category_names = read_protobuf_file(join_file_paths(input_path, path), input_path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}
}
}
else if (filesystem::is_regular_file(input_path)) {
set<string> category_names = read_protobuf_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois);
set<string> top_level_category_names = read_protobuf_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois);
string filename = filesystem::path(input_path).filename();
for (set<string>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_filepath[*it].push_back(filename);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(filename);
}
}
return category_to_filepath;
return top_level_category_file_locations;
}

void write_taco_directory(
Expand Down Expand Up @@ -172,21 +173,20 @@ void process_data(
// All of the loaded pois and categories
vector<Parseable*> parsed_pois;
map<string, Category> marker_categories;
map<string, vector<vector<string>>> category_to_marker_pack_names;
map<string, vector<string>> duplicate_categories;
map<string, vector<vector<string>>> top_level_category_file_locations_by_pack;
map<string, set<string>> duplicate_categories;

// Read in all the xml taco markerpacks
auto begin = chrono::high_resolution_clock::now();
for (size_t i = 0; i < input_taco_paths.size(); i++) {
cout << "Loading taco pack " << input_taco_paths[i] << endl;

// swap this to map <category, set<filenames>>)
map<string, vector<string>> category_names = read_taco_directory(
map<string, vector<string>> top_level_category_file_locations = read_taco_directory(
input_taco_paths[i],
&marker_categories,
&parsed_pois);
for (map<string, vector<string>>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_marker_pack_names[it->first].push_back(it->second);
for (map<string, vector<string>>::iterator it = top_level_category_file_locations.begin(); it != top_level_category_file_locations.end(); it++) {
top_level_category_file_locations_by_pack[it->first].push_back(it->second);
}
}
auto end = chrono::high_resolution_clock::now();
Expand All @@ -198,20 +198,20 @@ void process_data(
for (size_t i = 0; i < input_guildpoint_paths.size(); i++) {
cout << "Loading guildpoint pack " << input_guildpoint_paths[i] << endl;

map<string, vector<string>> category_names = read_burrito_directory(
map<string, vector<string>> top_level_category_file_locations = read_burrito_directory(
input_guildpoint_paths[i],
&marker_categories,
&parsed_pois);
for (map<string, vector<string>>::iterator it = category_names.begin(); it != category_names.end(); it++) {
category_to_marker_pack_names[it->first].push_back(it->second);
for (map<string, vector<string>>::iterator it = top_level_category_file_locations.begin(); it != top_level_category_file_locations.end(); it++) {
top_level_category_file_locations_by_pack[it->first].push_back(it->second);
}
}

for (map<string, vector<vector<string>>>::iterator it = category_to_marker_pack_names.begin(); it != category_to_marker_pack_names.end(); it++) {
for (map<string, vector<vector<string>>>::iterator it = top_level_category_file_locations_by_pack.begin(); it != top_level_category_file_locations_by_pack.end(); it++) {
if (it->second.size() != 1) {
for (size_t i = 0; i < it->second.size(); i++) {
for (size_t j = 0; j < it->second[i].size(); j++) {
duplicate_categories[it->first].push_back(it->second[i][j]);
duplicate_categories[it->first].insert(it->second[i][j]);
}
}
}
Expand All @@ -224,10 +224,10 @@ void process_data(
cout << "Please remove one of the packs or edit the name of the packs' top level category before running the program again." << endl;
cout << "If you want to bypass this stop, use '--allow-duplicates'." << endl;
cout << "The following top level categories were found in more than one pack:" << endl;
for (map<string, vector<string>>::iterator it = duplicate_categories.begin(); it != duplicate_categories.end(); it++) {
cout << it->first << " in files:" << endl;
for (map<string, set<string>>::iterator it = duplicate_categories.begin(); it != duplicate_categories.end(); it++) {
cout << " \"" << it->first << "\" in files:" << endl;
for (string str : it->second) {
cout << str << endl;
cout << " " << str << endl;
}
}
return;
Expand Down

0 comments on commit 628e590

Please sign in to comment.