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/07/31 00:33:34 UTC

svn commit: r561164 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Integer.cpp Integer.h

Author: tabish
Date: Mon Jul 30 15:33:30 2007
New Revision: 561164

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

Adding in more Types wrappers

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp?view=diff&rev=561164&r1=561163&r2=561164
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp Mon Jul 30 15:33:30 2007
@@ -57,12 +57,78 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toString( int value )
-{
-    //TODO
-    std::ostringstream ostream;
-    ostream << value;
-    return ostream.str();
+int Integer::reverseBytes( int value ) {
+    int b3 = value >> 24;
+    int b2 = (value >> 8) & 0xFF00;
+    int b1 = (value & 0xFF00) << 8;
+    int b0 = value << 24;
+    return (b0 | b1 | b2 | b3);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::reverse( int value ) {
+    value = (((value & 0xAAAAAAAA) >> 1) | ((value & 0x55555555) << 1));
+    value = (((value & 0xCCCCCCCC) >> 2) | ((value & 0x33333333) << 2));
+    value = (((value & 0xF0F0F0F0) >> 4) | ((value & 0x0F0F0F0F) << 4));
+    value = (((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8));
+    return ((value >> 16) | (value << 16));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Integer::toString() const {
+    return Integer::toString( this->value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Integer::toString( int value ) {
+    return Integer::toString( value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Integer::toString( int value, int radix ) {
+
+    std::string result = "";
+
+    if( radix < Character::MIN_RADIX || radix > Character::MAX_RADIX ) {
+        radix = 10;
+    }
+
+    if( value == 0 ) {
+        return "0";
+    }
+
+    int count = 2, j = value;
+    bool negative = value < 0;
+    if( !negative ) {
+        count = 1;
+        j = -value;
+    }
+
+    while( (value /= radix) != 0 ) {
+        count++;
+    }
+
+    char* buffer = new char[count];
+    const int length = count;
+
+    do {
+        int ch = 0 - ( j % radix );
+        if( ch > 9 ) {
+            ch = ch - 10 + 'a';
+        } else {
+            ch += '0';
+        }
+        buffer[--count] = (char)ch;
+    } while( (j /= radix) != 0 );
+
+    if( negative ) {
+        buffer[0] = '-';
+    }
+
+    result.append( &buffer[0], length );
+    delete buffer;
+
+    return result;
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h?view=diff&rev=561164&r1=561163&r2=561164
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h Mon Jul 30 15:33:30 2007
@@ -159,6 +159,14 @@
         static int reverseBytes( int value );
 
         /**
+         * Returns the value obtained by reversing the order of the bits in the
+         * two's complement binary representation of the specified int  value.
+         * @param value - the value whose bits are to be reversed
+         * @returns the reversed bits int.
+         */
+        static int reverse( int value );
+
+        /**
          * Parses the string argument as a signed int in the radix specified by
          * the second argument. The characters in the string must all be digits,
          * of the specified radix (as determined by whether