You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/01/11 20:04:56 UTC

svn commit: r495335 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq: io/DataInputStream.cpp io/DataOutputStream.cpp util/Endian.h

Author: tabish
Date: Thu Jan 11 11:04:55 2007
New Revision: 495335

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

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

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp?view=diff&rev=495335&r1=495334&r2=495335
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp Thu Jan 11 11:04:55 2007
@@ -141,13 +141,6 @@
         value |= (byte1 << 8 | byte2 << 0);
         
         return value;
-
-        //char* temp = (char*)&value;
-        //
-        //return (short)Endian::byteSwap( value );
-
-        //this->readFully( ( unsigned char* )&value, 0, sizeof( unsigned short ) );
-        //return Endian::byteSwap( value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -166,10 +159,6 @@
         value |= (byte1 << 8 | byte2 << 0);
         
         return value;
-
-//        unsigned short value;
-//        this->readFully( ( unsigned char* )&value, 0, sizeof( unsigned short ) );
-//        return Endian::byteSwap( value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -189,10 +178,6 @@
         value |= (byte1 << 24 | byte2 << 16 | byte3 << 8 | byte4 << 0);
         
         return value;
-
-//        unsigned int value;    
-//        this->readFully( ( unsigned char* )&value, 0, sizeof( unsigned int ) );
-//        return (int)Endian::byteSwap( value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -202,13 +187,10 @@
 double DataInputStream::readDouble() throw ( io::IOException, io::EOFException ) {
     try {
 
-        unsigned long long value = this->readLong();
-        
-        return *((double*)&value);
-
-//        double value;
-//        this->readFully( ( unsigned char* )&value, 0, sizeof( double ) );
-//        return Endian::byteSwap( value );
+        unsigned long long lvalue = this->readLong();
+        double value = 0.0;
+        memcpy( &value, &lvalue, sizeof( unsigned long long ) );        
+        return value;
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -218,20 +200,10 @@
 float DataInputStream::readFloat() throw ( io::IOException, io::EOFException ) {
     try {
 
-        unsigned int value = 0;
-
-        unsigned char byte1 = this->readByte();
-        unsigned char byte2 = this->readByte();
-        unsigned char byte3 = this->readByte();
-        unsigned char byte4 = this->readByte();
-
-        value |= (byte1 << 24 | byte2 << 16 | byte3 << 8 | byte4 << 0);
-
-        return *((float*)&value);
-
-//        float value;
-//        this->readFully( ( unsigned char* )&value, 0, sizeof( float ) );
-//        return Endian::byteSwap( value );
+        unsigned int lvalue = this->readInt();
+        float value = 0.0f;
+        memcpy( &value, &lvalue, sizeof( unsigned int ) );
+        return value;
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -257,10 +229,6 @@
                   byte5 << 24 | byte6 << 16 | byte7 << 8  | byte8 << 0 );
 
         return value;
-
-//        unsigned long long value;
-//        this->readFully( ( unsigned char* )&value, 0, sizeof( unsigned long long ) );
-//        return (long long)Endian::byteSwap( value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -309,7 +277,7 @@
 void DataInputStream::readFully( std::vector< unsigned char >& buffer ) 
     throw ( io::IOException, io::EOFException ) {
     try {
-        readFully( &buffer[0], 0, buffer.size() );
+        this->readFully( &buffer[0], 0, buffer.size() );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp?view=diff&rev=495335&r1=495334&r2=495335
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp Thu Jan 11 11:04:55 2007
@@ -90,7 +90,7 @@
         unsigned char ivalue = 0;
         value == true ? ivalue = 1 : ivalue = 0;
 
-        write( ivalue );
+        this->write( ivalue );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -99,7 +99,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeByte( unsigned char value ) throw ( IOException ) {
     try {
-        write( value );
+        this->write( value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -108,7 +108,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeShort( short value ) throw ( IOException ) {
     try {
-        writeUnsignedShort( (unsigned short)value );
+        this->writeUnsignedShort( (unsigned short)value );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -136,10 +136,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeInt( int value ) throw ( IOException ) {
     try {
-        write( (unsigned char)( (value & 0xFF000000) >> 24 ) );
-        write( (unsigned char)( (value & 0x00FF0000) >> 16 ) );
-        write( (unsigned char)( (value & 0x0000FF00) >> 8 ) );
-        write( (unsigned char)( (value & 0x000000FF) >> 0 ) );
+        this->write( (unsigned char)( (value & 0xFF000000) >> 24 ) );
+        this->write( (unsigned char)( (value & 0x00FF0000) >> 16 ) );
+        this->write( (unsigned char)( (value & 0x0000FF00) >> 8 ) );
+        this->write( (unsigned char)( (value & 0x000000FF) >> 0 ) );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -148,14 +148,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeLong( long long value ) throw ( IOException ) {
     try {
-        write( (unsigned char)( (value & 0xFF00000000000000ULL) >> 56 ) );
-        write( (unsigned char)( (value & 0x00FF000000000000ULL) >> 48 ) );
-        write( (unsigned char)( (value & 0x0000FF0000000000ULL) >> 40 ) );
-        write( (unsigned char)( (value & 0x000000FF00000000ULL) >> 32 ) );
-        write( (unsigned char)( (value & 0x00000000FF000000ULL) >> 24 ) );
-        write( (unsigned char)( (value & 0x0000000000FF0000ULL) >> 16 ) );
-        write( (unsigned char)( (value & 0x000000000000FF00ULL) >> 8 ) );
-        write( (unsigned char)( (value & 0x00000000000000FFULL) >> 0 ) );
+        this->write( (unsigned char)( (value & 0xFF00000000000000ULL) >> 56 ) );
+        this->write( (unsigned char)( (value & 0x00FF000000000000ULL) >> 48 ) );
+        this->write( (unsigned char)( (value & 0x0000FF0000000000ULL) >> 40 ) );
+        this->write( (unsigned char)( (value & 0x000000FF00000000ULL) >> 32 ) );
+        this->write( (unsigned char)( (value & 0x00000000FF000000ULL) >> 24 ) );
+        this->write( (unsigned char)( (value & 0x0000000000FF0000ULL) >> 16 ) );
+        this->write( (unsigned char)( (value & 0x000000000000FF00ULL) >> 8 ) );
+        this->write( (unsigned char)( (value & 0x00000000000000FFULL) >> 0 ) );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -164,7 +164,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeFloat( float value ) throw ( IOException ) {
     try {
-        this->writeInt( *((unsigned int*)&value) );
+        unsigned int lvalue = 0;
+        memcpy( &lvalue, &value, sizeof( float ) );
+        this->writeInt( lvalue );
+        memcpy( &value, &lvalue, sizeof( unsigned int ) );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
@@ -173,7 +176,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 void DataOutputStream::writeDouble( double value ) throw ( IOException ) {
     try {
-        writeLong( *((unsigned long long*)&value) );
+        unsigned long long lvalue = 0;
+        memcpy( &lvalue, &value, sizeof( double ) );
+        this->writeLong( lvalue );
+        memcpy( &value, &lvalue, sizeof( unsigned long long ) );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )

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=495335&r1=495334&r2=495335
==============================================================================
--- 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 Thu Jan 11 11:04:55 2007
@@ -17,6 +17,8 @@
 #ifndef ACTIVEMQ_UTIL_ENDIAN_H
 #define ACTIVEMQ_UTIL_ENDIAN_H
 
+#include <activemq/util/Config.h>
+
 namespace activemq{
 namespace util{
     
@@ -82,16 +84,18 @@
                    (((unsigned long long)value & 0x000000000000FF00ULL ) << 40 ) |
                    (((unsigned long long)value & 0x00000000000000FFULL ) << 56 );
         }
-        
+
         static float byteSwap( float value ){
 
             #ifdef WORDS_BIGENDIAN
                 return value;
             #endif
 
-            unsigned int lvalue = *((unsigned int*)&value);
+            unsigned int lvalue = 0;
+            memcpy( &lvalue, &value, sizeof( float ) );
             lvalue = byteSwap( lvalue );
-            return *((float*)&lvalue);
+            memcpy( &value, &lvalue, sizeof( unsigned int ) );
+            return value;
         }
         
         static double byteSwap( double value ){
@@ -100,9 +104,11 @@
                 return value;
             #endif
 
-            unsigned long long lvalue = *((unsigned long long*)&value);
+            unsigned long long lvalue = 0;
+            memcpy( &lvalue, &value, sizeof( double ) );
             lvalue = byteSwap( lvalue );
-            return *((double*)&lvalue);
+            memcpy( &value, &lvalue, sizeof( unsigned long long ) );
+            return value;
         }
     };