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 2008/04/29 22:52:37 UTC

svn commit: r652104 [9/29] - in /activemq/activemq-cpp/trunk: ./ m4/ src/examples/ src/examples/consumers/ src/main/ src/main/decaf/ src/main/decaf/internal/ src/main/decaf/internal/net/ src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/ma...

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include "Exception.h"
+#include <decaf/util/logging/LoggerDefines.h>
+#include <decaf/internal/AprPool.h>
+
+#include <sstream>
+#include <apr_strings.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::lang;
+using namespace decaf::util::logging;
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const Exception& ex ) throw() : Throwable() {
+    *this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const char* file, const int lineNumber,
+                      const char* msg, ... ) throw() {
+    va_list vargs;
+    va_start( vargs, msg ) ;
+    buildMessage( msg, vargs );
+
+    // Set the first mark for this exception.
+    setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::~Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setMessage( const char* msg, ... ){
+    va_list vargs;
+    va_start( vargs, msg );
+    buildMessage( msg, vargs );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::buildMessage( const char* format, va_list& vargs ) {
+
+    // Allocate buffer with a guess of it's size
+    AprPool pool;
+
+    // Allocate a buffer of the specified size.
+    char* buffer = apr_pvsprintf( pool.getAprPool(), format, vargs );
+
+    // Guessed size was enough. Assign the string.
+    message.assign( buffer, strlen( buffer ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setMark( const char* file, const int lineNumber ) {
+
+    // Add this mark to the end of the stack trace.
+    stackTrace.push_back( std::make_pair( (std::string)file, (int)lineNumber ) );
+
+    std::ostringstream stream;
+    stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
+    stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
+
+    //decaf::util::logger::SimpleLogger logger("com.yadda2");
+    //logger.log( stream.str() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception* Exception::clone() const {
+    return new Exception( *this );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector< std::pair< std::string, int> > Exception::getStackTrace() const {
+    return stackTrace;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setStackTrace(
+    const std::vector< std::pair< std::string, int> >& trace ) {
+
+    this->stackTrace = trace;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace() const {
+    printStackTrace( std::cerr );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace( std::ostream& stream ) const {
+    stream << getStackTraceString();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Exception::getStackTraceString() const {
+
+    // Create the output stream.
+    std::ostringstream stream;
+
+    // Write the message and each stack entry.
+    stream << message << std::endl;
+    for( unsigned int ix=0; ix<stackTrace.size(); ++ix ){
+        stream << "\tFILE: " << stackTrace[ix].first;
+        stream << ", LINE: " << stackTrace[ix].second;
+        stream << std::endl;
+    }
+
+    // Return the string from the output stream.
+    return stream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception& Exception::operator =( const Exception& ex ){
+    this->message = ex.message;
+    this->stackTrace = ex.stackTrace;
+    return *this;
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Exception.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+#define _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+
+#ifdef _WIN32
+#pragma warning( disable: 4251 )
+#endif
+
+#include <decaf/lang/Throwable.h>
+#include <decaf/lang/exceptions/ExceptionDefines.h>
+#include <decaf/util/Config.h>
+#include <stdarg.h>
+#include <sstream>
+
+namespace decaf{
+namespace lang{
+
+    /*
+     * Base class for all exceptions.
+     */
+    class DECAF_API Exception : public Throwable {
+    private:
+
+        /**
+         * The cause of this exception.
+         */
+        std::string message;
+
+        /**
+         * The stack trace.
+         */
+        std::vector< std::pair< std::string, int> > stackTrace;
+
+    public:
+
+        /**
+         * Default Constructor
+         */
+        Exception() throw();
+
+        /**
+         * Copy Constructor
+         */
+        Exception( const Exception& ex ) throw();
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        Exception( const char* file, const int lineNumber,
+                   const char* msg, ... ) throw();
+
+        virtual ~Exception() throw();
+
+        /**
+         * Gets the message for this exception.
+         * @return Text formatted error message
+         */
+        virtual std::string getMessage() const{
+            return message;
+        }
+
+        /**
+         * Implement method from std::exception
+         * @return the const char* of <code>getMessage()</code>.
+         */
+        virtual const char* what() const throw (){
+            return message.c_str();
+        }
+
+        /**
+         * Sets the cause for this exception.
+         * @param msg the format string for the msg.
+         * @param variable - params to format into the string
+         */
+        virtual void setMessage( const char* msg, ... );
+
+        /**
+         * Adds a file/line number to the stack trace.
+         * @param file The name of the file calling this method (use __FILE__).
+         * @param lineNumber The line number in the calling file (use __LINE__).
+         */
+        virtual void setMark( const char* file, const int lineNumber );
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         * @return Copy of this Exception object
+         */
+        virtual Exception* clone() const;
+
+        /**
+         * Provides the stack trace for every point where
+         * this exception was caught, marked, and rethrown.  The first
+         * item in the returned vector is the first point where the mark
+         * was set (e.g. where the exception was created).
+         * @return the stack trace.
+         */
+        virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
+
+        /**
+         * Prints the stack trace to std::err
+         */
+        virtual void printStackTrace() const;
+
+        /**
+         * Prints the stack trace to the given output stream.
+         * @param stream the target output stream.
+         */
+        virtual void printStackTrace( std::ostream& stream ) const;
+
+        /**
+         * Gets the stack trace as one contiguous string.
+         * @return string with formatted stack trace data
+         */
+        virtual std::string getStackTraceString() const;
+
+        /**
+         * Assignment operator.
+         * @param const reference to another Exception
+         */
+        virtual Exception& operator =( const Exception& ex );
+
+    protected:
+
+        virtual void setStackTrace(
+            const std::vector< std::pair< std::string, int> >& trace );
+
+        virtual void buildMessage( const char* format, va_list& vargs );
+
+   };
+
+}}
+
+#endif /*_DECAF_LANG_EXCEPTION_EXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Float.h"
+#include <decaf/lang/Integer.h>
+#include <limits>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const float Float::MAX_VALUE = 3.40282346638528860e+38f;
+const float Float::MIN_VALUE = 1.40129846432481707e-45f;
+const float Float::NaN = std::numeric_limits<float>::quiet_NaN();
+const float Float::POSITIVE_INFINITY = std::numeric_limits<float>::infinity();
+const float Float::NEGATIVE_INFINITY = -std::numeric_limits<float>::infinity();
+
+////////////////////////////////////////////////////////////////////////////////
+Float::Float( float value ) {
+    this->value = value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float::Float( double value ) {
+    this->value = (float)value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float::Float( const std::string& value ) throw( exceptions::NumberFormatException ) {
+    this->value = Float::parseFloat( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::compareTo( const Float& f ) const {
+    return Float::compare( this->value, f.value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::compareTo( const float& f ) const {
+    return Float::compare( this->value, f );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Float::toString() const {
+    return Float::toString( this->value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isInfinite() const {
+    return Float::isInfinite( this->value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isNaN() const {
+    return Float::isNaN( this->value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::compare( float f1, float f2 ) {
+
+    int i1, i2 = 0;
+    long NaNbits = Float::floatToIntBits( Float::NaN );
+
+    if( ( i1 = Float::floatToIntBits( f1 ) ) == NaNbits ) {
+        if( Float::floatToIntBits( f2 ) == NaNbits ) {
+            return 0;
+        }
+        return 1;
+    }
+
+    if( ( i2 = Float::floatToIntBits( f2 ) ) == NaNbits ) {
+        return -1;
+    }
+
+    if( f1 == f2 ) {
+        if( i1 == i2 ) {
+            return 0;
+        }
+
+        // check for -0
+        return i1 > i2 ? 1 : -1;
+    }
+
+    return f1 > f2 ? 1 : -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::floatToIntBits( float value ) {
+
+    int intValue = 0;
+    memcpy( &intValue, &value, sizeof( float ) );
+
+    if( ( intValue & SINGLE_EXPONENT_MASK ) == SINGLE_EXPONENT_MASK )
+    {
+        if( intValue & SINGLE_MANTISSA_MASK )
+        {
+            return SINGLE_NAN_BITS;
+        }
+    }
+
+    return intValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::floatToRawIntBits( float value ) {
+
+    int intValue = 0;
+    memcpy( &intValue, &value, sizeof( float ) );
+    return intValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Float::intBitsToFloat( int bits ) {
+
+    float floatValue = 0;
+    memcpy( &floatValue, &bits, sizeof( int ) );
+    return floatValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isInfinite( float value ) {
+    return ( value == POSITIVE_INFINITY ) || ( value == NEGATIVE_INFINITY );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isNaN( float value ) {
+    return value != value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Float::parseFloat( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    // TODO - This is not going to parse the formats we say we do.
+    float result = 0.0;
+    istringstream stream( value );
+    stream >> result;
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Float::toHexString( float value ) {
+    /*
+     * Reference: http://en.wikipedia.org/wiki/IEEE_754
+     */
+    if( value != value ) {
+        return "NaN";
+    }
+    if( value == POSITIVE_INFINITY ) {
+        return "Infinity";
+    }
+    if( value == NEGATIVE_INFINITY ) {
+        return "-Infinity";
+    }
+
+    unsigned int bitValue = Float::floatToIntBits( value );
+
+    bool negative = ( bitValue & 0x80000000 ) != 0;
+    // mask exponent bits and shift down
+    unsigned int exponent = ( bitValue & 0x7f800000 ) >> 23;
+    // mask significand bits and shift up
+    // significand is 23-bits, so we shift to treat it like 24-bits
+    unsigned int significand = ( bitValue & 0x007FFFFF ) << 1;
+
+    if( exponent == 0 && significand == 0 ) {
+        return ( negative ? "-0x0.0p0" : "0x0.0p0" );
+    }
+
+    // Start with the correct sign and Hex indicator
+    std::string hexString( negative ? "-0x" : "0x" );
+
+    if( exponent == 0 ) {
+        // denormal (subnormal) value
+        hexString.append( "0." );
+        // significand is 23-bits, so there can be 6 hex digits
+        unsigned int fractionDigits = 6;
+        // remove trailing hex zeros, so Integer.toHexString() won't print
+        // them
+        while( ( significand != 0 ) && ( ( significand & 0xF ) == 0 ) ) {
+            significand >>= 4;
+            fractionDigits--;
+        }
+        // this assumes Integer.toHexString() returns lowercase characters
+        std::string hexSignificand = Integer::toHexString( significand );
+
+        // if there are digits left, then insert some '0' chars first
+        if( significand != 0 && fractionDigits > hexSignificand.length() ) {
+            unsigned int digitDiff = fractionDigits - hexSignificand.length();
+            while( digitDiff-- != 0 ) {
+                hexString.append( "0" );
+            }
+        }
+        hexString.append( hexSignificand );
+        hexString.append( "p-126" );
+    } else {
+        // normal value
+        hexString.append( "1." );
+        // significand is 23-bits, so there can be 6 hex digits
+        unsigned int fractionDigits = 6;
+        // remove trailing hex zeros, so Integer.toHexString() won't print
+        // them
+        while( (significand != 0) && ((significand & 0xF ) == 0 ) ) {
+            significand >>= 4;
+            fractionDigits--;
+        }
+        // this assumes Integer.toHexString() returns lowercase characters
+        std::string hexSignificand = Integer::toHexString( significand );
+
+        // if there are digits left, then insert some '0' chars first
+        if( significand != 0 && fractionDigits > hexSignificand.length() ) {
+            unsigned int digitDiff = fractionDigits - hexSignificand.length();
+            while( digitDiff-- != 0 ) {
+                hexString.append( "0" );
+            }
+        }
+        hexString.append( hexSignificand );
+        hexString.append( "p" );
+        // remove exponent's 'bias' and convert to a string
+        hexString.append( Integer::toString( exponent - 127 ) );
+    }
+
+    return hexString;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Float::toString( float value ) {
+
+    // TODO - This is not going to support the formats we say we do.
+    ostringstream stream;
+    stream << value;
+    return stream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float Float::valueOf( float value ) {
+    return Float( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float Float::valueOf( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return valueOf( parseFloat( value ) );
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Float.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,414 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_FLOAT_H_
+#define _DECAF_LANG_FLOAT_H_
+
+#include <decaf/util/Config.h>
+#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 Float : public Number,
+                            public Comparable<Float>,
+                            public Comparable<float> {
+    private:
+
+        float value;
+
+    public:
+
+        /** The size in bits of the primitive int type */
+        static const int SIZE = 32;
+
+        /** The maximum value that the primitive type can hold */
+        static const float MAX_VALUE;
+
+        /** The minimum value that the primitive type can hold */
+        static const float MIN_VALUE;
+
+        /** Constant for the Not a Number Value */
+        static const float NaN;
+
+        /** Constant for Positive Infinity */
+        static const float POSITIVE_INFINITY;
+
+        /** Constant for Negative Infinitiy */
+        static const float NEGATIVE_INFINITY;
+
+    public:
+
+        /**
+         * @param value - the primitve type to wrap
+         */
+        Float( float value );
+
+        /**
+         * @param value - the primitve type to wrap
+         */
+        Float( double value );
+
+        /**
+         * @param value - the string to convert to a primitve type to wrap
+         */
+        Float( const std::string& value ) throw( exceptions::NumberFormatException );
+
+        virtual ~Float() {}
+
+        /**
+         * Compares this Float instance with another.
+         * @param f - the Float 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 Float& f ) const;
+
+        /**
+         * @param f - the Float object to compare against.
+         * @returns true if the two Float Objects have the same value.
+         */
+        bool equals( const Float& f ) const {
+            return this->value == f.value;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param f - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const Float& f ) const {
+            return this->value == f.value;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param f - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const Float& f ) const {
+            return this->value < f.value;
+        }
+
+        /**
+         * Compares this Float instance with another.
+         * @param f - the Float 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 float& f ) const;
+
+        /**
+         * @param f - the Float object to compare against.
+         * @returns true if the two Float Objects have the same value.
+         */
+        bool equals( const float& f ) const {
+            return this->value == f;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param f - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const float& f ) const {
+            return this->value == f;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param f - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const float& f ) const {
+            return this->value < f;
+        }
+
+        /**
+         * @returns this Float 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 this->value;
+        }
+
+        /**
+         * Answers the byte value which the receiver represents
+         * @return byte the value of the receiver.
+         */
+        virtual unsigned char byteValue() const {
+            return (unsigned char)this->value;
+        }
+
+        /**
+         * Answers the short value which the receiver represents
+         * @return short 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 (long long)this->value;
+        }
+
+        /**
+         * @returns true if the float is equal to positive infinity.
+         */
+        bool isInfinite() const;
+
+        /**
+         * @returns true if the float is equal to NaN.
+         */
+        bool isNaN() const;
+
+    public:   // Statics
+
+        /**
+         * Compares the two specified double values. The sign of the integer value
+         * returned is the same as that of the integer that would be returned by the
+         * call: Float( f1 ).compareTo( Float( f2) )
+         * @param f1 - the first double to compare
+         * @param f2 - the second double to compare
+         * @returns the value 0 if d1 is numerically equal to f2; a value less than
+         * 0 if f1 is numerically less than f2; and a value greater than 0  if f1 is
+         * numerically greater than f2.
+         */
+        static int compare( float f1, float f2 );
+
+        /**
+         * Returns a representation of the specified floating-point value according
+         * to the IEEE 754 floating-point "single format" bit layout.
+         *
+         * Bit 31 (the bit that is selected by the mask 0x80000000) represents the
+         * sign of the floating-point number. Bits 30-23 (the bits that are selected
+         * by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that
+         * are selected by the mask 0x007fffff) represent the significand (sometimes
+         * called the mantissa) of the floating-point number.
+         *
+         * If the argument is positive infinity, the result is 0x7f800000.
+         * If the argument is negative infinity, the result is 0xff800000.
+         * If the argument is NaN, the result is 0x7fc00000.
+         *
+         * In all cases, the result is an integer that, when given to the
+         * intBitsToFloat(int) method, will produce a floating-point value the
+         * same as the argument to floatToIntBits (except all NaN values are
+         * collapsed to a single "canonical" NaN value).
+         * @param value - the float to convert to int bits
+         * @returns the int that holds the float's value
+         */
+        static int floatToIntBits( float value );
+
+        /**
+         * Returns a representation of the specified floating-point value according
+         * to the IEEE 754 floating-point "single format" bit layout, preserving
+         * Not-a-Number (NaN) values.
+         *
+         * Bit 31 (the bit that is selected by the mask 0x80000000) represents the
+         * sign of the floating-point number. Bits 30-23 (the bits that are selected
+         * by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that
+         * are selected by the mask 0x007fffff) represent the significand (sometimes
+         * called the mantissa) of the floating-point number.
+         *
+         * If the argument is positive infinity, the result is 0x7f800000.
+         * If the argument is negative infinity, the result is 0xff800000.
+         * If the argument is NaN, the result is the integer representing the
+         * actual NaN value. Unlike the floatToIntBits method, intToRawIntBits
+         * does not collapse all the bit patterns encoding a NaN to a single
+         * "canonical" NaN value.
+         *
+         * In all cases, the result is an integer that, when given to the
+         * intBitsToFloat(int) method, will produce a floating-point value the same
+         * as the argument to floatToRawIntBits.
+         * @param the float to convert to a raw int
+         * @returns the raw int value of the float
+         */
+        static int floatToRawIntBits( float value );
+
+        /**
+         * Returns the float value corresponding to a given bit representation. The
+         * argument is considered to be a representation of a floating-point value
+         * according to the IEEE 754 floating-point "single format" bit layout.
+         *
+         * If the argument is 0x7f800000, the result is positive infinity.
+         * If the argument is 0xff800000, the result is negative infinity.
+         * If the argument is any value in the range 0x7f800001 through 0x7fffffff
+         * or in the range 0xff800001 through 0xffffffff, the result is a NaN. No
+         * IEEE 754 floating-point operation provided by C++ can distinguish
+         * between two NaN values of the same type with different bit patterns.
+         * Distinct values of NaN are only distinguishable by use of the
+         * Float::floatToRawIntBits method.
+         *
+         * @param bits - the bits of the float encoded as a float
+         * @return a new float created from the int bits.
+         */
+        static float intBitsToFloat( int bits );
+
+        /**
+         * @param value - The float to check.
+         * @returns true if the float is equal to infinity.
+         */
+        static bool isInfinite( float value );
+
+        /**
+         * @param value - The float to check.
+         * @returns true if the float is equal to NaN.
+         */
+        static bool isNaN( float value );
+
+        /**
+         * Returns a new float initialized to the value represented by the
+         * specified string, as performed by the valueOf method of class Float.
+         * @param value - the string to parse
+         * @returns a float parsed from the string
+         * @throw NumberFormatException
+         */
+        static float parseFloat( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a hexadecimal string representation of the float argument. All
+         * characters mentioned below are ASCII characters.
+         *
+         *  * If the argument is NaN, the result is the string "NaN".
+         *  * Otherwise, the result is a string that represents the sign and magnitude
+         *    (absolute value) of the argument. If the sign is negative, the first
+         *    character of the result is '-'; if the sign is positive, no sign
+         *    character appears in the result. As for the magnitude m:
+         *      o If m is infinity, it is represented by the string "Infinity"; thus,
+         *        positive infinity produces the result "Infinity" and negative
+         *        infinity produces the result "-Infinity".
+         *      o If m is zero, it is represented by the string "0x0.0p0"; thus,
+         *        negative zero produces the result "-0x0.0p0" and positive zero
+         *        produces the result "0x0.0p0".
+         *      o If m is a float value with a normalized representation, substrings
+         *        are used to represent the significand and exponent fields. The
+         *        significand is represented by the characters "0x1." followed by a
+         *        lowercase hexadecimal representation of the rest of the
+         *        significand as a fraction. Trailing zeros in the hexadecimal
+         *        representation are removed unless all the digits are zero, in which
+         *        case a single zero is used. Next, the exponent is represented by
+         *        "p" followed by a decimal string of the unbiased exponent as if
+         *        produced by a call to Integer.toString on the exponent value.
+         *      o If m is a float value with a subnormal representation, the
+         *        significand is represented by the characters "0x0." followed by a
+         *        hexadecimal representation of the rest of the significand as a
+         *        fraction. Trailing zeros in the hexadecimal representation are
+         *        removed. Next, the exponent is represented by "p-126". Note that
+         *        there must be at least one nonzero digit in a subnormal significand.
+         *
+         * @param value - The float to convert to a string
+         * @returns the Hex formatted float string.
+         */
+        static std::string toHexString( float value );
+
+        /**
+         * Returns a string representation of the float  argument. All characters
+         * mentioned below are ASCII characters.
+         *
+         * If the argument is NaN, the result is the string "NaN".
+         * Otherwise, the result is a string that represents the sign and magnitude
+         * (absolute value) of the argument. If the sign is negative, the first
+         * character of the result is '-'; if the sign is positive, no
+         * sign character appears in the result. As for the magnitude m:
+         *  o If m is infinity, it is represented by the characters "Infinity"; thus,
+         *    positive infinity produces the result "Infinity" and negative infinity
+         *    produces the result "-Infinity".
+         *  o If m is zero, it is represented by the characters "0.0"; thus, negative
+         *    zero produces the result "-0.0" and positive zero produces the result
+         *    "0.0".
+         *  o If m is greater than or equal to 10-3 but less than 107, then it is
+         *    represented as the integer part of m, in decimal form with no leading
+         *    zeroes, followed by '.', followed by one or more decimal digits
+         *    representing the fractional part of m.
+         *  o If m is less than 10-3 or greater than or equal to 107, then it is
+         *    represented in so-called "computerized scientific notation." Let n be
+         *    the unique integer such that 10n <= m < 10n+1; then let a be the
+         *    mathematically exact quotient of m and 10n so that 1 <= a < 10.
+         *    The magnitude is then represented as the integer part of a, as a
+         *    single decimal digit, followed by '.', followed by decimal digits
+         *    representing the fractional part of a, followed by the letter 'E',
+         *    followed by a representation of n as a decimal integer, as produced
+         *    by the method Integer.toString(int).
+         * @param value - The float to convert to a string
+         * @returns the formatted float string.
+         */
+        static std::string toString( float value );
+
+        /**
+         * Returns a Float instance representing the specified float value.
+         * @param value - float to wrap
+         * @returns new Float instance wrapping the primitive value
+         */
+        static Float valueOf( float value );
+
+        /**
+         * Returns a Float instance that wraps a primtive float which is parsed
+         * from the string value passed.
+         *
+         * @param value - the string to parse
+         * @returns a new Float instance wrapping the float parsed from value
+         * @throws NumberFormatException on error.
+         */
+        static Float valueOf( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+    private:
+
+        static const unsigned int SINGLE_EXPONENT_MASK = 0x7F800000;
+        static const unsigned int SINGLE_MANTISSA_MASK = 0x007FFFFF;
+        static const unsigned int SINGLE_NAN_BITS = (SINGLE_EXPONENT_MASK | 0x00400000);
+
+    };
+
+}}
+
+#endif /*_DECAF_LANG_FLOAT_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,475 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Character.h>
+#include <sstream>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Integer::Integer( int value ) {
+    this->value = value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer::Integer( const std::string& value ) throw( exceptions::NumberFormatException ) {
+    this->value = parseInt( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::compareTo( const Integer& i ) const {
+    return this->value < i.value ? -1 : this->value == i.value ? 0 : 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::compareTo( const int& i ) const {
+    return this->value < i ? -1 : this->value == i ? 0 : 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::bitCount( int value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+
+    // 32-bit recursive reduction using SWAR...
+    // but first step is mapping 2-bit values
+    // into sum of 2 1-bit values in sneaky way
+    uvalue -= ((uvalue >> 1) & 0x55555555);
+    uvalue = (((uvalue >> 2) & 0x33333333) + (uvalue & 0x33333333));
+    uvalue = (((uvalue >> 4) + uvalue) & 0x0F0F0F0F);
+    uvalue += (uvalue >> 8);
+    uvalue += (uvalue >> 16);
+    return(uvalue & 0x0000003F);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::reverseBytes( int value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+
+    unsigned int b3 = uvalue >> 24;
+    unsigned int b2 = (uvalue >> 8) & 0xFF00;
+    unsigned int b1 = (uvalue & 0xFF00) << 8;
+    unsigned int b0 = uvalue << 24;
+    return (b0 | b1 | b2 | b3);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::reverse( int value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+
+    uvalue = (((uvalue & 0xAAAAAAAA) >> 1) | ((uvalue & 0x55555555) << 1));
+    uvalue = (((uvalue & 0xCCCCCCCC) >> 2) | ((uvalue & 0x33333333) << 2));
+    uvalue = (((uvalue & 0xF0F0F0F0) >> 4) | ((uvalue & 0x0F0F0F0F) << 4));
+    uvalue = (((uvalue & 0xFF00FF00) >> 8) | ((uvalue & 0x00FF00FF) << 8));
+    return ((uvalue >> 16) | (uvalue << 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 ) {
+
+    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++;
+    }
+
+    // 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 Integer::toBinaryString( int value ) {
+
+    int count = 1;
+    int 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 Integer::toOctalString( int value ) {
+
+    int count = 1, 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 Integer::toHexString( int value ) {
+
+    int count = 1;
+    int 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::parseInt( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Integer::parseInt( value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::parseInt( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    if( radix < Character::MIN_RADIX ||
+        radix > Character::MAX_RADIX ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid radix" );
+    }
+
+    int length = (int)value.length(), i = 0;
+    if( length == 0 ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid: zero length string");
+    }
+
+    bool negative = value[i] == '-';
+    if( negative && ++i == length ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid only a minus sign given");
+    }
+
+    return Integer::parse( value, i, radix, negative );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::valueOf( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Integer( Integer::parseInt( value ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::valueOf( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Integer( Integer::parseInt( value, radix ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::decode( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    int length = (int)value.length(), i = 0;
+    if( length == 0 ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid zero size string");
+    }
+
+    char firstDigit = value[i];
+    bool negative = firstDigit == '-';
+    if( negative ) {
+        if( length == 1 ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer:decode - Invalid zero string, minus only");
+        }
+
+        firstDigit = value[++i];
+    }
+
+    int base = 10;
+    if( firstDigit == '0' ) {
+        if( ++i == length ) {
+            return valueOf( 0 );
+        }
+
+        if( ( firstDigit = value[i] ) == 'x' || firstDigit == 'X' ) {
+            if( i == length ) {
+                throw NumberFormatException(
+                    __FILE__, __LINE__,
+                    "Integer:decode - Invalid zero string, minus only");
+            }
+            i++;
+            base = 16;
+        } else {
+            base = 8;
+        }
+    } else if( firstDigit == '#' ) {
+        if( i == length ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer:decode - Invalid zero string, minus only");
+        }
+        i++;
+        base = 16;
+    }
+
+    int result = parse( value, i, base, negative );
+    return valueOf( result );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+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 = (int)value.size();
+
+    while( offset < length ) {
+        int digit = Character::digit( value[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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::highestOneBit( int value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+
+    uvalue |= (uvalue >> 1);
+    uvalue |= (uvalue >> 2);
+    uvalue |= (uvalue >> 4);
+    uvalue |= (uvalue >> 8);
+    uvalue |= (uvalue >> 16);
+    return ( uvalue & ~(uvalue >> 1));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::lowestOneBit( int value ) {
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+    return ( uvalue & (-uvalue) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::numberOfLeadingZeros( int value ) {
+
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+
+    value |= value >> 1;
+    value |= value >> 2;
+    value |= value >> 4;
+    value |= value >> 8;
+    value |= value >> 16;
+    return Integer::bitCount( ~uvalue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::numberOfTrailingZeros( int value ) {
+    if( value == 0 ) {
+        return 0;
+    }
+
+    unsigned int uvalue = (unsigned int)value;
+    return bitCount( (uvalue & -uvalue) - 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::rotateLeft( int value, int distance ) {
+    unsigned int i = (unsigned int)value;
+    int j = distance & 0x1F;
+    return ( i << j ) | ( i >> (-j & 0x1F ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::rotateRight( int value, int distance ) {
+    unsigned int i = (unsigned int)value;
+    int j = distance & 0x1F;
+    return ( i >> j ) | ( i << (-j & 0x1F ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::signum( int value ) {
+    return ( value == 0 ? 0 : ( value < 0 ? -1 : 1 ) );
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Integer.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,516 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_INTEGER_H_
+#define _DECAF_LANG_INTEGER_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/lang/Number.h>
+#include <decaf/lang/Comparable.h>
+#include <string>
+#include <decaf/lang/exceptions/NumberFormatException.h>
+
+namespace decaf{
+namespace lang{
+
+    class DECAF_API Integer : public Number,
+                              public Comparable<Integer>,
+                              public Comparable<int> {
+    private:
+
+        // The primitve Integer value.
+        int value;
+
+    public:
+
+        /** The size in bits of the primitive int type */
+        static const int SIZE = 32;
+
+        /** The maximum value that the primitive type can hold */
+        static const int MAX_VALUE = (int)0x7FFFFFFF;
+
+        /** The minimum value that the primitive type can hold */
+        static const int MIN_VALUE = (int)0x80000000;
+
+    public:
+
+        /**
+         * @param the primitive value to wrap
+         */
+        Integer( int value );
+
+        /**
+         * @param the base 10 encoded string to decode to sn int and wrap.
+         * @throws NumberFormatException
+         */
+        Integer( const std::string& value ) throw( exceptions::NumberFormatException );
+
+        virtual ~Integer() {}
+
+        /**
+         * Compares this Integer instance with another.
+         * @param i - 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 Integer& i ) const;
+
+        /**
+         * @param i - the Integer object to compare against.
+         * @returns true if the two Integer Objects have the same value.
+         */
+        bool equals( const Integer& i ) const {
+            return this->value == i.value;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param i - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const Integer& i ) const {
+            return this->value == i.value;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param i - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const Integer& i ) const {
+            return this->value < i.value;
+        }
+
+        /**
+         * Compares this Integer instance with another.
+         * @param i - 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 int& i ) const;
+
+        /**
+         * @param i - the Integer object to compare against.
+         * @returns true if the two Integer Objects have the same value.
+         */
+        bool equals( const int& i ) const {
+            return this->value == i;
+        }
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param i - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const int& i ) const {
+            return this->value == i;
+        }
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param i - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const int& i ) const {
+            return this->value < i;
+        }
+
+        /**
+         * @returns this Interger 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 this->value;
+        }
+
+        /**
+         * Answers the long value which the receiver represents
+         * @return long the value of the receiver.
+         */
+        virtual long long longValue() const {
+            return (long long)this->value;
+        }
+
+    public:  // Statics
+
+        /**
+         * Decodes a String into a Integer. 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 Integer object containing the decoded value
+         * @throws NumberFomatException if the string is not formatted correctly.
+         */
+        static Integer decode( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns the value obtained by reversing the order of the bytes in the
+         * two's complement representation of the specified int value.
+         * @param value - the int whose bytes we are to reverse
+         * @return the reversed int.
+         */
+        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
+         * Character.digit(char, int) returns a nonnegative value) except that the
+         * first character may be an ASCII minus sign '-' to indicate a negative
+         * value. The resulting byte value is returned.
+         *
+         * An exception of type NumberFormatException is thrown if any of the
+         * following situations occurs:
+         *  * The first argument is null or is a string of length zero.
+         *  * The radix is either smaller than Character.MIN_RADIX or larger than
+         *    Character.MAX_RADIX.
+         *  * Any character of the string is not a digit of the specified radix,
+         *    except that the first character may be a minus sign '-' ('\u002D')
+         *    provided that the string is longer than length 1.
+         *  * The value represented by the string is not a value of type int.
+         *
+         * @param s - the String containing the int representation to be parsed
+         * @param radix - the radix to be used while parsing s
+         * @return the int represented by the string argument in the specified radix.
+         * @throws NumberFormatException - If String does not contain a parsable int.
+         */
+        static int parseInt( const std::string& s, int radix )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Parses the string argument as a signed decimal int. The characters
+         * in the string must all be decimal digits, except that the first
+         * character may be an ASCII minus sign '-' ('\u002D') to indicate a
+         * negative value. The resulting int value is returned, exactly as if
+         * the argument and the radix 10 were given as arguments to the
+         * parseInteger( const std::string, int ) method.
+         * @param s - String to convert to a int
+         * @returns the converted int value
+         * @throws NumberFormatException if the string is not a int.
+         */
+        static int parseInt( const std::string& s )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a Integer instance representing the specified int value.
+         * @param value - the int to wrap
+         * @return the new Integer object wrapping value.
+         */
+        static Integer valueOf( int value ) {
+            return Integer( value );
+        }
+
+        /**
+         * Returns a Integer object holding the value given by the specified
+         * std::string.  The argument is interpreted as representing a signed
+         * decimal int, exactly as if the argument were given to the
+         * parseInt( std::string ) method. The result is a Integer object that
+         * represents the int value specified by the string.
+         * @param value - std::string to parse as base 10
+         * @return new Integer Object wrapping the primitive
+         * @throws NumberFormatException if the string is not a decimal int.
+         */
+        static Integer valueOf( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a Integer 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 int in the
+         * radix specified by the second argument, exactly as if the argument were
+         * given to the parseInt( std::string, int ) method. The result is a
+         * Integer object that represents the int value specified by the string.
+         * @param value - std::string to parse as base ( radix )
+         * @param radix - base of the string to parse.
+         * @return new Integer Object wrapping the primitive
+         * @throws NumberFormatException if the string is not a valid int.
+         */
+        static Integer valueOf( const std::string& value, int radix )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * 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 int to count
+         * @return the number of one-bits in the two's complement binary
+         * representation of the specified int value.
+         */
+        static int bitCount( int value );
+
+        /**
+         * Converts the int to a String representation
+         * @param int to convert
+         * @return string representation
+         */
+        static std::string toString( int 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 int to convert to a string
+         * @param radix - the radix to format the string in
+         * @returns an int formatted to the string value of the radix given.
+         */
+        static std::string toString( int 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 int to be translated to an Octal string
+         * @returns the unsigned int value as a Octal string
+         */
+        static std::string toHexString( int value );
+
+        /**
+         * Returns a string representation of the integer argument as an unsigned
+         * integer in base 8.
+         *
+         * 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 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 int to be translated to an Octal string
+         * @returns the unsigned int value as a Octal string
+         */
+        static std::string toOctalString( int value );
+
+        /**
+         * Returns a string representation of the integer argument as an unsigned
+         * integer in base 2.
+         *
+         * 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 binary (base 2) with no extra leading 0s.
+         * If the unsigned magnitude is zero, it is represented by a single zero
+         * character '0' ('\u0030'); otherwise, the first character of the
+         * representation of the unsigned magnitude will not be the zero character.
+         * The characters '0' ('\u0030') and '1' ('\u0031') are used as binary
+         * digits.
+         * @param value - the int to be translated to a binary string
+         * @returns the unsigned int value as a binary string
+         */
+        static std::string toBinaryString( int value );
+
+        /**
+         * Returns an int 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 int to be inspected
+         * @return an int 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 int highestOneBit( int value );
+
+        /**
+         * Returns an int 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 int to be inspected
+         * @return an int 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 int lowestOneBit( int value );
+
+        /**
+         * Returns the number of zero bits preceding the highest-order ("leftmost")
+         * one-bit in the two's complement binary representation of the specified
+         * int value. Returns 32 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)) = 31 - numberOfLeadingZeros(x)
+         *     * ceil( log2(x)) = 32 - numberOfLeadingZeros(x - 1)
+         *
+         * @param value - the int 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
+         * int value, or 32 if the value is equal to zero.
+         */
+        static int numberOfLeadingZeros( int value );
+
+        /**
+         * Returns the number of zero bits following the lowest-order ("rightmost")
+         * one-bit in the two's complement binary representation of the specified
+         * int value. Returns 32 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
+         * int value, or 32 if the value is equal to zero.
+         */
+        static int numberOfTrailingZeros( int value );
+
+        /**
+         * Returns the value obtained by rotating the two's complement binary
+         * representation of the specified int 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 int 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 int value left by the specified number
+         * of bits.
+         */
+        static int rotateLeft( int value, int distance );
+
+        /**
+         * Returns the value obtained by rotating the two's complement binary
+         * representation of the specified int 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 int 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 int value right by the specified number
+         * of bits.
+         */
+        static int rotateRight( int value, int distance );
+
+        /**
+         * Returns the signum function of the specified int 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 int to be inspected
+         * @return the signum function of the specified int value.
+         */
+        static int signum( int value );
+
+    private:
+
+        static int parse( const std::string& value, int offset,
+                          int radix, bool negative )
+            throw ( exceptions::NumberFormatException );
+
+    };
+
+}}
+
+#endif /*_DECAF_LANG_INTEGER_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/lang/Iterable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Iterable.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Iterable.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Iterable.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_ITERABLE_H_
+#define _DECAF_LANG_ITERABLE_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace lang{
+
+    /**
+     * Implementing this interface allows an object to be cast to an Iterable
+     * type for generic collections API calls.
+     */
+    template< typename T >
+    class DECAF_API Iterable {
+    public:
+
+        virtual ~Iterable() {}
+
+        /**
+         * @returns an iterator over a set of elements of type T.
+         */
+        T iterator() = 0;
+        const T iterator() = 0;
+
+    };
+
+}}
+
+#endif /*_DECAF_LANG_ITERABLE_H_*/