# HG changeset patch # User Benjamin Golinvaux # Date 1565437208 -7200 # Node ID e7723a39adf8da720a81ad5b8932ed2a0c0c01d3 # Parent ce29644acd190b52af3438e5e9d7089c590fb818 Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger use an std::stringstream so that manipulators like "std::hex" are supported (when using ORTHANC_ENABLE_LOGGING_PLUGIN or ORTHANC_ENABLE_LOGGING_STDIO) diff -r ce29644acd19 -r e7723a39adf8 Core/Logging.cpp --- a/Core/Logging.cpp Mon Aug 05 13:57:54 2019 +0200 +++ b/Core/Logging.cpp Sat Aug 10 13:40:08 2019 +0200 @@ -92,6 +92,7 @@ *********************************************************/ #include +#include namespace Orthanc { @@ -113,20 +114,21 @@ InternalLogger::~InternalLogger() { + std::string message = messageStream_.str(); if (context_ != NULL) { switch (level_) { case InternalLevel_ERROR: - OrthancPluginLogError(context_, message_.c_str()); + OrthancPluginLogError(context_, message.c_str()); break; case InternalLevel_WARNING: - OrthancPluginLogWarning(context_, message_.c_str()); + OrthancPluginLogWarning(context_, message.c_str()); break; case InternalLevel_INFO: - OrthancPluginLogInfo(context_, message_.c_str()); + OrthancPluginLogInfo(context_, message.c_str()); break; case InternalLevel_TRACE: @@ -136,7 +138,7 @@ default: { std::string s = ("Unknown log level (" + boost::lexical_cast(level_) + - ") for message: " + message_); + ") for message: " + message); OrthancPluginLogError(context_, s.c_str()); break; } @@ -239,20 +241,22 @@ InternalLogger::~InternalLogger() { + std::string message = messageStream_.str(); + switch (level_) { case InternalLevel_ERROR: - globalErrorLogFunc(message_.c_str()); + globalErrorLogFunc(message.c_str()); break; case InternalLevel_WARNING: - globalWarningLogFunc(message_.c_str()); + globalWarningLogFunc(message.c_str()); break; case InternalLevel_INFO: if (globalVerbose_) { - globalInfoLogFunc(message_.c_str()); + globalInfoLogFunc(message.c_str()); // TODO: stone_console_info(message_.c_str()); } break; @@ -260,14 +264,14 @@ case InternalLevel_TRACE: if (globalTrace_) { - globalTraceLogFunc(message_.c_str()); + globalTraceLogFunc(message.c_str()); } break; default: { std::stringstream ss; - ss << "Unknown log level (" << level_ << ") for message: " << message_; + ss << "Unknown log level (" << level_ << ") for message: " << message; auto s = ss.str(); globalErrorLogFunc(s.c_str()); } diff -r ce29644acd19 -r e7723a39adf8 Core/Logging.h --- a/Core/Logging.h Mon Aug 05 13:57:54 2019 +0200 +++ b/Core/Logging.h Sat Aug 10 13:40:08 2019 +0200 @@ -143,8 +143,8 @@ class InternalLogger : public boost::noncopyable { private: - InternalLevel level_; - std::string message_; + InternalLevel level_; + std::stringstream messageStream_; public: InternalLogger(InternalLevel level, @@ -156,7 +156,7 @@ template InternalLogger& operator<< (const T& message) { - message_ += boost::lexical_cast(message); + messageStream_ << message; return *this; } }; diff -r ce29644acd19 -r e7723a39adf8 Core/Toolbox.cpp --- a/Core/Toolbox.cpp Mon Aug 05 13:57:54 2019 +0200 +++ b/Core/Toolbox.cpp Sat Aug 10 13:40:08 2019 +0200 @@ -923,14 +923,16 @@ { // http://sourceforge.net/p/predef/wiki/Endianness/ - uint8_t buffer[4]; + uint32_t bufferView; + + uint8_t* buffer = reinterpret_cast(&bufferView); buffer[0] = 0x00; buffer[1] = 0x01; buffer[2] = 0x02; buffer[3] = 0x03; - switch (*((uint32_t *)buffer)) + switch (bufferView) { case 0x00010203: return Endianness_Big; @@ -943,7 +945,6 @@ } } - std::string Toolbox::WildcardToRegularExpression(const std::string& source) { // TODO - Speed up this with a regular expression