From a4746eab0c84cf2b0091080fcb351a1ec33391cf Mon Sep 17 00:00:00 2001 From: yein Date: Fri, 3 Oct 2025 12:53:46 -0700 Subject: [PATCH] Minor changes in utils::Status (#9288) * Minor changes in utils::Status - << operator doesn't have to be friend - simplify getErrorMessage to not use strlen internally * Replace std::ostream to utils::io::ostream --- libs/utils/include/utils/Status.h | 8 +++++--- libs/utils/src/Status.cpp | 10 ++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/utils/include/utils/Status.h b/libs/utils/include/utils/Status.h index 5b462e5ad8..c2c494c60c 100644 --- a/libs/utils/include/utils/Status.h +++ b/libs/utils/include/utils/Status.h @@ -95,7 +95,9 @@ public: * Returns the error message for this Status. * @return The error message string. Will be empty if the status is OK. */ - std::string_view getErrorMessage() const; + std::string_view getErrorMessage() const { + return std::string_view(mErrorMessage.begin(), mErrorMessage.end()); + } /** * Convenient factory functions for creating Status objects. @@ -128,14 +130,14 @@ public: return {StatusCode::INVALID_ARGUMENT, message}; } - friend std::ostream& operator<<(std::ostream& os, const Status& status); - private: StatusCode mStatusCode; // Reason for the error if exists. utils::CString mErrorMessage; }; +utils::io::ostream& operator<<(utils::io::ostream& os, const Status& status); + } // namespace utils #endif // TNT_UTILS_STATUS_H diff --git a/libs/utils/src/Status.cpp b/libs/utils/src/Status.cpp index db35db996e..a6a9f21016 100644 --- a/libs/utils/src/Status.cpp +++ b/libs/utils/src/Status.cpp @@ -15,13 +15,11 @@ */ #include -namespace utils { -std::string_view Status::getErrorMessage() const { - const char* ptr = mErrorMessage.c_str(); - return (ptr != nullptr) ? ptr : ""; -} +#include -std::ostream& operator<<(std::ostream& os, const Status& status) { +namespace utils { + +utils::io::ostream& operator<<(utils::io::ostream& os, const Status& status) { os << "Status: "; switch (status.getCode()) { case StatusCode::OK: os << "Ok";