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/08/03 15:26:09 UTC

svn commit: r562458 - in /activemq/activemq-cpp/trunk/src/decaf/src: main/decaf/lang/Integer.h main/decaf/lang/Long.cpp main/decaf/lang/Long.h test/decaf/lang/LongTest.cpp test/decaf/lang/LongTest.h

Author: tabish
Date: Fri Aug  3 06:26:08 2007
New Revision: 562458

URL: http://svn.apache.org/viewvc?view=rev&rev=562458
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.h
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.h

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=562458&r1=562457&r2=562458
==============================================================================
--- 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 Fri Aug  3 06:26:08 2007
@@ -468,7 +468,9 @@
          * is negative: rotateLeft(val, distance) == rotateLeft(val, distance & 0x1F).
          * @param value - the int to be inspected
          * @param distance - the number of bits to rotate
-         * @return
+         * @return the value obtained by rotating the two's complement binary
+         * representation of the specified int value left by the specified number
+         * of bits.
          */
         static int rotateLeft( int value, int distance );
 

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.cpp?view=diff&rev=562458&r1=562457&r2=562458
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.cpp Fri Aug  3 06:26:08 2007
@@ -16,25 +16,478 @@
  */
 
 #include "Long.h"
+#include <decaf/lang/Character.h>
 #include <sstream>
 
 using namespace decaf;
 using namespace decaf::lang;
 
 ////////////////////////////////////////////////////////////////////////////////
