Skip to content

Commit

Permalink
fix compiler issues with C++17 (#5)
Browse files Browse the repository at this point in the history
* fix compiler issues with C++17

* fix issues with LogMsg

* next issue

* maybe this will work
  • Loading branch information
rpatters1 authored Feb 5, 2025
1 parent e4060a9 commit f51689c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/mnxvalidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ std::string getTimeStamp(const std::string& fmt)
#ifdef _WIN32
localtime_s(&localTime, &time_t_now); // Windows
#else
localtime_r(&time_t_now, &localTime); // Linux/Unix
std::tm* tmPtr = localtime(&time_t_now); // POSIX: localtime is thread-safe per thread
if (tmPtr) {
localTime = *tmPtr;
} else {
return {}; // Handle failure gracefully
}
#endif
std::ostringstream timestamp;
timestamp << std::put_time(&localTime, fmt.c_str());
Expand Down
25 changes: 24 additions & 1 deletion src/mnxvalidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,32 @@ using arg_string = std::string;
#endif

using Buffer = std::vector<char>;
using LogMsg = std::stringstream;
using json = nlohmann::json;

/// @class LogMsg
/// @brief Stringstream class that allows rvalues to be streamed to logMessage
class LogMsg {
private:
std::stringstream stream;

public:
LogMsg() = default;
LogMsg(const LogMsg& other) : stream(other.stream.str()) {} // Copy constructor
LogMsg(LogMsg&& other) noexcept : stream(std::move(other.stream)) {} // Move constructor

// Allow retrieval of the internal stream content
std::string str() const { return stream.str(); }

void flush() { stream.flush(); }

// Override operator<< to ensure LogMsg&& is always returned
template <typename T>
LogMsg&& operator<<(const T& value) {
stream << value;
return std::move(*this);
}
};

/// @brief defines log message severity
enum class LogSeverity
{
Expand Down
2 changes: 1 addition & 1 deletion tests/mnxvalidatetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void checkStderr(const std::vector<std::string>& expectedMessages, std::function
<< "Message \"" << expectedMessage << "\" not found. Actual: " << capturedErrors;
}
}
};
}

void checkStdout(const std::vector<std::string>& expectedMessages, std::function<void()> callback)
{
Expand Down

0 comments on commit f51689c

Please sign in to comment.