diff Core/Toolbox.cpp @ 453:30086c1aca30

endianness
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jul 2013 14:29:44 +0200
parents d2c69150a979
children c9a5d72f8481
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Thu Jul 04 11:48:02 2013 +0200
+++ b/Core/Toolbox.cpp	Thu Jul 04 14:29:44 2013 +0200
@@ -34,6 +34,7 @@
 
 #include "OrthancException.h"
 
+#include <stdint.h>
 #include <string.h>
 #include <boost/filesystem.hpp>
 #include <boost/filesystem/fstream.hpp>
@@ -671,4 +672,29 @@
 
     s.resize(target);
   }
+
+
+  Endianness Toolbox::DetectEndianness()
+  {
+    // http://sourceforge.net/p/predef/wiki/Endianness/
+
+    uint8_t buffer[4];
+
+    buffer[0] = 0x00;
+    buffer[1] = 0x01;
+    buffer[2] = 0x02;
+    buffer[3] = 0x03;
+
+    switch (*((uint32_t *)buffer)) 
+    {
+      case 0x00010203: 
+        return Endianness_Big;
+
+      case 0x03020100: 
+        return Endianness_Little;
+        
+      default:
+        throw OrthancException(ErrorCode_NotImplemented);
+    }
+  }
 }