From 8cd90dbd78ddb83ddae8a2b23e62826009d331ab Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 17 Oct 2023 20:34:28 -0400 Subject: [PATCH 1/8] Allows files and directories to inputs and handles them based on type --- xml_converter/src/xml_converter.cpp | 37 ++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index cb39da84..d0838e2e 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -89,16 +90,40 @@ void move_supplementary_files(string input_directory, string output_directory) { } } -void read_taco_directory(string directory, map* marker_categories, vector* parsed_pois) { - vector xml_files = get_files_by_suffix(directory, ".xml"); - for (const string& path : xml_files) { - parse_xml_file(path, marker_categories, parsed_pois); +void read_taco_directory(string input_path, map* marker_categories, vector* parsed_pois) { + if (filesystem::is_regular_file(input_path)) { + if (has_suffix(input_path, ".xml")) { + parse_xml_file(input_path, marker_categories, parsed_pois); + } + else { + cout << "Error: " << input_path << " is a file that does not end in .xml" << endl; + } + } + else if (filesystem::is_directory(input_path)) { + vector xml_files = get_files_by_suffix(input_path, ".xml"); + for (const string& path : xml_files) { + parse_xml_file(path, marker_categories, parsed_pois); + } + } + else { + cout << "Error: Unknown file type" << endl; } } -void write_taco_directory(string directory, map* marker_categories, vector* parsed_pois) { +void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 - string xml_filepath = directory + "xml_file.xml"; + string xml_filepath; + if (filesystem::is_regular_file(output_path)) { + if (has_suffix(output_path, ".xml")) { + xml_filepath = output_path; + } + else { + xml_filepath = output_path + "xml_file.xml"; + } + } + else { + xml_filepath = output_path + "xml_file.xml"; + } write_xml_file(xml_filepath, marker_categories, parsed_pois); } From 96f7b7c718c05f2483a28772c6f114411903f543 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 22 Oct 2023 15:17:43 -0400 Subject: [PATCH 2/8] Removing requirement that files end in .xml --- xml_converter/src/xml_converter.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index d0838e2e..44b9067e 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -91,13 +91,8 @@ void move_supplementary_files(string input_directory, string output_directory) { } void read_taco_directory(string input_path, map* marker_categories, vector* parsed_pois) { - if (filesystem::is_regular_file(input_path)) { - if (has_suffix(input_path, ".xml")) { - parse_xml_file(input_path, marker_categories, parsed_pois); - } - else { - cout << "Error: " << input_path << " is a file that does not end in .xml" << endl; - } + if (!filesystem::exists(input_path)){ + cout << "Error: " << input_path << " is not an existing directory or file"; } else if (filesystem::is_directory(input_path)) { vector xml_files = get_files_by_suffix(input_path, ".xml"); @@ -105,24 +100,21 @@ void read_taco_directory(string input_path, map* marker_catego parse_xml_file(path, marker_categories, parsed_pois); } } - else { - cout << "Error: Unknown file type" << endl; + else if (filesystem::is_regular_file(input_path)) { + parse_xml_file(input_path, marker_categories, parsed_pois); } } void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 string xml_filepath; - if (filesystem::is_regular_file(output_path)) { - if (has_suffix(output_path, ".xml")) { - xml_filepath = output_path; - } - else { - xml_filepath = output_path + "xml_file.xml"; - } + if (filesystem::is_directory(output_path)) { + if (!has_suffix(output_path, "/")) + output_path += "/"; + xml_filepath = output_path + "/xml_file.xml"; } else { - xml_filepath = output_path + "xml_file.xml"; + xml_filepath = output_path; } write_xml_file(xml_filepath, marker_categories, parsed_pois); } From 01ecfeb0554b549ac3177cb38d24c0feba895bbc Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 31 Oct 2023 22:27:00 -0400 Subject: [PATCH 3/8] Logic for if an output path does not exist --- xml_converter/src/xml_converter.cpp | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 44b9067e..94e56a1c 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -91,8 +91,8 @@ void move_supplementary_files(string input_directory, string output_directory) { } void read_taco_directory(string input_path, map* marker_categories, vector* parsed_pois) { - if (!filesystem::exists(input_path)){ - cout << "Error: " << input_path << " is not an existing directory or file"; + if (!filesystem::exists(input_path)) { + cout << "Error: " << input_path << " is not an existing directory or file" << endl; } else if (filesystem::is_directory(input_path)) { vector xml_files = get_files_by_suffix(input_path, ".xml"); @@ -108,13 +108,32 @@ void read_taco_directory(string input_path, map* marker_catego void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 string xml_filepath; - if (filesystem::is_directory(output_path)) { - if (!has_suffix(output_path, "/")) - output_path += "/"; - xml_filepath = output_path + "/xml_file.xml"; + // If the file path leads to a directory or file, use that path + // This will overwrite files + if (filesystem::exists(output_path)) { + if (filesystem::is_directory(output_path)) { + if (!has_suffix(output_path, "/")) + output_path += "/"; + xml_filepath = output_path + "xml_file.xml"; + } + else { + xml_filepath = output_path; + } } + // If the file path does not exist, assumes it is a directory path + // unless it ends in .xml, in which it is assumed to be a file path else { - xml_filepath = output_path; + if (has_suffix(output_path, ".xml")) { + xml_filepath = output_path; + } + else if (filesystem::create_directory(output_path)) { + if (!has_suffix(output_path, "/")) + output_path += "/"; + xml_filepath = output_path + "xml_file.xml"; + } + else { + cout << "Error: " << output_path << "is not a valid directory path" << endl; + } } write_xml_file(xml_filepath, marker_categories, parsed_pois); } From b60141bb8a871b9d665f717d13aec179f7001b9b Mon Sep 17 00:00:00 2001 From: klingbolt Date: Wed, 1 Nov 2023 00:08:00 -0400 Subject: [PATCH 4/8] Removed xml file as an output --- xml_converter/src/xml_converter.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 94e56a1c..d39cbd36 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -120,13 +120,9 @@ void write_taco_directory(string output_path, map* marker_cate xml_filepath = output_path; } } - // If the file path does not exist, assumes it is a directory path - // unless it ends in .xml, in which it is assumed to be a file path + // If the file path does not exist, assume it is a directory path else { - if (has_suffix(output_path, ".xml")) { - xml_filepath = output_path; - } - else if (filesystem::create_directory(output_path)) { + if (filesystem::create_directory(output_path)) { if (!has_suffix(output_path, "/")) output_path += "/"; xml_filepath = output_path + "xml_file.xml"; From c20b1846ebdb6564f0cbc07ffa372618f04429d7 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sat, 4 Nov 2023 21:46:50 -0400 Subject: [PATCH 5/8] Removed duplicated logic --- xml_converter/src/xml_converter.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index d39cbd36..609e668e 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -108,26 +108,16 @@ void read_taco_directory(string input_path, map* marker_catego void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 string xml_filepath; - // If the file path leads to a directory or file, use that path - // This will overwrite files - if (filesystem::exists(output_path)) { - if (filesystem::is_directory(output_path)) { - if (!has_suffix(output_path, "/")) - output_path += "/"; - xml_filepath = output_path + "xml_file.xml"; - } - else { - xml_filepath = output_path; - } + if (!has_suffix(output_path, "/")){ + output_path += "/"; + xml_filepath = output_path + "xml_file.xml"; } - // If the file path does not exist, assume it is a directory path else { - if (filesystem::create_directory(output_path)) { - if (!has_suffix(output_path, "/")) - output_path += "/"; - xml_filepath = output_path + "xml_file.xml"; + xml_filepath = output_path; } - else { + + if (!filesystem::is_directory(output_path)) { + if (!filesystem::create_directory(output_path)) { cout << "Error: " << output_path << "is not a valid directory path" << endl; } } From d15d3371b5ab0c985bdaf674f5cc5260c6a7f32c Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sat, 4 Nov 2023 21:47:45 -0400 Subject: [PATCH 6/8] Linter fixes --- xml_converter/src/xml_converter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 609e668e..e2f86bca 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -108,13 +108,13 @@ void read_taco_directory(string input_path, map* marker_catego void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 string xml_filepath; - if (!has_suffix(output_path, "/")){ + if (!has_suffix(output_path, "/")) { output_path += "/"; xml_filepath = output_path + "xml_file.xml"; } else { - xml_filepath = output_path; - } + xml_filepath = output_path; + } if (!filesystem::is_directory(output_path)) { if (!filesystem::create_directory(output_path)) { From 66762727ed322b6219952a27a7e8eb65e0d1da72 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 5 Nov 2023 00:32:32 -0400 Subject: [PATCH 7/8] removed unnessecary variable --- xml_converter/src/xml_converter.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index e2f86bca..3100d85f 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -107,21 +107,14 @@ void read_taco_directory(string input_path, map* marker_catego void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 - string xml_filepath; if (!has_suffix(output_path, "/")) { output_path += "/"; - xml_filepath = output_path + "xml_file.xml"; - } - else { - xml_filepath = output_path; - } - if (!filesystem::is_directory(output_path)) { if (!filesystem::create_directory(output_path)) { cout << "Error: " << output_path << "is not a valid directory path" << endl; } } - write_xml_file(xml_filepath, marker_categories, parsed_pois); + write_xml_file(output_path + "xml_file.xml", marker_categories, parsed_pois); } //////////////////////////////////////////////////////////////////////////////// From 757906cee0736f613208421fc29fd3c0f934efe8 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 5 Nov 2023 00:36:26 -0400 Subject: [PATCH 8/8] Added bracket --- xml_converter/src/xml_converter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 3100d85f..fb0ebe78 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -109,6 +109,7 @@ void write_taco_directory(string output_path, map* marker_cate // TODO: Exportion of XML Marker Packs File Structure #111 if (!has_suffix(output_path, "/")) { output_path += "/"; + } if (!filesystem::is_directory(output_path)) { if (!filesystem::create_directory(output_path)) { cout << "Error: " << output_path << "is not a valid directory path" << endl;