changeset 3490:786fce009be8

Merge
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:42:38 +0200
parents e7723a39adf8 (diff) 48231cfd2693 (current diff)
children 22bdb9c91ebf cfaa9eded17e
files
diffstat 3 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Logging.cpp	Fri Aug 09 09:19:51 2019 +0200
+++ b/Core/Logging.cpp	Sat Aug 10 13:42:38 2019 +0200
@@ -92,6 +92,7 @@
  *********************************************************/
 
 #include <boost/lexical_cast.hpp>
+#include <sstream>
 
 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<std::string>(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());
         }
--- a/Core/Logging.h	Fri Aug 09 09:19:51 2019 +0200
+++ b/Core/Logging.h	Sat Aug 10 13:42:38 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 <typename T>
       InternalLogger& operator<< (const T& message)
       {
-        message_ += boost::lexical_cast<std::string>(message);
+        messageStream_ << message;
         return *this;
       }
     };
--- a/Core/Toolbox.cpp	Fri Aug 09 09:19:51 2019 +0200
+++ b/Core/Toolbox.cpp	Sat Aug 10 13:42:38 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<uint8_t*>(&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