Skip to content

Commit

Permalink
reorder structure
Browse files Browse the repository at this point in the history
Signed-off-by: Timm Ruppert <[email protected]>
  • Loading branch information
TimmRuppert committed Nov 7, 2024
1 parent 9dcc389 commit d514b7e
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 33 deletions.
10 changes: 5 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# 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()

# 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)
2 changes: 1 addition & 1 deletion examples/example_native_binary_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
//

#include <osi-utilities/tracefile/NativeBinaryTraceFileReader.h>
#include <osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h>

#include <optional>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
//

#include <osi-utilities/tracefile/TextTraceFileReader.h>
#include <osi-utilities/tracefile/reader/txthTraceFileReader.h>

#include <optional>

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <fstream>
#include <functional>

#include "Reader.h"
#include "../Reader.h"
#include "osi_groundtruth.pb.h"
#include "osi_hostvehicledata.pb.h"
#include "osi_motionrequest.pb.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <fstream>
#include <functional>

#include "Reader.h"
#include "../Reader.h"
#include "osi_groundtruth.pb.h"
#include "osi_hostvehicledata.pb.h"
#include "osi_motionrequest.pb.h"
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <mcap/mcap.hpp>

#include "Writer.h"
#include "../Writer.h"

namespace osi3 {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
//

#include "osi-utilities/tracefile/NativeBinaryTraceFileReader.h"
#include "osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h"

#include <filesystem>
#include <sstream>
Expand Down
6 changes: 3 additions & 3 deletions src/tracefile/Reader.cpp → src/tracefile/reader/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<osi3::TraceFileReader> createTraceFileReader(const std::string& format) {
if (format == "mcap") {
Expand All @@ -15,7 +15,7 @@ std::unique_ptr<osi3::TraceFileReader> createTraceFileReader(const std::string&
} else if (format == "osi") {
return std::make_unique<osi3::NativeBinaryTraceFileReader>();
} else if (format == "txth") {
return std::make_unique<osi3::TextTraceFileReader>();
return std::make_unique<osi3::txthTraceFileReader>();
} else {
throw std::invalid_argument("Unsupported format: " + format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
// SPDX-License-Identifier: MPL-2.0
//

#include "osi-utilities/tracefile/TextTraceFileReader.h"
#include "osi-utilities/tracefile/reader/txthTraceFileReader.h"

#include <filesystem>
#include <sstream>

#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;
Expand Down Expand Up @@ -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<ReadResult> TextTraceFileReader::ReadMessage() {
std::optional<ReadResult> txthTraceFileReader::ReadMessage() {
if (!trace_file_) {
return std::nullopt;
}
Expand All @@ -74,7 +71,7 @@ std::optional<ReadResult> TextTraceFileReader::ReadMessage() {
return result;
}

std::string TextTraceFileReader::ReadNextMessageFromFile() {
std::string txthTraceFileReader::ReadNextMessageFromFile() {
std::string message;
std::string line;
uint last_position = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d514b7e

Please sign in to comment.