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/29 20:17:16 UTC

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

Author: tabish
Date: Sun Jul 29 11:17:16 2007
New Revision: 560775

URL: http://svn.apache.org/viewvc?view=rev&rev=560775
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=560775&r1=560774&r2=560775
==============================================================================
--- 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 Sun Jul 29 11:17:16 2007
@@ -20,6 +20,7 @@
 
 using namespace decaf;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 Integer::Integer( int value ) {
@@ -38,7 +39,20 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 int Integer::bitCount( int value ) {
-    return value; //TODO
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    // 32-bit recursive reduction using SWAR...
+    // but first step is mapping 2-bit values
+    // into sum of 2 1-bit values in sneaky way
+    value -= ((value >> 1) & 0x55555555);
+    value = (((value >> 2) & 0x33333333) + (value & 0x33333333));
+    value = (((value >> 4) + value) & 0x0F0F0F0F);
+    value += (value >> 8);
+    value += (value >> 16);
+    return(value & 0x0000003F);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -58,4 +72,48 @@
     istream.clear();
     istream >> ret;
     return ret;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::parse( const std::string& value, int offset,
+                    int radix, bool negative )
+    throw ( exceptions::NumberFormatException ) {
+
+    int max = Integer::MIN_VALUE / radix;
+    int result = 0, length = value.size();
+
+    while( offset < length ) {
+        //TODO
+        int digit = 0;//Character.digit(string.charAt(offset++), radix);
+        if( digit == -1 ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer::parse - number string is invalid: ",
+                value.c_str() );
+        }
+        if( max > result ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer::parse - number string is invalid: ",
+                value.c_str() );
+        }
+        int next = result * radix - digit;
+        if( next > result ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer::parse - number string is invalid: ",
+                value.c_str() );
+        }
+        result = next;
+    }
+    if( !negative ) {
+        result = -result;
+        if( result < 0 ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer::parse - number string is invalid: ",
+                value.c_str() );
+        }
+    }
+    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=560775&r1=560774&r2=560775
==============================================================================
--- 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 Sun Jul 29 11:17:16 2007
@@ -275,6 +275,12 @@
          */
         static std::string toString( int value, int radix );
 
+    private:
+
+        static int parse( const std::string& value, int offset,
+                          int radix, bool negative )
+            throw ( exceptions::NumberFormatException );
+
     };
 
 }}