From d514b7e63e0695952f7c2dd787a104cd15b15caf Mon Sep 17 00:00:00 2001 From: Timm Ruppert Date: Thu, 7 Nov 2024 10:36:56 +0100 Subject: [PATCH] reorder structure Signed-off-by: Timm Ruppert --- examples/CMakeLists.txt | 10 +++++----- examples/example_native_binary_reader.cpp | 2 +- ..._text_reader.cpp => example_txth_reader.cpp} | 4 ++-- .../{ => reader}/NativeBinaryTraceFileReader.h | 2 +- .../txthTraceFileReader.h} | 4 ++-- .../{ => writer}/MCAPTraceFileWriter.h | 2 +- src/CMakeLists.txt | 10 +++++----- .../NativeBinaryTraceFileReader.cpp | 2 +- src/tracefile/{ => reader}/Reader.cpp | 6 +++--- .../txthTraceFileReader.cpp} | 17 +++++++---------- .../{ => writer}/MCAPTraceFileWriter.cpp | 2 +- src/tracefile/{ => writer}/Writer.cpp | 2 +- .../NativeBinaryTraceFileReader_test.cpp | 0 .../{ => writer}/MCAPTraceFileWriter_test.cpp | 0 14 files changed, 30 insertions(+), 33 deletions(-) rename examples/{example_text_reader.cpp => example_txth_reader.cpp} (98%) rename include/osi-utilities/tracefile/{ => reader}/NativeBinaryTraceFileReader.h (99%) rename include/osi-utilities/tracefile/{TextTraceFileReader.h => reader/txthTraceFileReader.h} (97%) rename include/osi-utilities/tracefile/{ => writer}/MCAPTraceFileWriter.h (98%) rename src/tracefile/{ => reader}/NativeBinaryTraceFileReader.cpp (97%) rename src/tracefile/{ => reader}/Reader.cpp (76%) rename src/tracefile/{TextTraceFileReader.cpp => reader/txthTraceFileReader.cpp} (84%) rename src/tracefile/{ => writer}/MCAPTraceFileWriter.cpp (99%) rename src/tracefile/{ => writer}/Writer.cpp (93%) rename tests/src/tracefile/{ => reader}/NativeBinaryTraceFileReader_test.cpp (100%) rename tests/src/tracefile/{ => writer}/MCAPTraceFileWriter_test.cpp (100%) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4c03249..4005b9a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,19 +1,19 @@ # Create executables for each example add_executable(example_mcap_writer example_mcap_writer.cpp) add_executable(example_native_binary_reader example_native_binary_reader.cpp) -add_executable(example_text_reader example_text_reader.cpp) +add_executable(example_txth_reader example_txth_reader.cpp) add_executable(convert_osi2mcap convert_osi2mcap.cpp) # Link against OSI made available by parent CMakeLists.txt if(LINK_WITH_SHARED_OSI) target_link_libraries(example_mcap_writer PRIVATE open_simulation_interface) target_link_libraries(example_native_binary_reader PRIVATE open_simulation_interface) - target_link_libraries(example_text_reader PRIVATE open_simulation_interface) + target_link_libraries(example_txth_reader PRIVATE open_simulation_interface) target_link_libraries(convert_osi2mcap PRIVATE open_simulation_interface) else() target_link_libraries(example_mcap_writer PRIVATE open_simulation_interface_pic) target_link_libraries(example_native_binary_reader PRIVATE open_simulation_interface_pic) - target_link_libraries(example_text_reader PRIVATE open_simulation_interface_pic) + target_link_libraries(example_txth_reader PRIVATE open_simulation_interface_pic) target_link_libraries(convert_osi2mcap PRIVATE open_simulation_interface_pic) include_directories(${OSI_INCLUDE_DIR}) endif() @@ -21,11 +21,11 @@ endif() # Link each example against the library target_link_libraries(example_mcap_writer PRIVATE OSIUtilities) target_link_libraries(example_native_binary_reader PRIVATE OSIUtilities) -target_link_libraries(example_text_reader PRIVATE OSIUtilities) +target_link_libraries(example_txth_reader PRIVATE OSIUtilities) target_link_libraries(convert_osi2mcap PRIVATE OSIUtilities) # Specify the public headers for the library for clean access target_include_directories(example_mcap_writer PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(example_native_binary_reader PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_include_directories(example_text_reader PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_include_directories(example_txth_reader PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(convert_osi2mcap PUBLIC ${PROJECT_SOURCE_DIR}/include) \ No newline at end of file diff --git a/examples/example_native_binary_reader.cpp b/examples/example_native_binary_reader.cpp index 435521b..03e03e8 100644 --- a/examples/example_native_binary_reader.cpp +++ b/examples/example_native_binary_reader.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 // -#include +#include #include diff --git a/examples/example_text_reader.cpp b/examples/example_txth_reader.cpp similarity index 98% rename from examples/example_text_reader.cpp rename to examples/example_txth_reader.cpp index 8bf9bf0..5ffc9b3 100644 --- a/examples/example_text_reader.cpp +++ b/examples/example_txth_reader.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 // -#include +#include #include @@ -142,7 +142,7 @@ int main(const int argc, const char** argv) { // Open the trace file // downstream functions of Open will guess the message type from the filename (options->message_type has the unknown value) // or use the provided cli argument value for the message type - auto tracefile_reader = osi3::TextTraceFileReader(); + auto tracefile_reader = osi3::txthTraceFileReader(); if (!tracefile_reader.Open(options->file_path, options->message_type)) { std::cerr << "Error: Could not open file '" << options->file_path << "'\n\n"; return 1; diff --git a/include/osi-utilities/tracefile/NativeBinaryTraceFileReader.h b/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h similarity index 99% rename from include/osi-utilities/tracefile/NativeBinaryTraceFileReader.h rename to include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h index 920ae38..5e7ef3b 100644 --- a/include/osi-utilities/tracefile/NativeBinaryTraceFileReader.h +++ b/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h @@ -9,7 +9,7 @@ #include #include -#include "Reader.h" +#include "../Reader.h" #include "osi_groundtruth.pb.h" #include "osi_hostvehicledata.pb.h" #include "osi_motionrequest.pb.h" diff --git a/include/osi-utilities/tracefile/TextTraceFileReader.h b/include/osi-utilities/tracefile/reader/txthTraceFileReader.h similarity index 97% rename from include/osi-utilities/tracefile/TextTraceFileReader.h rename to include/osi-utilities/tracefile/reader/txthTraceFileReader.h index 5bd6603..edb922e 100644 --- a/include/osi-utilities/tracefile/TextTraceFileReader.h +++ b/include/osi-utilities/tracefile/reader/txthTraceFileReader.h @@ -11,7 +11,7 @@ #include #include -#include "Reader.h" +#include "../Reader.h" #include "osi_groundtruth.pb.h" #include "osi_hostvehicledata.pb.h" #include "osi_motionrequest.pb.h" @@ -24,7 +24,7 @@ #include "osi_trafficupdate.pb.h" namespace osi3 { -class TextTraceFileReader final : public TraceFileReader { +class txthTraceFileReader final : public TraceFileReader { /** * @brief Function type for parsing protobuf TextFormat strings into protobuf objects */ diff --git a/include/osi-utilities/tracefile/MCAPTraceFileWriter.h b/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h similarity index 98% rename from include/osi-utilities/tracefile/MCAPTraceFileWriter.h rename to include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h index 5e2bd8a..4f3bced 100644 --- a/include/osi-utilities/tracefile/MCAPTraceFileWriter.h +++ b/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h @@ -8,7 +8,7 @@ #include -#include "Writer.h" +#include "../Writer.h" namespace osi3 { /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aede6b3..f8706ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,11 +7,11 @@ option(BUILD_TESTING "Build the testing suite" ON) # specify library source files set(OSIUtilities_SRCS tracefile/MCAPImplementation.cpp - tracefile/Writer.cpp - tracefile/MCAPTraceFileWriter.cpp - tracefile/Reader.cpp - tracefile/NativeBinaryTraceFileReader.cpp - tracefile/TextTraceFileReader.cpp + tracefile/writer/Writer.cpp + tracefile/writer/MCAPTraceFileWriter.cpp + tracefile/reader/Reader.cpp + tracefile/reader/NativeBinaryTraceFileReader.cpp + tracefile/reader/txthTraceFileReader.cpp ) diff --git a/src/tracefile/NativeBinaryTraceFileReader.cpp b/src/tracefile/reader/NativeBinaryTraceFileReader.cpp similarity index 97% rename from src/tracefile/NativeBinaryTraceFileReader.cpp rename to src/tracefile/reader/NativeBinaryTraceFileReader.cpp index b020408..b454af3 100644 --- a/src/tracefile/NativeBinaryTraceFileReader.cpp +++ b/src/tracefile/reader/NativeBinaryTraceFileReader.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 // -#include "osi-utilities/tracefile/NativeBinaryTraceFileReader.h" +#include "osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h" #include #include diff --git a/src/tracefile/Reader.cpp b/src/tracefile/reader/Reader.cpp similarity index 76% rename from src/tracefile/Reader.cpp rename to src/tracefile/reader/Reader.cpp index 02ecae5..18a1536 100644 --- a/src/tracefile/Reader.cpp +++ b/src/tracefile/reader/Reader.cpp @@ -5,8 +5,8 @@ #include "osi-utilities/tracefile/Reader.h" -#include "osi-utilities/tracefile/NativeBinaryTraceFileReader.h" -#include "osi-utilities/tracefile/TextTraceFileReader.h" +#include "osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h" +#include "osi-utilities/tracefile/reader/txthTraceFileReader.h" std::unique_ptr createTraceFileReader(const std::string& format) { if (format == "mcap") { @@ -15,7 +15,7 @@ std::unique_ptr createTraceFileReader(const std::string& } else if (format == "osi") { return std::make_unique(); } else if (format == "txth") { - return std::make_unique(); + return std::make_unique(); } else { throw std::invalid_argument("Unsupported format: " + format); } diff --git a/src/tracefile/TextTraceFileReader.cpp b/src/tracefile/reader/txthTraceFileReader.cpp similarity index 84% rename from src/tracefile/TextTraceFileReader.cpp rename to src/tracefile/reader/txthTraceFileReader.cpp index 05caaa8..f60a213 100644 --- a/src/tracefile/TextTraceFileReader.cpp +++ b/src/tracefile/reader/txthTraceFileReader.cpp @@ -3,16 +3,13 @@ // SPDX-License-Identifier: MPL-2.0 // -#include "osi-utilities/tracefile/TextTraceFileReader.h" +#include "osi-utilities/tracefile/reader/txthTraceFileReader.h" #include -#include - -#include "google/protobuf/text_format.h" namespace osi3 { -bool TextTraceFileReader::Open(const std::string& filename) { +bool txthTraceFileReader::Open(const std::string& filename) { if (filename.find(".txth") == std::string::npos) { std::cerr << "ERROR: The trace file '" << filename << "' must have a '.txth' extension." << std::endl; return false; @@ -49,16 +46,16 @@ bool TextTraceFileReader::Open(const std::string& filename) { return trace_file_.is_open(); } -bool TextTraceFileReader::Open(const std::string& filename, const ReaderTopLevelMessage message_type) { +bool txthTraceFileReader::Open(const std::string& filename, const ReaderTopLevelMessage message_type) { message_type_ = message_type; return Open(filename); } -void TextTraceFileReader::Close() { trace_file_.close(); } +void txthTraceFileReader::Close() { trace_file_.close(); } -bool TextTraceFileReader::HasNext() { return trace_file_ && !trace_file_.eof(); } +bool txthTraceFileReader::HasNext() { return trace_file_ && !trace_file_.eof(); } -std::optional TextTraceFileReader::ReadMessage() { +std::optional txthTraceFileReader::ReadMessage() { if (!trace_file_) { return std::nullopt; } @@ -74,7 +71,7 @@ std::optional TextTraceFileReader::ReadMessage() { return result; } -std::string TextTraceFileReader::ReadNextMessageFromFile() { +std::string txthTraceFileReader::ReadNextMessageFromFile() { std::string message; std::string line; uint last_position = 0; diff --git a/src/tracefile/MCAPTraceFileWriter.cpp b/src/tracefile/writer/MCAPTraceFileWriter.cpp similarity index 99% rename from src/tracefile/MCAPTraceFileWriter.cpp rename to src/tracefile/writer/MCAPTraceFileWriter.cpp index 0ba5eb1..b4a75c5 100644 --- a/src/tracefile/MCAPTraceFileWriter.cpp +++ b/src/tracefile/writer/MCAPTraceFileWriter.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 // -#include "osi-utilities/tracefile/MCAPTraceFileWriter.h" +#include "osi-utilities/tracefile/writer/MCAPTraceFileWriter.h" #include "google/protobuf/descriptor.pb.h" #include "osi_groundtruth.pb.h" diff --git a/src/tracefile/Writer.cpp b/src/tracefile/writer/Writer.cpp similarity index 93% rename from src/tracefile/Writer.cpp rename to src/tracefile/writer/Writer.cpp index 95144e7..3c58dc8 100644 --- a/src/tracefile/Writer.cpp +++ b/src/tracefile/writer/Writer.cpp @@ -5,7 +5,7 @@ #include "osi-utilities/tracefile/Writer.h" -#include "osi-utilities/tracefile/MCAPTraceFileWriter.h" +#include "osi-utilities/tracefile/writer/MCAPTraceFileWriter.h" // todo use enum or something else instead of a string // todo for the writer use mcap as default if the "string" is empty diff --git a/tests/src/tracefile/NativeBinaryTraceFileReader_test.cpp b/tests/src/tracefile/reader/NativeBinaryTraceFileReader_test.cpp similarity index 100% rename from tests/src/tracefile/NativeBinaryTraceFileReader_test.cpp rename to tests/src/tracefile/reader/NativeBinaryTraceFileReader_test.cpp diff --git a/tests/src/tracefile/MCAPTraceFileWriter_test.cpp b/tests/src/tracefile/writer/MCAPTraceFileWriter_test.cpp similarity index 100% rename from tests/src/tracefile/MCAPTraceFileWriter_test.cpp rename to tests/src/tracefile/writer/MCAPTraceFileWriter_test.cpp