Skip to content

Commit

Permalink
clean up variable names
Browse files Browse the repository at this point in the history
Signed-off-by: Timm Ruppert <[email protected]>
  • Loading branch information
TimmRuppert committed Nov 12, 2024
1 parent b44b08b commit 7c2cf8d
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 40 deletions.
6 changes: 3 additions & 3 deletions include/osi-utilities/tracefile/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class TraceFileReader {

/**
* @brief Opens a trace file for reading
* @param filename Path to the file to be opened
* @param file_path Path to the file to be opened
* @return true if successful, false otherwise
*/
virtual bool Open(const std::string& filename) = 0;
virtual bool Open(const std::string& file_path) = 0;

/**
* @brief Reads the next message from the trace file
Expand All @@ -104,7 +104,7 @@ class TraceFileReader {
// TODO change to function which guesses on the filename endings
/**
* @brief Factory function to create trace file readers based on the input file format
* @param format The format of the input file (e.g., "mcap")
* @param The format of the input file (e.g., "mcap")
* @return Unique pointer to a TraceFileReader implementation
*/
std::unique_ptr<TraceFileReader> createTraceFileReader(const std::string& format);
Expand Down
4 changes: 2 additions & 2 deletions include/osi-utilities/tracefile/Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class TraceFileWriter {

/**
* @brief Opens a file for writing
* @param filename Path to the file to be created/opened
* @param file_path Path to the file to be created/opened
* @return true if successful, false otherwise
*/
virtual bool Open(const std::string& filename) = 0;
virtual bool Open(const std::string& file_path) = 0;

/**
* @brief Writes a protobuf message to the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace osi3 {
*/
class MCAPTraceFileReader final : public TraceFileReader {
public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;
std::optional<ReadResult> ReadMessage() override;
void Close() override;
bool HasNext() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace osi3 {
*/
class NativeBinaryTraceFileReader final : public osi3::TraceFileReader {
public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;

/**
* @brief Opens a trace file with specified message type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TXTHTraceFileReader final : public TraceFileReader {
using MessageParserFunc = std::function<std::unique_ptr<google::protobuf::Message>(const std::string&)>;

public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;
/**
* @brief Opens a trace file with specified message type
* @param filename Path to the trace file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace osi3 {
*/
class MCAPTraceFileWriter final : public osi3::TraceFileWriter {
public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;

template <typename T>
bool WriteMessage(T top_level_message, const std::string& topic = "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace osi3 {
*/
class NativeBinaryTraceFileWriter final : public TraceFileWriter {
public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;
void Close() override;

bool SetMetadata(const std::string& /*name*/, const std::unordered_map<std::string, std::string>& /*metadata_entries*/) override { return true; }
Expand Down
5 changes: 3 additions & 2 deletions include/osi-utilities/tracefile/writer/TXTHTraceFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace osi3 {
*/
class TXTHTraceFileWriter final : public TraceFileWriter {
public:
bool Open(const std::string& filename) override;
bool Open(const std::string& file_path) override;
void Close() override;

bool SetMetadata(const std::string& name, const std::unordered_map<std::string, std::string>& metadata_entries) override { return false; }
Expand All @@ -30,7 +30,8 @@ class TXTHTraceFileWriter final : public TraceFileWriter {

private:
std::ofstream trace_file_;
bool file_open_{false};
bool file_open_ = false;

};

} // namespace osi3
Expand Down
8 changes: 4 additions & 4 deletions src/tracefile/reader/MCAPTraceFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace osi3 {

bool MCAPTraceFileReader::Open(const std::string& filename) {
if (!std::filesystem::exists(filename)) {
std::cerr << "ERROR: The trace file '" << filename << "' does not exist." << std::endl;
bool MCAPTraceFileReader::Open(const std::string& file_path) {
if (!std::filesystem::exists(file_path)) {
std::cerr << "ERROR: The trace file '" << file_path << "' does not exist." << std::endl;
return false;
}

if (const auto status = mcap_reader_.open(filename); !status.ok()) {
if (const auto status = mcap_reader_.open(file_path); !status.ok()) {
std::cerr << "ERROR: Failed to open MCAP file: " << status.message << std::endl;
return false;
}
Expand Down
18 changes: 9 additions & 9 deletions src/tracefile/reader/NativeBinaryTraceFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@ bool NativeBinaryTraceFileReader::Open(const std::string& filename, const Reader
return this->Open(filename);
}

bool NativeBinaryTraceFileReader::Open(const std::string& filename) {
bool NativeBinaryTraceFileReader::Open(const std::string& file_path) {
// check if at least .osi ending is present
if (filename.find(".osi") == std::string::npos) {
std::cerr << "ERROR: The trace file '" << filename << "' must have a '.osi' extension." << std::endl;
if (file_path.find(".osi") == std::string::npos) {
std::cerr << "ERROR: The trace file '" << file_path << "' must have a '.osi' extension." << std::endl;
return false;
}

// check if file exists
if (!std::filesystem::exists(filename)) {
std::cerr << "ERROR: The trace file '" << filename << "' does not exist." << std::endl;
if (!std::filesystem::exists(file_path)) {
std::cerr << "ERROR: The trace file '" << file_path << "' does not exist." << std::endl;
return false;
}

// Determine message type based on filename if not specified in advance
if (message_type_ == ReaderTopLevelMessage::kUnknown) {
for (const auto& [key, value] : kFileNameMessageTypeMap) {
if (filename.find(key) != std::string::npos) {
if (file_path.find(key) != std::string::npos) {
message_type_ = value;
break;
}
}
}
// if message_type_ is still unknown, return false
if (message_type_ == ReaderTopLevelMessage::kUnknown) {
std::cerr << "ERROR: Unable to determine message type from the filename '" << filename
std::cerr << "ERROR: Unable to determine message type from the filename '" << file_path
<< "'. Please ensure the filename follows the recommended OSI naming conventions as specified in the documentation or specify the message type manually."
<< std::endl;
return false;
}

parser_ = kParserMap_.at(message_type_);

trace_file_ = std::ifstream(filename, std::ios::binary);
trace_file_ = std::ifstream(file_path, std::ios::binary);
if (!trace_file_) {
std::cerr << "ERROR: Failed to open trace file: " << filename << std::endl;
std::cerr << "ERROR: Failed to open trace file: " << file_path << std::endl;
return false;
}
return true;
Expand Down
14 changes: 7 additions & 7 deletions src/tracefile/reader/TXTHTraceFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

namespace osi3 {

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;
bool TXTHTraceFileReader::Open(const std::string& file_path) {
if (file_path.find(".txth") == std::string::npos) {
std::cerr << "ERROR: The trace file '" << file_path << "' must have a '.txth' extension." << std::endl;
return false;
}

if (!std::filesystem::exists(filename)) {
std::cerr << "ERROR: The trace file '" << filename << "' does not exist." << std::endl;
if (!std::filesystem::exists(file_path)) {
std::cerr << "ERROR: The trace file '" << file_path << "' does not exist." << std::endl;
return false;
}

if (message_type_ == ReaderTopLevelMessage::kUnknown) {
for (const auto& [key, value] : kFileNameMessageTypeMap) {
if (filename.find(key) != std::string::npos) {
if (file_path.find(key) != std::string::npos) {
message_type_ = value;
break;
}
Expand All @@ -36,7 +36,7 @@ bool TXTHTraceFileReader::Open(const std::string& filename) {

parser_ = kParserMap_.at(message_type_);

trace_file_ = std::ifstream(filename);
trace_file_ = std::ifstream(file_path);

// find top-level message delimiter by peeking into the file and assuming the first line
// will be the pattern to indicate a new message
Expand Down
4 changes: 2 additions & 2 deletions src/tracefile/writer/MCAPTraceFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ std::string GetCurrentTimeString() {
} // namespace

namespace osi3 {
bool MCAPTraceFileWriter::Open(const std::string& filename) {
const auto res = mcap_writer_.open(filename, mcap_options_);
bool MCAPTraceFileWriter::Open(const std::string& file_path) {
const auto res = mcap_writer_.open(file_path, mcap_options_);
if (res.ok()) {
file_open_ = true;
this->AddCommonMetadata();
Expand Down
6 changes: 3 additions & 3 deletions src/tracefile/writer/NativeBinaryTraceFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

namespace osi3 {

bool NativeBinaryTraceFileWriter::Open(const std::string& filename) {
if (filename.substr(filename.length() - 4) != ".osi") {
bool NativeBinaryTraceFileWriter::Open(const std::string& file_path) {
if (file_path.substr(file_path.length() - 4) != ".osi") {
std::cerr << "Error: Filename must end with .osi extension\n";
return false;
}

trace_file_.open(filename, std::ios::binary);
trace_file_.open(file_path, std::ios::binary);
if (trace_file_.is_open()) {
file_open_ = true;
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/tracefile/writer/TXTHTraceFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

namespace osi3 {

bool TXTHTraceFileWriter::Open(const std::string& filename) {
if (filename.substr(filename.length() - 5) != ".txth") {
bool TXTHTraceFileWriter::Open(const std::string& file_path) {
if (file_path.substr(file_path.length() - 5) != ".txth") {
std::cerr << "Error: Filename must end with .txth extension\n";
return false;
}

trace_file_.open(filename);
trace_file_.open(file_path);
if (trace_file_.is_open()) {
file_open_ = true;
return true;
Expand Down

0 comments on commit 7c2cf8d

Please sign in to comment.