activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r494845 - /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h
Date Wed, 10 Jan 2007 15:17:28 GMT
Author: tabish
Date: Wed Jan 10 07:17:27 2007
New Revision: 494845

URL: http://svn.apache.org/viewvc?view=rev&rev=494845
Log:
http://issues.apache.org/activemq/browse/AMQCPP-25

Better Swap Methods, remove all the Macros and used the Autoconf define for WORDS_BEGENDIAN

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h?view=diff&rev=494845&r1=494844&r2=494845
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h Wed
Jan 10 07:17:27 2007
@@ -17,90 +17,6 @@
 #ifndef ACTIVEMQ_UTIL_ENDIAN_H
 #define ACTIVEMQ_UTIL_ENDIAN_H
 
-#if defined( unix ) || defined(__APPLE__)
-#include <netinet/in.h>
-#else
-#include <Winsock2.h>
-#endif
-
-// First try - check __BYTE_ORDER macro
-#if !defined IFR_IS_BIG_ENDIAN && !defined IFR_IS_LITTLE_ENDIAN && !defined
IFR_IS_DPD_ENDIAN
-# if defined( unix ) || defined(__APPLE__)
-#  include <sys/param.h> // defines __BYTE_ORDER (or sometimes __LITTLE_ENDIAN or __BIG_ENDIAN
or __PDP_ENDIAN)
-# endif
-# if defined (__GLIBC__)
-#  include <endian.h> // Can also define __BYTE_ORDER
-# endif
-# ifdef __BYTE_ORDER
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
-#   define IFR_IS_LITTLE_ENDIAN
-#  elif __BYTE_ORDER == __BIG_ENDIAN
-#   define IFR_IS_BIG_ENDIAN
-#  elif __BYTE_ORDER == __PDP_ENDIAN
-#   define IFR_IS_PDP_ENDIAN
-#  endif
-# endif
-#endif
-
-// Second try - check __LITTLE_ENDIAN or __BIG_ENDIAN
-#if !defined IFR_IS_BIG_ENDIAN && !defined IFR_IS_LITTLE_ENDIAN && !defined
IFR_IS_DPD_ENDIAN
-# if defined __LITTLE_ENDIAN
-#  define IFR_IS_LITTLE_ENDIAN
-# elif defined __BIG_ENDIAN
-#  define IFR_IS_BIG_ENDIAN
-# elif defined __PDP_ENDIAN
-#  define IFR_IS_PDP_ENDIAN
-# endif
-#endif
-
-// Last try - find out from well-known processor types using little endian
-#if !defined IFR_IS_BIG_ENDIAN && !defined IFR_IS_LITTLE_ENDIAN && !defined
IFR_IS_DPD_ENDIAN
-# if defined (i386) || defined (__i386__) \
-  || defined (_M_IX86) || defined (vax) \
-  || defined (__alpha) || defined (__alpha__) \
-  || defined (__x86_64__) || defined (__ia64) \
-  || defined (__ia64__) || defined (__amd64__) \
-  || defined (_M_IX86) || defined (_M_IA64) \
-  || defined (_M_ALPHA)
-#  define IFR_IS_LITTLE_ENDIAN
-# else
-#  if defined (__sparc) || defined(__sparc__) \
-  || defined(_POWER) || defined(__powerpc__) \
-  || defined(__ppc__) || defined(__hppa) \
-  || defined(_MIPSEB) || defined(_POWER) \
-  || defined(__s390__)
-#   define IFR_IS_BIG_ENDIAN
-#  endif
-# endif
-#endif
-
-// Show error if we still don't know endianess
-#if !defined IFR_IS_BIG_ENDIAN && !defined IFR_IS_LITTLE_ENDIAN && !defined
IFR_IS_DPD_ENDIAN
-#error "Could not determine endianess of your processor type"
-#endif
-
-// Use these if the compiler does not support _intXX
-#ifdef NEEDS_INT_DEFINED
-#define _int16 short
-#define _int32 int
-#define _int64 long long
-#endif
-
-// Check for uintXX types
-#ifndef uint8_t
-#define uint8_t unsigned char
-#endif
-#ifndef uint16_t
-#define uint16_t unsigned short
-#endif
-#ifndef uint32_t
-#define uint32_t unsigned int
-#endif
-#ifndef uint64_t
-#define uint64_t unsigned long long
-#endif
-
-// Macros and helpers for endian conversion
 namespace activemq{
 namespace util{
     
@@ -109,7 +25,7 @@
     
         static void byteSwap(unsigned char* data, int dataLength) {
             
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return;
             #endif
             
@@ -120,18 +36,18 @@
             }
         }
         
-        static uint8_t byteSwap( uint8_t value ){
+        static unsigned char byteSwap( unsigned char value ){
             
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
             return value;            
         }
         
-        static uint16_t byteSwap( uint16_t value ){
+        static unsigned short byteSwap( unsigned short value ){
 
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
@@ -139,9 +55,9 @@
                    (((unsigned short)value & 0x00FF ) << 8 );
         }
         
-        static uint32_t byteSwap( uint32_t value ){
+        static unsigned int byteSwap( unsigned int value ){
 
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
@@ -151,9 +67,9 @@
                    (((unsigned int)value & 0x000000FF ) << 24 );
         }
         
-        static uint64_t byteSwap( uint64_t value ){
+        static unsigned long long byteSwap( unsigned long long value ){
 
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
@@ -169,20 +85,24 @@
         
         static float byteSwap( float value ){
 
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
-            return (float)( byteSwap( (unsigned int)value ) );
+            unsigned int lvalue = *((unsigned int*)&value);
+            lvalue = byteSwap( lvalue );
+            return *((float*)&lvalue);
         }
         
         static double byteSwap( double value ){
 
-            #ifdef IFR_IS_BIGENDIAN
+            #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
-            
-            return (double)( byteSwap( (unsigned long long)value ) );
+
+            unsigned long long lvalue = *((unsigned long long*)&value);
+            lvalue = byteSwap( lvalue );
+            return *((double*)&lvalue);
         }
     };
     



Mime
View raw message