+Long::Long( long long value ) {
+    this->value = value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Long::Long( const std::string& value ) {
+    this->value = parseLong( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::compareTo( const Long& l ) const {
+    return this->value < l.value ? -1 : this->value == l.value ? 0 : 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::compareTo( const long long& l ) const {
+    return this->value < l ? -1 : this->value == l ? 0 : 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::bitCount( long long value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+
+    uvalue = (uvalue & 0x5555555555555555LL) + ((uvalue >> 1) & 0x5555555555555555LL);
+    uvalue = (uvalue & 0x3333333333333333LL) + ((uvalue >> 2) & 0x3333333333333333LL);
+    // adjust for 64-bit integer
+    unsigned int i = (unsigned int)( (uvalue >> 32) + uvalue );
+    i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F);
+    i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF);
+    i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF);
+    return i;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Long Long::decode( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    int length = value.length(), i = 0;
+    if( length == 0 ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Long::decode - Zero length string given." );
+    }
+
+    char firstDigit = value[i];
+    bool negative = firstDigit == '-';
+    if( negative ) {
+        if( length == 1 ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::decode - Invalid length string given.",
+                value.c_str() );
+        }
+        firstDigit = value[++i];
+    }
+
+    int base = 10;
+    if( firstDigit == '0' ) {
+        if( ++i == length ) {
+            return valueOf( 0LL );
+        }
+        if( ( firstDigit = value[i] ) == 'x' || firstDigit == 'X' ) {
+            if ( i == length ) {
+                throw exceptions::NumberFormatException(
+                    __FILE__, __LINE__,
+                    "Long::decode - Invalid length string given.",
+                    value.c_str() );
+            }
+            i++;
+            base = 16;
+        } else {
+            base = 8;
+        }
+    } else if( firstDigit == '#' ) {
+        if( i == length ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::decode - Invalid length string given.",
+                value.c_str() );
+        }
+        i++;
+        base = 16;
+    }
+
+    long long result = parse( value, i, base, negative );
+    return valueOf( result );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::highestOneBit( long long value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+
+    uvalue |= (uvalue >> 1);
+    uvalue |= (uvalue >> 2);
+    uvalue |= (uvalue >> 4);
+    uvalue |= (uvalue >> 8);
+    uvalue |= (uvalue >> 16);
+    uvalue |= (uvalue >> 32);
+    return ( uvalue & ~( uvalue >> 1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::lowestOneBit( long long value ) {
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+    return ( uvalue & (-uvalue) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::numberOfLeadingZeros( long long value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+
+    value |= value >> 1;
+    value |= value >> 2;
+    value |= value >> 4;
+    value |= value >> 8;
+    value |= value >> 16;
+    value |= value >> 32;
+    return Long::bitCount( ~uvalue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::numberOfTrailingZeros( long long value ) {
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+    return Long::bitCount( (uvalue & -uvalue) - 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 long long Long::parseLong( const std::string& value )
-{
-    long long ret = 0;
-    std::istringstream istream(value);
-    istream.clear();
-    istream >> ret;
-    return ret;
+    throw ( exceptions::NumberFormatException ) {
+
+    return Long::parseLong( value, 10 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Long::toString( long long value )
-{
-    std::ostringstream ostream;
-    ostream << value;
-    return ostream.str();
+long long Long::parseLong( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    if( radix < Character::MIN_RADIX ||
+        radix > Character::MAX_RADIX ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Long::parseLong - Given Radix is out of range." );
+    }
+
+    int length = value.length();
+    int i = 0;
+
+    if( length == 0 ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Long::parseLong - Zero length string is illegal." );
+    }
+
+    bool negative = value[i] == '-';
+    if( negative && ++i == length ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Long::parseLong - Only a minus given, string is invalid." );
+    }
+
+    return Long::parse( value, i, radix, negative );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::parse( const std::string& value, int offset,
+                       int radix, bool negative )
+    throw ( exceptions::NumberFormatException ) {
+
+    long long max = Long::MIN_VALUE / radix;
+    long long result = 0;
+    long long length = value.length();
+
+    while( offset < length ) {
+        int digit = Character::digit( value[offset++], radix );
+
+        if( digit == -1 ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::parseLong - String contains no digit characters." );
+        }
+
+        if( max > result ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::parseLong - Parsed value greater than max for radix." );
+        }
+
+        long long next = result * radix - digit;
+
+        if( next > result ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::parseLong - Only a minus given, string is invalid." );
+        }
+
+        result = next;
+    }
+
+    if( !negative ) {
+        result = -result;
+        if( result < 0 ) {
+            throw exceptions::NumberFormatException(
+                __FILE__, __LINE__,
+                "Long::parseLong - Value less than zero, but no minus sign." );
+        }
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::reverseBytes( long long value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+
+    long long b7 = (uvalue >> 56);
+    long long b6 = (uvalue >> 40) & 0xFF00ULL;
+    long long b5 = (uvalue >> 24) & 0xFF0000ULL;
+    long long b4 = (uvalue >> 8) & 0xFF000000ULL;
+    long long b3 = (uvalue & 0xFF000000ULL) << 8;
+    long long b2 = (uvalue & 0xFF0000ULL) << 24;
+    long long b1 = (uvalue & 0xFF00ULL) << 40;
+    long long b0 = (uvalue << 56);
+    return ( b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::reverse( long long value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned long long uvalue = (unsigned long long)value;
+
+    // From Hacker's Delight, 7-1, Figure 7-1
+    uvalue = ( uvalue & 0x5555555555555555ULL ) << 1 | (uvalue >> 1) &
+             0x5555555555555555ULL;
+    uvalue = ( uvalue & 0x3333333333333333ULL ) << 2 | (uvalue >> 2) &
+             0x3333333333333333ULL;
+    uvalue = ( uvalue & 0x0F0F0F0F0F0F0F0FULL ) << 4 | (uvalue >> 4) &
+             0x0F0F0F0F0F0F0F0FULL;
+
+    return reverseBytes( uvalue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::rotateLeft( long long value, int distance ) {
+    unsigned long long i = (unsigned long long)value;
+    int j = distance & 0x1F;
+    return ( i << j ) | ( i >> (-j & 0x1F ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Long::rotateRight( long long value, int distance ) {
+    unsigned long long i = (unsigned long long)value;
+    int j = distance & 0x1F;
+    return ( i >> j ) | ( i << (-j & 0x1F ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Long::signum( long long value ) {
+    return ( value == 0 ? 0 : ( value < 0 ? -1 : 1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toString() const {
+    return Long::toString( this->value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toString( long long value ) {
+    return Long::toString( value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toString( long long value, int radix ) {
+
+    if( radix < Character::MIN_RADIX || radix > Character::MAX_RADIX ) {
+        radix = 10;
+    }
+
+    if( value == 0 ) {
+        return "0";
+    }
+
+    int count = 2;
+    long long j = value;
+    bool negative = value < 0;
+
+    if( !negative ) {
+        count = 1;
+        j = -value;
+    }
+
+    while( (value /= radix) != 0 ) {
+        count++;
+    }
+
+    // Save length and allocate a new buffer for the string, add one
+    // more for the null character.
+    int length = count;
+    char* buffer = new char[length + 1];
+
+    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] = '-';
+    }
+
+    // Ensure there's a null
+    buffer[length] = 0;
+    std::string result( &buffer[0] );
+    delete [] buffer;
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toBinaryString( long long value ) {
+
+    int count = 1;
+    long long j = value;
+
+    if( value < 0 ) {
+        count = 32;
+    } else {
+        while ( (j >>= 1) != 0) {
+            count++;
+        }
+    }
+
+    // Save length and allocate a new buffer for the string, add one
+    // more for the null character.
+    int length = count;
+    char* buffer = new char[length + 1];
+
+    do {
+        buffer[--count] = (char)( (value & 1) + '0' );
+        value >>= 1;
+    } while( count > 0 );
+
+    // Ensure there's a null
+    buffer[length] = 0;
+    std::string result( &buffer[0] );
+    delete [] buffer;
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toOctalString( long long value ) {
+
+    int count = 1;
+    long long j = value;
+
+    if( value < 0 ) {
+        count = 11;
+    } else {
+        while ( (j >>= 3) != 0 ) {
+            count++;
+        }
+    }
+
+    // Save length and allocate a new buffer for the string, add one
+    // more for the null character.
+    int length = count;
+    char* buffer = new char[length + 1];
+
+    do {
+        buffer[--count] = (char)( (value & 7) + '0' );
+        value >>= 3;
+    } while( count > 0 );
+
+    // Ensure there's a null
+    buffer[length] = 0;
+    std::string result( &buffer[0] );
+    delete [] buffer;
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Long::toHexString( long long value ) {
+
+    int count = 1;
+    long long j = value;
+
+    if( value < 0 ) {
+        count = 8;
+    } else {
+        while( (j >>= 4) != 0 ) {
+            count++;
+        }
+    }
+
+    // Save length and allocate a new buffer for the string, add one
+    // more for the null character.
+    int length = count;
+    char* buffer = new char[length + 1];
+
+    do {
+        int t = value & 15;
+        if( t > 9 ) {
+            t = t - 10 + 'a';
+        } else {
+            t += '0';
+        }
+        buffer[--count] = (char)t;
+        value >>= 4;
+    } while( count > 0 );
+
+    // Ensure there's a null
+    buffer[length] = 0;
+    std::string result( &buffer[0] );
+    delete [] buffer;
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Long Long::valueOf( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Long( Long::parseLong( value ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Long Long::valueOf( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Long( Long::parseLong( value, radix ) );
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.h?view=diff&rev=562458&r1=562457&r2=562458
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Long.h Fri Aug  3 06:26:08 2007
@@ -20,12 +20,15 @@
 
 #include <decaf/lang/Number.h>
 #include <decaf/lang/Comparable.h>
+#include <decaf/lang/exceptions/NumberFormatException.h>
 #include <string>
 
 namespace decaf{
 namespace lang{
 
-    class DECAF_API Long : public Number{
+    class DECAF_API Long : public Number,
+                           public Comparable<Long>,
+                           public Comparable<long long> {
     private:
 
         // The primitive long long value
@@ -44,15 +47,323 @@
 
     public:
 
-        Long() {}
+        /**
+         * @param value - the primitive long long to wrap
+         */
+        Long( long long value );
+
+        /**
+         * @param value - the long long formated string to wrap
+         */
+        Long( const std::string& value );
+
         virtual ~Long() {}
 
         /**
-         * Parses the String passed and extracts an long.
-         * @param String to parse
-         * @return long value
+         * Compares this Long instance with another.
+         * @param l - the Long instance to be compared
+         * @return zero if this object represents the same integer value as the
+         * argument; a positive value if this object represents a value greater
+         * than the passed in value, and -1 if this object repesents a value
+         * less than the passed in value.
+         */
+        virtual int compareTo( const Long& l ) const;
+
+        /**
+         * @param l - the Long object to compare against.
+         * @returns true if the two Integer Objects have the same value.
+         */
+        bool equals( const Long& l ) const {
+            return this->value == l.value;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param l - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const Long& l ) const {
+            return this->value == l.value;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param l - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
          */
-        static long long parseLong( const std::string& value );
+        virtual bool operator<( const Long& l ) const {
+            return this->value < l.value;
+        }
+
+        /**
+         * Compares this Long instance with another.
+         * @param l - the Integer instance to be compared
+         * @return zero if this object represents the same integer value as the
+         * argument; a positive value if this object represents a value greater
+         * than the passed in value, and -1 if this object repesents a value
+         * less than the passed in value.
+         */
+        virtual int compareTo( const long long& l ) const;
+
+        /**
+         * @param l - the Long object to compare against.
+         * @returns true if the two Integer Objects have the same value.
+         */
+        bool equals( const long long& l ) const {
+            return this->value == l;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param l - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const long long& l ) const {
+            return this->value == l;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param l - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const long long& l ) const {
+            return this->value < l;
+        }
+
+        /**
+         * @returns this Long Object as a String Representation
+         */
+        std::string toString() const;
+
+        /**
+         * Answers the double value which the receiver represents
+         * @return double the value of the receiver.
+         */
+        virtual double doubleValue() const {
+            return (double)this->value;
+        }
+
+        /**
+         * Answers the float value which the receiver represents
+         * @return float the value of the receiver.
+         */
+        virtual float floatValue() const {
+            return (float)this->value;
+        }
+
+        /**
+         * Answers the byte value which the receiver represents
+         * @return int the value of the receiver.
+         */
+        virtual unsigned char byteValue() const {
+            return (unsigned char)this->value;
+        }
+
+        /**
+         * Answers the short value which the receiver represents
+         * @return int the value of the receiver.
+         */
+        virtual short shortValue() const {
+            return (short)this->value;
+        }
+
+        /**
+         * Answers the int value which the receiver represents
+         * @return int the value of the receiver.
+         */
+        virtual int intValue() const {
+            return (int)this->value;
+        }
+
+        /**
+         * Answers the long value which the receiver represents
+         * @return long the value of the receiver.
+         */
+        virtual long long longValue() const {
+            return this->value;
+        }
+
+    public:
+
+        /**
+         * Returns the number of one-bits in the two's complement binary
+         * representation of the specified int value. This function is sometimes
+         * referred to as the population count.
+         * @param value - the long long to count
+         * @return the number of one-bits in the two's complement binary
+         * representation of the specified long long value.
+         */
+        static int bitCount( long long value );
+
+        /**
+         * Decodes a String into a Long. Accepts decimal, hexadecimal, and octal
+         * numbers given by the following grammar:
+         *
+         * The sequence of characters following an (optional) negative sign and/or
+         * radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the
+         * Integer.parseInteger method with the indicated radix (10, 16, or 8). This
+         * sequence of characters must represent a positive value or a
+         * NumberFormatException will be thrown. The result is negated if first
+         * character of the specified String is the minus sign. No whitespace
+         * characters are permitted in the string.
+         * @param value - The string to decode
+         * @returns a Long object containing the decoded value
+         * @throws NumberFomatException if the string is not formatted correctly.
+         */
+        static Long decode( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns an long long value with at most a single one-bit, in the position
+         * of the highest-order ("leftmost") one-bit in the specified int value.
+         * Returns zero if the specified value has no one-bits in its two's
+         * complement binary representation, that is, if it is equal to zero.
+         * @param value - the long long to be inspected
+         * @return an long long value with a single one-bit, in the position of the
+         * highest-order one-bit in the specified value, or zero if the specified
+         * value is itself equal to zero.
+         */
+        static long long highestOneBit( long long value );
+
+        /**
+         * Returns an long long value with at most a single one-bit, in the position
+         * of the lowest-order ("rightmost") one-bit in the specified int value.
+         * Returns zero if the specified value has no one-bits in its two's
+         * complement binary representation, that is, if it is equal to zero.
+         * @param value - the long long to be inspected
+         * @return an long long value with a single one-bit, in the position of the
+         * lowest-order one-bit in the specified value, or zero if the specified
+         * value is itself equal to zero.
+         */
+        static long long lowestOneBit( long long value );
+
+        /**
+         * Returns the number of zero bits preceding the highest-order ("leftmost")
+         * one-bit in the two's complement binary representation of the specified
+         * long long value. Returns 64 if the specified value has no one-bits in its
+         * two's complement representation, in other words if it is equal to zero.
+         *
+         * Note that this method is closely related to the logarithm base 2. For
+         * all positive int values x:
+         *
+         *     * floor( log2(x)) = 63 - numberOfLeadingZeros(x)
+         *     * ceil( log2(x)) = 64 - numberOfLeadingZeros(x - 1)
+         *
+         * @param value - the long long to be inspected
+         * @return the number of zero bits preceding the highest-order ("leftmost")
+         * one-bit in the two's complement binary representation of the specified
+         * long long value, or 64 if the value is equal to zero.
+         */
+        static int numberOfLeadingZeros( long long value );
+
+        /**
+         * Returns the number of zero bits following the lowest-order ("rightmost")
+         * one-bit in the two's complement binary representation of the specified
+         * long long value. Returns 64 if the specified value has no one-bits in its
+         * two's complement representation, in other words if it is equal to zero.
+         * @param value - the int to be inspected
+         * @return the number of zero bits following the lowest-order ("rightmost")
+         * one-bit in the two's complement binary representation of the specified
+         * long long value, or 64 if the value is equal to zero.
+         */
+        static int numberOfTrailingZeros( long long value );
+
+        /**
+         * Parses the string argument as a signed decimal long. The characters in the
+         * string must all be decimal digits, except that the first character may be
+         * an ASCII minus sign '-' to indicate a negative value. The resulting long
+         * value is returned, exactly as if the argument and the radix 10 were given
+         * as arguments to the parseLong(java.lang.String, int) method.
+         *
+         * Note that the characters LL or ULL are not permitted to appear at the end
+         * of this string as would normally be permitted in a C++ program.
+         * @param value - String to parse
+         * @return long long value
+         * @throws NumberFormatException on invalid string value
+         */
+        static long long parseLong( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a Long object holding the value extracted from the specified
+         * string when parsed with the radix given by the second argument. The
+         * first argument is interpreted as representing a signed long in the radix
+         * specified by the second argument, exactly as if the arguments were
+         * given to the parseLong(std::string, int) method. The result is a
+         * Long object that represents the long long value specified by the string.
+         * @param value - String to parse
+         * @param radix - the base encoding of the string
+         * @return long long value
+         * @throws NumberFormatException on invalid string value
+         */
+        static long long parseLong( const std::string& value, int radix )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns the value obtained by reversing the order of the bytes in the
+         * two's complement representation of the specified long long value.
+         * @param value - the long long whose bytes we are to reverse
+         * @return the reversed long long.
+         */
+        static long long reverseBytes( long long value );
+
+        /**
+         * Returns the value obtained by reversing the order of the bits in the
+         * two's complement binary representation of the specified long long value.
+         * @param value - the value whose bits are to be reversed
+         * @returns the reversed bits long long.
+         */
+        static long long reverse( long long value );
+
+        /**
+         * Returns the value obtained by rotating the two's complement binary
+         * representation of the specified value left by the specified number
+         * of bits. (Bits shifted out of the left hand, or high-order, side reenter
+         * on the right, or low-order.)
+         *
+         * Note that left rotation with a negative distance is equivalent to right
+         * rotation: rotateLeft(val, -distance) == rotateRight(val, distance). Note
+         * also that rotation by any multiple of 32 is a no-op, so all but the last
+         * five bits of the rotation distance can be ignored, even if the distance
+         * is negative: rotateLeft(val, distance) == rotateLeft(val, distance & 0x1F).
+         * @param value - the long long to be inspected
+         * @param distance - the number of bits to rotate
+         * @return the value obtained by rotating the two's complement binary
+         * representation of the specified value left by the specified number
+         * of bits.
+         */
+        static long long rotateLeft( long long value, int distance );
+
+        /**
+         * Returns the value obtained by rotating the two's complement binary
+         * representation of the specified value right by the specified number
+         * of bits. (Bits shifted out of the right hand, or low-order, side reenter
+         * on the left, or high-order.)
+         *
+         * Note that right rotation with a negative distance is equivalent to left
+         * rotation: rotateRight(val, -distance) == rotateLeft(val, distance). Note
+         * also that rotation by any multiple of 32 is a no-op, so all but the last
+         * five bits of the rotation distance can be ignored, even if the distance is
+         * negative: rotateRight(val, distance) == rotateRight(val, distance & 0x1F).
+         * @param value - the long long to be inspected
+         * @param distance - the number of bits to rotate
+         * @return the value obtained by rotating the two's complement binary
+         * representation of the specified value right by the specified number
+         * of bits.
+         */
+        static long long rotateRight( long long value, int distance );
+
+        /**
+         * Returns the signum function of the specified value. (The return value
+         * is -1 if the specified value is negative; 0 if the specified value is zero;
+         * and 1 if the specified value is positive.)
+         * @param value - the long long to be inspected
+         * @return the signum function of the specified long long value.
+         */
+        static int signum( long long value );
 
         /**
          * Converts the long to a String representation
@@ -60,6 +371,133 @@
          * @return string representation
          */
         static std::string toString( long long value );
+
+        /*
+         * Returns a string representation of the first argument in the radix
+         * specified by the second argument.
+         *
+         * If the radix is smaller than Character.MIN_RADIX or larger than
+         * Character.MAX_RADIX, then the radix 10 is used instead.
+         *
+         * If the first argument is negative, the first element of the result is
+         * the ASCII minus character '-'. If the first argument is not
+         * negative, no sign character appears in the result.
+         *
+         * The remaining characters of the result represent the magnitude of the
+         * first argument. If the magnitude is zero, it is represented by a single
+         *  zero character '0'; otherwise, the first character of the
+         * representation of the magnitude will not be the zero character. The
+         * following ASCII characters are used as digits:
+         *
+         *    0123456789abcdefghijklmnopqrstuvwxyz
+         *
+         * @param value - the long long to convert to a string
+         * @param radix - the radix to format the string in
+         * @returns an long long formatted to the string value of the radix given.
+         */
+        static std::string toString( long long value, int radix );
+
+        /**
+         * Returns a string representation of the integer argument as an unsigned
+         * integer in base 16.
+         *
+         * The unsigned integer value is the argument plus 2^32 if the argument is
+         * negative; otherwise, it is equal to the argument. This value is converted
+         * to a string of ASCII digits in hexadecimal (base 16) with no extra leading
+         * 0s. If the unsigned magnitude is zero, it is represented by a single zero
+         * character '0'; otherwise, the first character of the representation of the
+         * unsigned magnitude will not be the zero character. The following characters
+         * are used as hexadecimal digits:
+         *
+         * 		0123456789abcdef
+         *
+         * If uppercase letters are desired, the toUpperCase() method may be called
+         * on the result:
+         * @param value - the long long to be translated to an Octal string
+         * @returns the unsigned long long value as a Octal string
+         */
+        static std::string toHexString( long long value );
+
+        /**
+         * Returns a string representation of the long long argument as an unsigned
+         * long long in base 8.
+         *
+         * The unsigned long long value is the argument plus 2^32 if the argument is
+         * negative; otherwise, it is equal to the argument. This value is converted
+         * to a string of ASCII digits in octal (base 8) with no extra leading 0s.
+         *
+         * If the unsigned magnitude is zero, it is represented by a single zero
+         * character '0'; otherwise, the first character of the representation
+         * of the unsigned magnitude will not be the zero character. The following
+         * characters are used as octal digits:
+         *
+         *      01234567
+         *
+         * @param value - the long long to be translated to an Octal string
+         * @returns the unsigned long long value as a Octal string
+         */
+        static std::string toOctalString( long long value );
+
+        /**
+         * Returns a string representation of the long long argument as an unsigned
+         * long long in base 2.
+         *
+         * The unsigned long long value is the argument plus 2^32 if the argument is
+         * negative; otherwise it is equal to the argument. This value is converted
+         * to a string of ASCII digits in binary (base 2) with no extra leading 0s.
+         * If the unsigned magnitude is zero, it is represented by a single zero
+         * character '0'; otherwise, the first character of the
+         * representation of the unsigned magnitude will not be the zero character.
+         * The characters '0' and '1' are used as binary
+         * digits.
+         * @param value - the long long to be translated to a binary string
+         * @returns the unsigned long long value as a binary string
+         */
+        static std::string toBinaryString( long long value );
+
+        /**
+         * Returns a Long instance representing the specified int value.
+         * @param value - the long long to wrap
+         * @return the new Integer object wrapping value.
+         */
+        static Long valueOf( long long value ) {
+            return Long( value );
+        }
+
+        /**
+         * Returns a Long object holding the value given by the specified
+         * std::string.  The argument is interpreted as representing a signed
+         * decimal long long, exactly as if the argument were given to the
+         * parseLong( std::string ) method. The result is a Integer object that
+         * represents the long long value specified by the string.
+         * @param value - std::string to parse as base 10
+         * @return new Long Object wrapping the primitive
+         * @throws NumberFormatException if the string is not a decimal long long.
+         */
+        static Long valueOf( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a Long object holding the value extracted from the specified
+         * std::string when parsed with the radix given by the second argument.
+         * The first argument is interpreted as representing a signed long long in the
+         * radix specified by the second argument, exactly as if the argument were
+         * given to the parseLong( std::string, int ) method. The result is a
+         * Long object that represents the long long value specified by the string.
+         * @param value - std::string to parse as base ( radix )
+         * @param radix - base of the string to parse.
+         * @return new Long Object wrapping the primitive
+         * @throws NumberFormatException if the string is not a valid long long.
+         */
+        static Long valueOf( const std::string& value, int radix )
+            throw ( exceptions::NumberFormatException );
+
+    private:
+
+        static long long parse( const std::string& value, int offset,
+                                int radix, bool negative )
+            throw ( exceptions::NumberFormatException );
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.cpp?view=diff&rev=562458&r1=562457&r2=562458
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.cpp Fri Aug  3 06:26:08 2007
@@ -21,14 +21,15 @@
 using namespace decaf;
 using namespace decaf::lang;
 
-void LongTest::test(void)
-{
+////////////////////////////////////////////////////////////////////////////////
+void LongTest::test() {
+
     long long x = Long::parseLong("12");
-    long long y = Long::parseLong("12.1");
-    long long z = Long::parseLong("42 24");
+    long long y = Long::parseLong("FF", 16);
+    long long z = Long::parseLong("42");
 
     CPPUNIT_ASSERT( x == 12 );
-    CPPUNIT_ASSERT( y == 12 );
+    CPPUNIT_ASSERT( y == 255 );
     CPPUNIT_ASSERT( z == 42 );
 
     std::string x1 = Long::toString( x );
@@ -36,7 +37,74 @@
     std::string z1 = Long::toString( z );
 
     CPPUNIT_ASSERT( x1 == "12" );
-    CPPUNIT_ASSERT( y1 == "12" );
+    CPPUNIT_ASSERT( y1 == "255" );
     CPPUNIT_ASSERT( z1 == "42" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LongTest::test2() {
+
+    Long llong( 255 );
+
+    // Test cast functions
+    CPPUNIT_ASSERT( llong.byteValue() == 255 );
+    CPPUNIT_ASSERT( llong.shortValue() ==  255 );
+    CPPUNIT_ASSERT( llong.intValue() == 255 );
+    CPPUNIT_ASSERT( llong.longValue() == 255 );
+    CPPUNIT_ASSERT( llong.floatValue() == 255.0f );
+    CPPUNIT_ASSERT( llong.doubleValue() == 255.0 );
+
+    // Comparison functions
+    CPPUNIT_ASSERT( llong.compareTo( 256 ) == -1 );
+    CPPUNIT_ASSERT( llong.compareTo( 255 ) == 0 );
+    CPPUNIT_ASSERT( llong.compareTo( 254 ) == 1 );
+    CPPUNIT_ASSERT( llong.equals( Long( 255 ) ) == true );
+    CPPUNIT_ASSERT( llong.compareTo( Long( 255 ) ) == 0 );
+    CPPUNIT_ASSERT( llong == Long( 255 ) );
+
+    // decode
+    CPPUNIT_ASSERT( llong == Long::decode( "255" ) );
+    CPPUNIT_ASSERT( llong == Long::decode( "0xFF" ) );
+    CPPUNIT_ASSERT( llong == Long::decode( "255" ) );
+    CPPUNIT_ASSERT( Long::decode( "-255" ) == -255 );
+
+    // reverseBytes
+    CPPUNIT_ASSERT( (long long)0xFF00000000000000LL == Long::reverseBytes( 255 ) );
+
+    // reverse
+    CPPUNIT_ASSERT( Long::reverse( Long::reverse( 255 ) ) == 255 );
+
+    // parseInt
+    CPPUNIT_ASSERT( Long::parseLong( "255") == 255 );
+    CPPUNIT_ASSERT( Long::parseLong( "255", 10 ) == 255 );
+    CPPUNIT_ASSERT( Long::parseLong( "255", 11 ) != 255 );
+    CPPUNIT_ASSERT( Long::parseLong( "FF", 16 ) == 255 );
+
+    // valueOf
+    CPPUNIT_ASSERT( Long::valueOf( 255 ) == 255 );
+    CPPUNIT_ASSERT( Long::valueOf( "255" ) == 255 );
+    CPPUNIT_ASSERT( Long::valueOf( "255", 10 ) == 255 );
+    CPPUNIT_ASSERT( (Long::valueOf( "255", 11 )).intValue() != 255 );
+    CPPUNIT_ASSERT( Long::valueOf( "FF", 16 ) == 255 );
+
+    // bitCount
+    CPPUNIT_ASSERT( Long::bitCount( 255 ) == 8 );
+    CPPUNIT_ASSERT( Long::bitCount( 0xFFFFFFFF ) == 32 );
+
+    //toXXXString
+    CPPUNIT_ASSERT( Long::toString( 255 ) == "255" );
+    CPPUNIT_ASSERT( Long::toString( 255, 16 ) == "ff" );
+    CPPUNIT_ASSERT( Long::toHexString( 255 ) == "ff" );
+    CPPUNIT_ASSERT( Long::toOctalString( 255 ) == "377" );
+    CPPUNIT_ASSERT( Long::toBinaryString( 255 ) == "11111111" );
+    CPPUNIT_ASSERT( Long::toString( 255255 ) == "255255" );
+
+    // highestOneBit
+    CPPUNIT_ASSERT( Long::highestOneBit( 255 ) == 128 );
+    CPPUNIT_ASSERT( Long::highestOneBit( 0xFF000000 ) == (long long)0x80000000 );
+
+    // lowestOneBit
+    CPPUNIT_ASSERT( Long::lowestOneBit( 255 ) == 1 );
+    CPPUNIT_ASSERT( Long::lowestOneBit( 0xFF000000 ) == (long long)0x01000000 );
 
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.h?view=diff&rev=562458&r1=562457&r2=562458
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/LongTest.h Fri Aug  3 06:26:08 2007
@@ -30,6 +30,7 @@
     {
         CPPUNIT_TEST_SUITE( LongTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( test2 );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -37,7 +38,8 @@
         LongTest() {}
         virtual ~LongTest() {}
 
-        virtual void test(void);
+        virtual void test();
+        virtual void test2();
 
     };