Skip to content

Commit f51689c

Browse files
authored
fix compiler issues with C++17 (#5)
* fix compiler issues with C++17 * fix issues with LogMsg * next issue * maybe this will work
1 parent e4060a9 commit f51689c

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/mnxvalidate.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ std::string getTimeStamp(const std::string& fmt)
8585
#ifdef _WIN32
8686
localtime_s(&localTime, &time_t_now); // Windows
8787
#else
88-
localtime_r(&time_t_now, &localTime); // Linux/Unix
88+
std::tm* tmPtr = localtime(&time_t_now); // POSIX: localtime is thread-safe per thread
89+
if (tmPtr) {
90+
localTime = *tmPtr;
91+
} else {
92+
return {}; // Handle failure gracefully
93+
}
8994
#endif
9095
std::ostringstream timestamp;
9196
timestamp << std::put_time(&localTime, fmt.c_str());

src/mnxvalidate.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,32 @@ using arg_string = std::string;
7575
#endif
7676

7777
using Buffer = std::vector<char>;
78-
using LogMsg = std::stringstream;
7978
using json = nlohmann::json;
8079

80+
/// @class LogMsg
81+
/// @brief Stringstream class that allows rvalues to be streamed to logMessage
82+
class LogMsg {
83+
private:
84+
std::stringstream stream;
85+
86+
public:
87+
LogMsg() = default;
88+
LogMsg(const LogMsg& other) : stream(other.stream.str()) {} // Copy constructor
89+
LogMsg(LogMsg&& other) noexcept : stream(std::move(other.stream)) {} // Move constructor
90+
91+
// Allow retrieval of the internal stream content
92+
std::string str() const { return stream.str(); }
93+
94+
void flush() { stream.flush(); }
95+
96+
// Override operator<< to ensure LogMsg&& is always returned
97+
template <typename T>
98+
LogMsg&& operator<<(const T& value) {
99+
stream << value;
100+
return std::move(*this);
101+
}
102+
};
103+
81104
/// @brief defines log message severity
82105
enum class LogSeverity
83106
{

tests/mnxvalidatetests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void checkStderr(const std::vector<std::string>& expectedMessages, std::function
6666
<< "Message \"" << expectedMessage << "\" not found. Actual: " << capturedErrors;
6767
}
6868
}
69-
};
69+
}
7070

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

0 commit comments

Comments
 (0)