From 7c2cf8d6ceb434ee4940ddf1612e21021ec798ef Mon Sep 17 00:00:00 2001 From: Timm Ruppert Date: Tue, 12 Nov 2024 18:58:58 +0100 Subject: [PATCH] clean up variable names Signed-off-by: Timm Ruppert --- include/osi-utilities/tracefile/Reader.h | 6 +++--- include/osi-utilities/tracefile/Writer.h | 4 ++-- .../tracefile/reader/MCAPTraceFileReader.h | 2 +- .../reader/NativeBinaryTraceFileReader.h | 2 +- .../tracefile/reader/TXTHTraceFileReader.h | 2 +- .../tracefile/writer/MCAPTraceFileWriter.h | 2 +- .../writer/NativeBinaryTraceFileWriter.h | 2 +- .../tracefile/writer/TXTHTraceFileWriter.h | 5 +++-- src/tracefile/reader/MCAPTraceFileReader.cpp | 8 ++++---- .../reader/NativeBinaryTraceFileReader.cpp | 18 +++++++++--------- src/tracefile/reader/TXTHTraceFileReader.cpp | 14 +++++++------- src/tracefile/writer/MCAPTraceFileWriter.cpp | 4 ++-- .../writer/NativeBinaryTraceFileWriter.cpp | 6 +++--- src/tracefile/writer/TXTHTraceFileWriter.cpp | 6 +++--- 14 files changed, 41 insertions(+), 40 deletions(-) diff --git a/include/osi-utilities/tracefile/Reader.h b/include/osi-utilities/tracefile/Reader.h index 011adb2..a5abdfc 100644 --- a/include/osi-utilities/tracefile/Reader.h +++ b/include/osi-utilities/tracefile/Reader.h @@ -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 @@ -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 createTraceFileReader(const std::string& format); diff --git a/include/osi-utilities/tracefile/Writer.h b/include/osi-utilities/tracefile/Writer.h index d251423..2f3d3a6 100644 --- a/include/osi-utilities/tracefile/Writer.h +++ b/include/osi-utilities/tracefile/Writer.h @@ -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 diff --git a/include/osi-utilities/tracefile/reader/MCAPTraceFileReader.h b/include/osi-utilities/tracefile/reader/MCAPTraceFileReader.h index 019d1b4..bef6245 100644 --- a/include/osi-utilities/tracefile/reader/MCAPTraceFileReader.h +++ b/include/osi-utilities/tracefile/reader/MCAPTraceFileReader.h @@ -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 ReadMessage() override; void Close() override; bool HasNext() override; diff --git a/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h b/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h index eeff4d8..7d16daa 100644 --- a/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h +++ b/include/osi-utilities/tracefile/reader/NativeBinaryTraceFileReader.h @@ -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 diff --git a/include/osi-utilities/tracefile/reader/TXTHTraceFileReader.h b/include/osi-utilities/tracefile/reader/TXTHTraceFileReader.h index d0979c7..176ff13 100644 --- a/include/osi-utilities/tracefile/reader/TXTHTraceFileReader.h +++ b/include/osi-utilities/tracefile/reader/TXTHTraceFileReader.h @@ -38,7 +38,7 @@ class TXTHTraceFileReader final : public TraceFileReader { using MessageParserFunc = std::function(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 diff --git a/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h b/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h index 6ec1888..b006712 100644 --- a/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h +++ b/include/osi-utilities/tracefile/writer/MCAPTraceFileWriter.h @@ -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 bool WriteMessage(T top_level_message, const std::string& topic = ""); diff --git a/include/osi-utilities/tracefile/writer/NativeBinaryTraceFileWriter.h b/include/osi-utilities/tracefile/writer/NativeBinaryTraceFileWriter.h index 8515593..88b81ec 100644 --- a/include/osi-utilities/tracefile/writer/NativeBinaryTraceFileWriter.h +++ b/include/osi-utilities/tracefile/writer/NativeBinaryTraceFileWriter.h @@ -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& /*metadata_entries*/) override { return true; } diff --git a/include/osi-utilities/tracefile/writer/TXTHTraceFileWriter.h b/include/osi-utilities/tracefile/writer/TXTHTraceFileWriter.h index 875aae2..8b9cbc1 100644 --- a/include/osi-utilities/tracefile/writer/TXTHTraceFileWriter.h +++ b/include/osi-utilities/tracefile/writer/TXTHTraceFileWriter.h @@ -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& metadata_entries) override { return false; } @@ -30,7 +30,8 @@ class TXTHTraceFileWriter final : public TraceFileWriter { private: std::ofstream trace_file_; - bool file_open_{false}; + bool file_open_ = false; + }; } // namespace osi3 diff --git a/src/tracefile/reader/MCAPTraceFileReader.cpp b/src/tracefile/reader/MCAPTraceFileReader.cpp index ac4a4ed..ab66dcf 100644 --- a/src/tracefile/reader/MCAPTraceFileReader.cpp +++ b/src/tracefile/reader/MCAPTraceFileReader.cpp @@ -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; } diff --git a/src/tracefile/reader/NativeBinaryTraceFileReader.cpp b/src/tracefile/reader/NativeBinaryTraceFileReader.cpp index e1b97d6..965a59a 100644 --- a/src/tracefile/reader/NativeBinaryTraceFileReader.cpp +++ b/src/tracefile/reader/NativeBinaryTraceFileReader.cpp @@ -15,23 +15,23 @@ 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; } @@ -39,7 +39,7 @@ bool NativeBinaryTraceFileReader::Open(const std::string& filename) { } // 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; @@ -47,9 +47,9 @@ bool NativeBinaryTraceFileReader::Open(const std::string& filename) { 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; diff --git a/src/tracefile/reader/TXTHTraceFileReader.cpp b/src/tracefile/reader/TXTHTraceFileReader.cpp index 36af246..f248d82 100644 --- a/src/tracefile/reader/TXTHTraceFileReader.cpp +++ b/src/tracefile/reader/TXTHTraceFileReader.cpp @@ -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; } @@ -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 diff --git a/src/tracefile/writer/MCAPTraceFileWriter.cpp b/src/tracefile/writer/MCAPTraceFileWriter.cpp index b4a75c5..707b02e 100644 --- a/src/tracefile/writer/MCAPTraceFileWriter.cpp +++ b/src/tracefile/writer/MCAPTraceFileWriter.cpp @@ -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(); diff --git a/src/tracefile/writer/NativeBinaryTraceFileWriter.cpp b/src/tracefile/writer/NativeBinaryTraceFileWriter.cpp index afbbd4b..cdbce5d 100644 --- a/src/tracefile/writer/NativeBinaryTraceFileWriter.cpp +++ b/src/tracefile/writer/NativeBinaryTraceFileWriter.cpp @@ -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; diff --git a/src/tracefile/writer/TXTHTraceFileWriter.cpp b/src/tracefile/writer/TXTHTraceFileWriter.cpp index 35a3170..e4913b5 100644 --- a/src/tracefile/writer/TXTHTraceFileWriter.cpp +++ b/src/tracefile/writer/TXTHTraceFileWriter.cpp @@ -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;