Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates

  • Loading branch information...
commit 76ec5822fdf4c4ce991e0c0468a0d19258021840 1 parent 792d16f
@tabish121 tabish121 authored
Showing with 644 additions and 548 deletions.
  1. +1 −0  activemq-cpp/src/main/Makefile.am
  2. +3 −8 activemq-cpp/src/main/decaf/lang/Appendable.h
  3. +3 −3 activemq-cpp/src/main/decaf/lang/Boolean.cpp
  4. +4 −4 activemq-cpp/src/main/decaf/lang/Boolean.h
  5. +22 −23 activemq-cpp/src/main/decaf/lang/Byte.cpp
  6. +40 −18 activemq-cpp/src/main/decaf/lang/Byte.h
  7. +75 −68 activemq-cpp/src/main/decaf/lang/Double.cpp
  8. +49 −38 activemq-cpp/src/main/decaf/lang/Double.h
  9. +78 −75 activemq-cpp/src/main/decaf/lang/Float.cpp
  10. +50 −37 activemq-cpp/src/main/decaf/lang/Float.h
  11. +120 −122 activemq-cpp/src/main/decaf/lang/Integer.cpp
  12. +16 −10 activemq-cpp/src/main/decaf/lang/Integer.h
  13. +24 −17 activemq-cpp/src/main/decaf/lang/Long.cpp
  14. +23 −16 activemq-cpp/src/main/decaf/lang/Long.h
  15. +1 −1  activemq-cpp/src/main/decaf/lang/Number.h
  16. +34 −33 activemq-cpp/src/main/decaf/lang/Short.cpp
  17. +50 −33 activemq-cpp/src/main/decaf/lang/Short.h
  18. +2 −1  activemq-cpp/src/main/decaf/lang/StringBuffer.h
  19. +5 −0 activemq-cpp/src/main/decaf/lang/StringBuilder.cpp
  20. +4 −1 activemq-cpp/src/main/decaf/lang/StringBuilder.h
  21. +13 −13 activemq-cpp/src/main/decaf/util/Arrays.h
  22. +27 −27 activemq-cpp/src/test/testRegistry.cpp
View
1  activemq-cpp/src/main/Makefile.am
@@ -458,6 +458,7 @@ cc_sources = \
decaf/lang/Iterable.cpp \
decaf/lang/Long.cpp \
decaf/lang/Math.cpp \
+ decaf/lang/Number.cpp \
decaf/lang/Readable.cpp \
decaf/lang/Runnable.cpp \
decaf/lang/Runtime.cpp \
View
11 activemq-cpp/src/main/decaf/lang/Appendable.h
@@ -31,11 +31,6 @@ namespace lang {
* must be implemented by any class whose instances are intended to receive formatted
* output from a Formatter.
*
- * TODO
- * The characters to be appended should be valid Unicode characters as described in Unicode
- * Character Representation. Note that supplementary characters may be composed of multiple
- * 16-bit char values.
- *
* Appendables are not necessarily safe for multithreaded access. Thread safety is the
* responsibility of classes that extend and implement this interface.
*
@@ -59,7 +54,7 @@ namespace lang {
*
* @throws Exception if an error occurs.
*/
- virtual Appendable& append( char value ) = 0;
+ virtual Appendable& append(char value) = 0;
/**
* Appends the specified character sequence to this Appendable.
@@ -73,7 +68,7 @@ namespace lang {
*
* @throws Exception if an error occurs.
*/
- virtual Appendable& append( const CharSequence* csq ) = 0;
+ virtual Appendable& append(const CharSequence* csq) = 0;
/**
* Appends a subsequence of the specified character sequence to this Appendable.
@@ -92,7 +87,7 @@ namespace lang {
* @throws IndexOutOfBoundsException start is greater than end, or end is
* greater than csq.length()
*/
- virtual Appendable& append( const CharSequence* csq, int start, int end ) = 0;
+ virtual Appendable& append(const CharSequence* csq, int start, int end) = 0;
};
View
6 activemq-cpp/src/main/decaf/lang/Boolean.cpp
@@ -34,7 +34,7 @@ Boolean::Boolean(bool value) : value(value) {
}
////////////////////////////////////////////////////////////////////////////////
-Boolean::Boolean(const std::string& value) : value(false) {
+Boolean::Boolean(const String& value) : value(false) {
this->value = parseBoolean(value);
}
@@ -86,7 +86,7 @@ std::string Boolean::toString() const {
}
////////////////////////////////////////////////////////////////////////////////
-Boolean Boolean::valueOf(const std::string& value) {
+Boolean Boolean::valueOf(const String& value) {
return Boolean(value);
}
@@ -96,7 +96,7 @@ Boolean Boolean::valueOf(bool value) {
}
////////////////////////////////////////////////////////////////////////////////
-bool Boolean::parseBoolean(const std::string& value) {
+bool Boolean::parseBoolean(const String& value) {
return StringUtils::compareIgnoreCase(value.c_str(), "true") == 0;
}
View
8 activemq-cpp/src/main/decaf/lang/Boolean.h
@@ -19,6 +19,7 @@
#define _DECAF_LANG_BOOLEAN_H_
#include <string>
+#include <decaf/lang/String.h>
#include <decaf/lang/Comparable.h>
#include <decaf/util/Config.h>
@@ -54,7 +55,7 @@ namespace lang{
/**
* @param value - String value to convert to a boolean.
*/
- Boolean(const std::string& value);
+ Boolean(const String& value);
virtual ~Boolean() {}
@@ -135,7 +136,6 @@ namespace lang{
}
public:
- // Statics
/**
* @param value
@@ -151,7 +151,7 @@ namespace lang{
*
* @returns a Boolean instance of the string value
*/
- static Boolean valueOf(const std::string& value);
+ static Boolean valueOf(const String& value);
/**
* Parses the String passed and extracts an bool.
@@ -160,7 +160,7 @@ namespace lang{
* The std::string value to parse
* @return bool value
*/
- static bool parseBoolean(const std::string& value);
+ static bool parseBoolean(const String& value);
/**
* Converts the bool to a String representation.
View
45 activemq-cpp/src/main/decaf/lang/Byte.cpp
@@ -29,63 +29,62 @@ const unsigned char Byte::MAX_VALUE = 0x80;
const int Byte::SIZE = 8;
////////////////////////////////////////////////////////////////////////////////
-Byte::Byte( unsigned char value ) : value(value) {
+Byte::Byte(unsigned char value) : value(value) {
}
////////////////////////////////////////////////////////////////////////////////
-Byte::Byte( const std::string& value ) : value(0) {
- this->value = parseByte( value );
+Byte::Byte(const String& value) : value(0) {
+ this->value = parseByte(value);
}
////////////////////////////////////////////////////////////////////////////////
std::string Byte::toString() const {
- return Integer::toString( value );
+ return Integer::toString(value);
}
////////////////////////////////////////////////////////////////////////////////
-std::string Byte::toString( unsigned char value ) {
- return Integer::toString( value );
+std::string Byte::toString(unsigned char value) {
+ return Integer::toString(value);
}
////////////////////////////////////////////////////////////////////////////////
-unsigned char Byte::parseByte( const std::string& s, int radix ) {
+unsigned char Byte::parseByte(const String& s, int radix) {
- int intValue = Integer::parseInt( s, radix );
- unsigned char result = (unsigned char)intValue;
- if( result != intValue ) {
+ int intValue = Integer::parseInt(s, radix);
+ unsigned char result = (unsigned char) intValue;
+ if (result != intValue) {
throw NumberFormatException(
- __FILE__, __LINE__,
- "Byte::parseByte - Not a valid unsigned char encoded string.");
+ __FILE__, __LINE__, "Byte::parseByte - Not a valid unsigned char encoded string.");
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
-unsigned char Byte::parseByte( const std::string& s ) {
- return parseByte( s, 10 );
+unsigned char Byte::parseByte(const String& s) {
+ return parseByte(s, 10);
}
////////////////////////////////////////////////////////////////////////////////
-Byte Byte::decode( const std::string& value ) {
+Byte Byte::decode(const String& value) {
- int intValue = Integer::decode( value ).intValue();
- unsigned char result = (unsigned char)intValue;
- if( result != intValue ) {
+ int intValue = Integer::decode(value).intValue();
+ unsigned char result = (unsigned char) intValue;
+ if (result != intValue) {
throw NumberFormatException(
__FILE__, __LINE__,
"Byte::decode - Not a valid unsigned char encoded string.");
}
- return Byte( result );
+ return Byte(result);
}
////////////////////////////////////////////////////////////////////////////////
-Byte Byte::valueOf( const std::string& value ) {
- return Byte( parseByte( value, 10 ) );
+Byte Byte::valueOf(const String& value) {
+ return Byte(parseByte(value, 10));
}
////////////////////////////////////////////////////////////////////////////////
-Byte Byte::valueOf( const std::string& value, int radix ) {
- return Byte( parseByte( value, radix ) );
+Byte Byte::valueOf(const String& value, int radix) {
+ return Byte(parseByte(value, radix));
}
View
58 activemq-cpp/src/main/decaf/lang/Byte.h
@@ -20,12 +20,13 @@
#include <decaf/util/Config.h>
#include <decaf/lang/Number.h>
+#include <decaf/lang/String.h>
#include <decaf/lang/Comparable.h>
#include <decaf/lang/exceptions/NumberFormatException.h>
#include <string>
-namespace decaf{
-namespace lang{
+namespace decaf {
+namespace lang {
class DECAF_API Byte : public Number,
public Comparable<Byte>,
@@ -60,7 +61,7 @@ namespace lang{
*
* @throws NumberFormatException if the string is not a valid byte.
*/
- Byte(const std::string& value);
+ Byte(const String& value);
virtual ~Byte() {}
@@ -193,7 +194,7 @@ namespace lang{
return (long long) this->value;
}
- public: // statics
+ public:
/**
* @returns a string representing the primitive value as Base 10
@@ -211,11 +212,15 @@ namespace lang{
* 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
+ *
+ * @param value
+ * The string to decode
+ *
* @returns a Byte object containing the decoded value
+ *
* @throws NumberFomatException if the string is not formatted correctly.
*/
- static Byte decode(const std::string& value);
+ static Byte decode(const String& value);
/**
* Parses the string argument as a signed unsigned char in the radix specified by
@@ -235,14 +240,17 @@ namespace lang{
* that the string is longer than length 1.
* * The value represented by the string is not a value of type unsigned char.
*
- * @param s - the String containing the unsigned char to be parsed
- * @param radix - the radix to be used while parsing s
+ * @param s
+ * The String containing the unsigned char to be parsed
+ * @param radix
+ * The radix to be used while parsing s
+ *
* @return the unsigned char represented by the string argument in the
* specified radix.
* @throws NumberFormatException - If String does not contain a parsable
* unsigned char.
*/
- static unsigned char parseByte(const std::string& s, int radix);
+ static unsigned char parseByte(const String& s, int radix);
/**
* Parses the string argument as a signed decimal unsigned char. The
@@ -250,16 +258,23 @@ namespace lang{
* first character may be an ASCII minus sign '-' to indicate a
* negative value. The resulting unsigned char value is returned, exactly as
* if the argument and the radix 10 were given as arguments to the
- * parseByte( const std::string, int ) method.
- * @param s - String to convert to a unsigned char
+ * parseByte(const String, int) method.
+ *
+ * @param s
+ * String to convert to a unsigned char
+ *
* @returns the converted unsigned char value
+ *
* @throws NumberFormatException if the string is not a unsigned char.
*/
- static unsigned char parseByte(const std::string& s);
+ static unsigned char parseByte(const String& s);
/**
* Returns a Character instance representing the specified char value.
- * @param value - the primitive char to wrap.
+ *
+ * @param value
+ * The primitive char to wrap.
+ *
* @returns a new Character instance that wraps this value.
*/
static Byte valueOf(unsigned char value) {
@@ -272,11 +287,14 @@ namespace lang{
* exactly as if the argument were given to the parseByte( std::string )
* method. The result is a Byte object that represents the unsigned char value
* specified by the string.
- * @param value - std::string to parse as base 10
+ *
+ * @param value
+ * String to parse as base 10
+ *
* @return new Byte Object wrapping the primitive
* @throws NumberFormatException if the string is not a decimal unsigned char.
*/
- static Byte valueOf(const std::string& value);
+ static Byte valueOf(const String& value);
/**
* Returns a Byte object holding the value extracted from the specified
@@ -286,12 +304,16 @@ namespace lang{
* were given to the parseByte( std::string, int ) method. The result is a
* Byte object that represents the unsigned char value specified by the
* string.
- * @param value - std::string to parse as base ( radix )
- * @param radix - base of the string to parse.
+ * @param value
+ * String to parse as base ( radix )
+ * @param radix
+ * Base of the string to parse.
+ *
* @return new Byte Object wrapping the primitive
+ *
* @throws NumberFormatException if the string is not a valid unsigned char.
*/
- static Byte valueOf(const std::string& value, int radix);
+ static Byte valueOf(const String& value, int radix);
};
View
143 activemq-cpp/src/main/decaf/lang/Double.cpp
@@ -17,6 +17,7 @@
#include "Double.h"
#include <decaf/lang/Long.h>
+#include <decaf/lang/ArrayPointer.h>
#include <limits>
#include <sstream>
#include <string.h>
@@ -34,59 +35,64 @@ const double Double::NaN = std::numeric_limits<double>::quiet_NaN();
const double Double::POSITIVE_INFINITY = std::numeric_limits<double>::infinity();
const double Double::NEGATIVE_INFINITY = -std::numeric_limits<double>::infinity();
+const long long Double::DOUBLE_SIGN_MASK = 0x8000000000000000LL;
+const long long Double::DOUBLE_EXPONENT_MASK = 0x7FF0000000000000LL;
+const long long Double::DOUBLE_MANTISSA_MASK = 0x000FFFFFFFFFFFFFLL;
+const long long Double::DOUBLE_NAN_BITS = DOUBLE_EXPONENT_MASK | 0x0008000000000000LL;
+
////////////////////////////////////////////////////////////////////////////////
-Double::Double( double value ) :value(value) {
+Double::Double(double value) : value(value) {
}
////////////////////////////////////////////////////////////////////////////////
-Double::Double( const std::string& value ) : value(0) {
- this->value = Double::parseDouble( value );
+Double::Double(const String& value) : value(0) {
+ this->value = Double::parseDouble(value);
}
////////////////////////////////////////////////////////////////////////////////
-int Double::compareTo( const Double& d ) const {
- return Double::compare( this->value, d.value );
+int Double::compareTo(const Double& d) const {
+ return Double::compare(this->value, d.value);
}
////////////////////////////////////////////////////////////////////////////////
-int Double::compareTo( const double& d ) const {
- return Double::compare( this->value, d );
+int Double::compareTo(const double& d) const {
+ return Double::compare(this->value, d);
}
////////////////////////////////////////////////////////////////////////////////
std::string Double::toString() const {
- return Double::toString( this->value );
+ return Double::toString(this->value);
}
////////////////////////////////////////////////////////////////////////////////
bool Double::isInfinite() const {
- return Double::isInfinite( this->value );
+ return Double::isInfinite(this->value);
}
////////////////////////////////////////////////////////////////////////////////
bool Double::isNaN() const {
- return Double::isNaN( this->value );
+ return Double::isNaN(this->value);
}
////////////////////////////////////////////////////////////////////////////////
-int Double::compare( double d1, double d2 ) {
+int Double::compare(double d1, double d2) {
long long l1, l2 = 0;
- long long NaNbits = Double::doubleToLongBits( Double::NaN );
+ long long NaNbits = Double::doubleToLongBits(Double::NaN);
- if( ( l1 = Double::doubleToLongBits( d1 ) ) == NaNbits ) {
- if( Double::doubleToLongBits( d2 ) == NaNbits ) {
+ if ((l1 = Double::doubleToLongBits(d1)) == NaNbits) {
+ if (Double::doubleToLongBits(d2) == NaNbits) {
return 0;
}
return 1;
}
- if( ( l2 = Double::doubleToLongBits( d2 ) ) == NaNbits ) {
+ if ((l2 = Double::doubleToLongBits(d2)) == NaNbits) {
return -1;
}
- if( d1 == d2 ) {
- if( l1 == l2 ) {
+ if (d1 == d2) {
+ if (l1 == l2) {
return 0;
}
@@ -98,13 +104,13 @@ int Double::compare( double d1, double d2 ) {
}
////////////////////////////////////////////////////////////////////////////////
-long long Double::doubleToLongBits( double value ) {
+long long Double::doubleToLongBits(double value) {
long long longValue = 0;
- memcpy( &longValue, &value, sizeof( double ) );
+ memcpy(&longValue, &value, sizeof(double));
- if( ( longValue & DOUBLE_EXPONENT_MASK ) == DOUBLE_EXPONENT_MASK ) {
- if( longValue & DOUBLE_MANTISSA_MASK ) {
+ if ((longValue & DOUBLE_EXPONENT_MASK) == DOUBLE_EXPONENT_MASK) {
+ if (longValue & DOUBLE_MANTISSA_MASK) {
return DOUBLE_NAN_BITS;
}
}
@@ -113,135 +119,137 @@ long long Double::doubleToLongBits( double value ) {
}
////////////////////////////////////////////////////////////////////////////////
-long long Double::doubleToRawLongBits( double value ) {
+long long Double::doubleToRawLongBits(double value) {
long long longValue = 0;
- memcpy( &longValue, &value, sizeof( double ) );
+ memcpy(&longValue, &value, sizeof(double));
return longValue;
}
////////////////////////////////////////////////////////////////////////////////
-bool Double::isInfinite( double value ) {
- return ( value == POSITIVE_INFINITY ) || ( value == NEGATIVE_INFINITY );
+bool Double::isInfinite(double value) {
+ return (value == POSITIVE_INFINITY) || (value == NEGATIVE_INFINITY);
}
////////////////////////////////////////////////////////////////////////////////
-bool Double::isNaN( double value ) {
+bool Double::isNaN(double value) {
return value != value;
}
////////////////////////////////////////////////////////////////////////////////
-double Double::longBitsToDouble( long long bits ) {
+double Double::longBitsToDouble(long long bits) {
double result = 0;
- memcpy( &result, &bits, sizeof( long long ) );
+ memcpy(&result, &bits, sizeof(long long));
return result;
}
////////////////////////////////////////////////////////////////////////////////
-double Double::parseDouble( const std::string value ) {
+double Double::parseDouble(const String& value) {
// TODO - This is not going to parse the formats we say we do.
float result = 0.0;
- istringstream stream( value );
+ ArrayPointer<char> buffer(value.length() + 1);
+ value.getChars(0, value.length(), buffer.get(), value.length() + 1, 0);
+
+ istringstream stream(buffer.get());
stream >> result;
// Not everything got read, meaning there wasn't just a number here.
- if( !stream.eof() ) {
+ if (!stream.eof()) {
throw exceptions::NumberFormatException(
- __FILE__, __LINE__,
- "Failed to parse a valid float from input string: %s", value.c_str() );
+ __FILE__, __LINE__, "Failed to parse a valid float from input string: %s", value.c_str());
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Double::toHexString( double value ) {
+std::string Double::toHexString(double value) {
/*
* Reference: http://en.wikipedia.org/wiki/IEEE_754
*/
- if( value != value ) {
+ if (value != value) {
return "NaN";
}
- if( value == POSITIVE_INFINITY ) {
+ if (value == POSITIVE_INFINITY) {
return "Infinity";
}
- if( value == NEGATIVE_INFINITY ) {
+ if (value == NEGATIVE_INFINITY) {
return "-Infinity";
}
- unsigned long long bitValue = Double::doubleToLongBits( value );
+ unsigned long long bitValue = Double::doubleToLongBits(value);
- bool negative = ( bitValue & 0x8000000000000000LL ) != 0;
+ bool negative = (bitValue & 0x8000000000000000LL) != 0;
// mask exponent bits and shift down
- unsigned long long exponent = ( bitValue & 0x7FF0000000000000LL ) >> 52;
+ unsigned long long exponent = (bitValue & 0x7FF0000000000000LL) >> 52;
// mask significand bits and shift up
unsigned long long significand = bitValue & 0x000FFFFFFFFFFFFFLL;
- if( exponent == 0 && significand == 0 ) {
- return ( negative ? "-0x0.0p0" : "0x0.0p0" );
+ if (exponent == 0 && significand == 0) {
+ return (negative ? "-0x0.0p0" : "0x0.0p0");
}
// Start with sign and hex indicator
- std::string hexString( negative ? "-0x" : "0x" );
+ std::string hexString(negative ? "-0x" : "0x");
- if( exponent == 0 ) {
+ if (exponent == 0) {
// denormal (subnormal) value
hexString.append("0.");
// significand is 52-bits, so there can be 13 hex digits
unsigned int fractionDigits = 13;
// remove trailing hex zeros, so Integer.toHexString() won't print
// them
- while( ( significand != 0 ) && ( ( significand & 0xF ) == 0 ) ) {
+ while ((significand != 0) && ((significand & 0xF) == 0)) {
significand >>= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
- std::string hexSignificand = Long::toHexString( significand );
+ std::string hexSignificand = Long::toHexString(significand);
// if there are digits left, then insert some '0' chars first
- if( significand != 0 && fractionDigits > hexSignificand.length() ) {
- int digitDiff = fractionDigits - (int)hexSignificand.length();
- while( digitDiff-- != 0 ) {
- hexString.append( "0" );
+ if (significand != 0 && fractionDigits > hexSignificand.length()) {
+ int digitDiff = fractionDigits - (int) hexSignificand.length();
+ while (digitDiff-- != 0) {
+ hexString.append("0");
}
}
- hexString.append( hexSignificand );
- hexString.append( "p-1022" );
+ hexString.append(hexSignificand);
+ hexString.append("p-1022");
} else {
// normal value
- hexString.append( "1." );
+ hexString.append("1.");
// significand is 52-bits, so there can be 13 hex digits
unsigned int fractionDigits = 13;
// remove trailing hex zeros, so Integer.toHexString() won't print
// them
- while( (significand != 0 ) && ( ( significand & 0xF ) == 0 ) ) {
+ while ((significand != 0) && ((significand & 0xF) == 0)) {
significand >>= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
- std::string hexSignificand = Long::toHexString( significand );
+ std::string hexSignificand = Long::toHexString(significand);
// if there are digits left, then insert some '0' chars first
- if( significand != 0 && fractionDigits > hexSignificand.length() ) {
- int digitDiff = fractionDigits - (int)hexSignificand.length();
- while( digitDiff-- != 0 ) {
- hexString.append( "0" );
+ if (significand != 0 && fractionDigits > hexSignificand.length()) {
+ int digitDiff = fractionDigits - (int) hexSignificand.length();
+ while (digitDiff-- != 0) {
+ hexString.append("0");
}
}
- hexString.append( hexSignificand );
- hexString.append( "p" );
+ hexString.append(hexSignificand);
+ hexString.append("p");
// remove exponent's 'bias' and convert to a string
- hexString.append( Long::toString( exponent - 1023 ) );
+ hexString.append(Long::toString(exponent - 1023));
}
return hexString;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Double::toString( double value ) {
+std::string Double::toString(double value) {
// TODO - This is not going to output to the format we say we do.
ostringstream stream;
@@ -251,12 +259,11 @@ std::string Double::toString( double value ) {
}
////////////////////////////////////////////////////////////////////////////////
-Double Double::valueOf( double value ) {
- return Double( value );
+Double Double::valueOf(double value) {
+ return Double(value);
}
////////////////////////////////////////////////////////////////////////////////
-Double Double::valueOf( const std::string& value ) {
-
- return valueOf( parseDouble( value ) );
+Double Double::valueOf(const String& value) {
+ return valueOf(parseDouble(value));
}
View
87 activemq-cpp/src/main/decaf/lang/Double.h
@@ -21,11 +21,12 @@
#include <decaf/util/Config.h>
#include <decaf/lang/Comparable.h>
#include <decaf/lang/Number.h>
+#include <decaf/lang/String.h>
#include <decaf/lang/exceptions/NumberFormatException.h>
#include <string>
-namespace decaf{
-namespace lang{
+namespace decaf {
+namespace lang {
class DECAF_API Double : public Number,
public Comparable<Double>,
@@ -62,7 +63,7 @@ namespace lang{
* @param value
* The primitive type to wrap.
*/
- Double( double value );
+ Double(double value);
/**
* Constructs a new Double and attempts to convert the given string to a double
@@ -74,7 +75,7 @@ namespace lang{
*
* @throws NumberFormatException if the string is not a a valid double.
*/
- Double( const std::string& value );
+ Double(const String& value);
virtual ~Double() {}
@@ -86,13 +87,13 @@ namespace lang{
* than the passed in value, and -1 if this object repesents a value
* less than the passed in value.
*/
- virtual int compareTo( const Double& d ) const;
+ virtual int compareTo(const Double& d) const;
/**
* @param d - the Double object to compare against.
* @returns true if the two Double Objects have the same value.
*/
- bool equals( const Double& d ) const {
+ bool equals(const Double& d) const {
return this->value == d.value;
}
@@ -101,7 +102,7 @@ namespace lang{
* @param d - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator==( const Double& d ) const {
+ virtual bool operator==(const Double& d) const {
return this->value == d.value;
}
@@ -111,7 +112,7 @@ namespace lang{
* @param d - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator<( const Double& d ) const {
+ virtual bool operator<(const Double& d) const {
return this->value < d.value;
}
@@ -123,13 +124,13 @@ namespace lang{
* than the passed in value, and -1 if this object represents a value
* less than the passed in value.
*/
- virtual int compareTo( const double& d ) const;
+ virtual int compareTo(const double& d) const;
/**
* @param d - the Double object to compare against.
* @returns true if the two Double Objects have the same value.
*/
- bool equals( const double& d ) const {
+ bool equals(const double& d) const {
return this->value == d;
}
@@ -138,7 +139,7 @@ namespace lang{
* @param d - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator==( const double& d ) const {
+ virtual bool operator==(const double& d) const {
return this->value == d;
}
@@ -148,7 +149,7 @@ namespace lang{
* @param d - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator<( const double& d ) const {
+ virtual bool operator<(const double& d) const {
return this->value < d;
}
@@ -170,7 +171,7 @@ namespace lang{
* @return float the value of the receiver.
*/
virtual float floatValue() const {
- return (float)this->value;
+ return (float) this->value;
}
/**
@@ -178,7 +179,7 @@ namespace lang{
* @return byte the value of the receiver.
*/
virtual unsigned char byteValue() const {
- return (unsigned char)this->value;
+ return (unsigned char) this->value;
}
/**
@@ -186,7 +187,7 @@ namespace lang{
* @return short the value of the receiver.
*/
virtual short shortValue() const {
- return (short)this->value;
+ return (short) this->value;
}
/**
@@ -194,7 +195,7 @@ namespace lang{
* @return int the value of the receiver.
*/
virtual int intValue() const {
- return (int)this->value;
+ return (int) this->value;
}
/**
@@ -202,7 +203,7 @@ namespace lang{
* @return long the value of the receiver.
*/
virtual long long longValue() const {
- return (long long)this->value;
+ return (long long) this->value;
}
/**
@@ -215,7 +216,7 @@ namespace lang{
*/
bool isNaN() const;
- public: // Statics
+ public:
/**
* Compares the two specified double values. The sign of the integer value
@@ -228,7 +229,7 @@ namespace lang{
* 0 if d1 is numerically less than d2; and a value greater than 0 if d1 is
* numerically greater than d2.
*/
- static int compare( double d1, double d2 );
+ static int compare(double d1, double d2);
/**
* Returns a representation of the specified floating-point value according
@@ -252,7 +253,7 @@ namespace lang{
* @param value - double to be converted
* @returns the long long bits that make up the double
*/
- static long long doubleToLongBits( double value );
+ static long long doubleToLongBits(double value);
/**
* Returns a representation of the specified floating-point value according
@@ -279,19 +280,19 @@ namespace lang{
* @param value - double to be converted
* @returns the long long bits that make up the double
*/
- static long long doubleToRawLongBits( double value );
+ static long long doubleToRawLongBits(double value);
/**
* @param value - The double to check.
* @returns true if the double is equal to infinity.
*/
- static bool isInfinite( double value );
+ static bool isInfinite(double value);
/**
* @param value - The double to check.
* @returns true if the double is equal to NaN.
*/
- static bool isNaN( double value );
+ static bool isNaN(double value);
/**
* Returns the double value corresponding to a given bit representation.
@@ -309,16 +310,20 @@ namespace lang{
* @param bits - the long long bits to convert to double
* @return the double converted from the bits
*/
- static double longBitsToDouble( long long bits );
+ static double longBitsToDouble(long long bits);
/**
* Returns a new double initialized to the value represented by the
* specified string, as performed by the valueOf method of class Double.
- * @param value - The string to parse to an double
+ *
+ * @param value
+ * The string to parse to an double.
+ *
* @returns a double parsed from the passed string
+ *
* @throws NumberFormatException
*/
- static double parseDouble( const std::string value );
+ static double parseDouble(const String& value);
/**
* Returns a hexadecimal string representation of the double argument. All
@@ -354,7 +359,7 @@ namespace lang{
* @param value - The double to convert to a string
* @returns the Hex formatted double string.
*/
- static std::string toHexString( double value );
+ static std::string toHexString(double value);
/**
* Returns a string representation of the double argument. All characters
@@ -387,31 +392,37 @@ namespace lang{
* @param value - The double to convert to a string
* @returns the formatted double string.
*/
- static std::string toString( double value );
+ static std::string toString(double value);
/**
* Returns a Double instance representing the specified double value.
- * @param value - double to wrap
+ *
+ * @param value
+ * The double to wrap.
+ *
* @returns new Double instance wrapping the primitive value
*/
- static Double valueOf( double value );
+ static Double valueOf(double value);
/**
- * Returns a Double instance that wraps a primtive double which is parsed
+ * Returns a Double instance that wraps a primitive double which is parsed
* from the string value passed.
- * @param value - the string to parse
+ *
+ * @param value
+ * The string to parse
+ *
* @returns a new Double instance wrapping the double parsed from value
+ *
* @throws NumberFormatException on error.
*/
- static Double valueOf( const std::string& value );
+ static Double valueOf(const String& value);
private:
- static const long long DOUBLE_SIGN_MASK = 0x8000000000000000LL;
- static const long long DOUBLE_EXPONENT_MASK = 0x7FF0000000000000LL;
- static const long long DOUBLE_MANTISSA_MASK = 0x000FFFFFFFFFFFFFLL;
- static const long long DOUBLE_NAN_BITS =
- DOUBLE_EXPONENT_MASK | 0x0008000000000000LL;
+ static const long long DOUBLE_SIGN_MASK;
+ static const long long DOUBLE_EXPONENT_MASK;
+ static const long long DOUBLE_MANTISSA_MASK;
+ static const long long DOUBLE_NAN_BITS;
};
View
153 activemq-cpp/src/main/decaf/lang/Float.cpp
@@ -17,6 +17,7 @@
#include "Float.h"
#include <decaf/lang/Integer.h>
+#include <decaf/lang/ArrayPointer.h>
#include <limits>
#include <string.h>
@@ -33,63 +34,67 @@ 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();
+const unsigned int Float::SINGLE_EXPONENT_MASK = 0x7F800000;
+const unsigned int Float::SINGLE_MANTISSA_MASK = 0x007FFFFF;
+const unsigned int Float::SINGLE_NAN_BITS = (SINGLE_EXPONENT_MASK | 0x00400000);
+
////////////////////////////////////////////////////////////////////////////////
-Float::Float( float value ) : value(value) {
+Float::Float(float value) : value(value) {
}
////////////////////////////////////////////////////////////////////////////////
-Float::Float( double value ) : value((float)value) {
+Float::Float(double value) : value((float) value) {
}
////////////////////////////////////////////////////////////////////////////////
-Float::Float( const std::string& value ) : value(0) {
- this->value = Float::parseFloat( value );
+Float::Float(const String& value) : value(0) {
+ 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.value);
}
////////////////////////////////////////////////////////////////////////////////
-int Float::compareTo( const float& f ) const {
- return Float::compare( this->value, f );
+int Float::compareTo(const float& f) const {
+ return Float::compare(this->value, f);
}
////////////////////////////////////////////////////////////////////////////////
std::string Float::toString() const {
- return Float::toString( this->value );
+ return Float::toString(this->value);
}
////////////////////////////////////////////////////////////////////////////////
bool Float::isInfinite() const {
- return Float::isInfinite( this->value );
+ return Float::isInfinite(this->value);
}
////////////////////////////////////////////////////////////////////////////////
bool Float::isNaN() const {
- return Float::isNaN( this->value );
+ return Float::isNaN(this->value);
}
////////////////////////////////////////////////////////////////////////////////
-int Float::compare( float f1, float f2 ) {
+int Float::compare(float f1, float f2) {
int i1, i2 = 0;
- long NaNbits = Float::floatToIntBits( Float::NaN );
+ long NaNbits = Float::floatToIntBits(Float::NaN);
- if( ( i1 = Float::floatToIntBits( f1 ) ) == NaNbits ) {
- if( Float::floatToIntBits( f2 ) == NaNbits ) {
+ if ((i1 = Float::floatToIntBits(f1)) == NaNbits) {
+ if (Float::floatToIntBits(f2) == NaNbits) {
return 0;
}
return 1;
}
- if( ( i2 = Float::floatToIntBits( f2 ) ) == NaNbits ) {
+ if ((i2 = Float::floatToIntBits(f2)) == NaNbits) {
return -1;
}
- if( f1 == f2 ) {
- if( i1 == i2 ) {
+ if (f1 == f2) {
+ if (i1 == i2) {
return 0;
}
@@ -101,15 +106,13 @@ int Float::compare( float f1, float f2 ) {
}
////////////////////////////////////////////////////////////////////////////////
-int Float::floatToIntBits( float value ) {
+int Float::floatToIntBits(float value) {
int intValue = 0;
- memcpy( &intValue, &value, sizeof( float ) );
+ memcpy(&intValue, &value, sizeof(float));
- if( ( intValue & SINGLE_EXPONENT_MASK ) == SINGLE_EXPONENT_MASK )
- {
- if( intValue & SINGLE_MANTISSA_MASK )
- {
+ if ((intValue & SINGLE_EXPONENT_MASK) == SINGLE_EXPONENT_MASK) {
+ if (intValue & SINGLE_MANTISSA_MASK) {
return SINGLE_NAN_BITS;
}
}
@@ -118,136 +121,137 @@ int Float::floatToIntBits( float value ) {
}
////////////////////////////////////////////////////////////////////////////////
-int Float::floatToRawIntBits( float value ) {
-
+int Float::floatToRawIntBits(float value) {
int intValue = 0;
- memcpy( &intValue, &value, sizeof( float ) );
+ memcpy(&intValue, &value, sizeof(float));
return intValue;
}
////////////////////////////////////////////////////////////////////////////////
-float Float::intBitsToFloat( int bits ) {
-
+float Float::intBitsToFloat(int bits) {
float floatValue = 0;
- memcpy( &floatValue, &bits, sizeof( int ) );
+ memcpy(&floatValue, &bits, sizeof(int));
return floatValue;
}
////////////////////////////////////////////////////////////////////////////////
-bool Float::isInfinite( float value ) {
- return ( value == POSITIVE_INFINITY ) || ( value == NEGATIVE_INFINITY );
+bool Float::isInfinite(float value) {
+ return (value == POSITIVE_INFINITY) || (value == NEGATIVE_INFINITY);
}
////////////////////////////////////////////////////////////////////////////////
-bool Float::isNaN( float value ) {
+bool Float::isNaN(float value) {
return value != value;
}
////////////////////////////////////////////////////////////////////////////////
-float Float::parseFloat( const std::string& value ) {
+float Float::parseFloat(const String& value) {
// TODO - This is not going to parse the formats we say we do.
float result = 0.0;
- istringstream stream( value );
+
+ ArrayPointer<char> buffer(value.length() + 1);
+ value.getChars(0, value.length(), buffer.get(), value.length() + 1, 0);
+
+ istringstream stream(buffer.get());
stream >> result;
// Not everything got read, meaning there wasn't just a number here.
- if( !stream.eof() ) {
+ if (!stream.eof()) {
throw exceptions::NumberFormatException(
__FILE__, __LINE__,
- "Failed to parse a valid float from input string: %s", value.c_str() );
+ "Failed to parse a valid float from input string: %s", value.c_str());
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Float::toHexString( float value ) {
+std::string Float::toHexString(float value) {
/*
* Reference: http://en.wikipedia.org/wiki/IEEE_754
*/
- if( value != value ) {
+ if (value != value) {
return "NaN";
}
- if( value == POSITIVE_INFINITY ) {
+ if (value == POSITIVE_INFINITY) {
return "Infinity";
}
- if( value == NEGATIVE_INFINITY ) {
+ if (value == NEGATIVE_INFINITY) {
return "-Infinity";
}
- unsigned int bitValue = Float::floatToIntBits( value );
+ unsigned int bitValue = Float::floatToIntBits(value);
- bool negative = ( bitValue & 0x80000000 ) != 0;
+ bool negative = (bitValue & 0x80000000) != 0;
// mask exponent bits and shift down
- unsigned int exponent = ( bitValue & 0x7f800000 ) >> 23;
+ 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;
+ unsigned int significand = (bitValue & 0x007FFFFF) << 1;
- if( exponent == 0 && significand == 0 ) {
- return ( negative ? "-0x0.0p0" : "0x0.0p0" );
+ 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" );
+ std::string hexString(negative ? "-0x" : "0x");
- if( exponent == 0 ) {
+ if (exponent == 0) {
// denormal (subnormal) value
- hexString.append( "0." );
+ 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 ) ) {
+ while ((significand != 0) && ((significand & 0xF) == 0)) {
significand >>= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
- std::string hexSignificand = Integer::toHexString( significand );
+ 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 - (int)hexSignificand.length();
- while( digitDiff-- != 0 ) {
- hexString.append( "0" );
+ if (significand != 0 && fractionDigits > hexSignificand.length()) {
+ unsigned int digitDiff = fractionDigits - (int) hexSignificand.length();
+ while (digitDiff-- != 0) {
+ hexString.append("0");
}
}
- hexString.append( hexSignificand );
- hexString.append( "p-126" );
+ hexString.append(hexSignificand);
+ hexString.append("p-126");
} else {
// normal value
- hexString.append( "1." );
+ 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 ) ) {
+ while ((significand != 0) && ((significand & 0xF) == 0)) {
significand >>= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
- std::string hexSignificand = Integer::toHexString( significand );
+ 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 - (int)hexSignificand.length();
- while( digitDiff-- != 0 ) {
- hexString.append( "0" );
+ if (significand != 0 && fractionDigits > hexSignificand.length()) {
+ unsigned int digitDiff = fractionDigits - (int) hexSignificand.length();
+ while (digitDiff-- != 0) {
+ hexString.append("0");
}
}
- hexString.append( hexSignificand );
- hexString.append( "p" );
+ hexString.append(hexSignificand);
+ hexString.append("p");
// remove exponent's 'bias' and convert to a string
- hexString.append( Integer::toString( exponent - 127 ) );
+ hexString.append(Integer::toString(exponent - 127));
}
return hexString;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Float::toString( float value ) {
-
+std::string Float::toString(float value) {
// TODO - This is not going to support the formats we say we do.
ostringstream stream;
stream << value;
@@ -255,12 +259,11 @@ std::string Float::toString( float value ) {
}
////////////////////////////////////////////////////////////////////////////////
-Float Float::valueOf( float value ) {
- return Float( value );
+Float Float::valueOf(float value) {
+ return Float(value);
}
////////////////////////////////////////////////////////////////////////////////
-Float Float::valueOf( const std::string& value ) {
-
- return valueOf( parseFloat( value ) );
+Float Float::valueOf(const String& value) {
+ return valueOf(parseFloat(value));
}
View
87 activemq-cpp/src/main/decaf/lang/Float.h
@@ -20,12 +20,13 @@
#include <decaf/util/Config.h>
#include <decaf/lang/Number.h>
+#include <decaf/lang/String.h>
#include <decaf/lang/Comparable.h>
#include <decaf/lang/exceptions/NumberFormatException.h>
#include <string>
-namespace decaf{
-namespace lang{
+namespace decaf {
+namespace lang {
class DECAF_API Float : public Number,
public Comparable<Float>,
@@ -59,17 +60,17 @@ namespace lang{
/**
* @param value - the primitive type to wrap
*/
- Float( float value );
+ Float(float value);
/**
* @param value - the primitive type to wrap
*/
- Float( double value );
+ Float(double value);
/**
* @param value - the string to convert to a primitive type to wrap
*/
- Float( const std::string& value );
+ Float(const String& value);
virtual ~Float() {}
@@ -81,13 +82,13 @@ namespace lang{
* than the passed in value, and -1 if this object represents a value
* less than the passed in value.
*/
- virtual int compareTo( const Float& f ) const;
+ 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 {
+ bool equals(const Float& f) const {
return this->value == f.value;
}
@@ -96,7 +97,7 @@ namespace lang{
* @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 {
+ virtual bool operator==(const Float& f) const {
return this->value == f.value;
}
@@ -106,7 +107,7 @@ namespace lang{
* @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 {
+ virtual bool operator<(const Float& f) const {
return this->value < f.value;
}
@@ -118,13 +119,13 @@ namespace lang{
* than the passed in value, and -1 if this object represents a value
* less than the passed in value.
*/
- virtual int compareTo( const float& f ) const;
+ 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 {
+ bool equals(const float& f) const {
return this->value == f;
}
@@ -133,7 +134,7 @@ namespace lang{
* @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 {
+ virtual bool operator==(const float& f) const {
return this->value == f;
}
@@ -143,7 +144,7 @@ namespace lang{
* @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 {
+ virtual bool operator<(const float& f) const {
return this->value < f;
}
@@ -157,7 +158,7 @@ namespace lang{
* @return double the value of the receiver.
*/
virtual double doubleValue() const {
- return (double)this->value;
+ return (double) this->value;
}
/**
@@ -173,7 +174,7 @@ namespace lang{
* @return byte the value of the receiver.
*/
virtual unsigned char byteValue() const {
- return (unsigned char)this->value;
+ return (unsigned char) this->value;
}
/**
@@ -181,7 +182,7 @@ namespace lang{
* @return short the value of the receiver.
*/
virtual short shortValue() const {
- return (short)this->value;
+ return (short) this->value;
}
/**
@@ -189,7 +190,7 @@ namespace lang{
* @return int the value of the receiver.
*/
virtual int intValue() const {
- return (int)this->value;
+ return (int) this->value;
}
/**
@@ -197,7 +198,7 @@ namespace lang{
* @return long the value of the receiver.
*/
virtual long long longValue() const {
- return (long long)this->value;
+ return (long long) this->value;
}
/**
@@ -210,7 +211,8 @@ namespace lang{
*/
bool isNaN() const;
- public: // Statics
+ public:
+ // Statics
/**
* Compares the two specified double values. The sign of the integer value
@@ -222,7 +224,7 @@ namespace lang{
* 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 );
+ static int compare(float f1, float f2);
/**
* Returns a representation of the specified floating-point value according
@@ -245,7 +247,7 @@ namespace lang{
* @param value - the float to convert to int bits
* @returns the int that holds the float's value
*/
- static int floatToIntBits( float value );
+ static int floatToIntBits(float value);
/**
* Returns a representation of the specified floating-point value according
@@ -272,7 +274,7 @@ namespace lang{
* The float to convert to a raw int.
* @returns the raw int value of the float
*/
- static int floatToRawIntBits( float value );
+ static int floatToRawIntBits(float value);
/**
* Returns the float value corresponding to a given bit representation. The
@@ -291,28 +293,36 @@ namespace lang{
* @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 );
+ 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 );
+ static bool isInfinite(float value);
/**
- * @param value - The float to check.
+ * Checks and returns whether the given float is equal to NaN.
+ *
+ * @param value
+ * The float to check.
+ *
* @returns true if the float is equal to NaN.
*/
- static bool isNaN( float value );
+ 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
+ *
+ * @param value
+ * The string to parse.
+ *
* @returns a float parsed from the string
- * @throw NumberFormatException
+ *
+ * @throw NumberFormatException if an error occurs parsing the String.
*/
- static float parseFloat( const std::string& value );
+ static float parseFloat(const String& value);
/**
* Returns a hexadecimal string representation of the float argument. All
@@ -348,7 +358,7 @@ namespace lang{
* @param value - The float to convert to a string
* @returns the Hex formatted float string.
*/
- static std::string toHexString( float value );
+ static std::string toHexString(float value);
/**
* Returns a string representation of the float argument. All characters
@@ -378,17 +388,20 @@ namespace lang{
* 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
+ *
+ * @param value
+ * The float to convert to a string
+ *
* @returns the formatted float string.
*/
- static std::string toString( float value );
+ 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 );
+ static Float valueOf(float value);
/**
* Returns a Float instance that wraps a primitive float which is parsed
@@ -398,13 +411,13 @@ namespace lang{
* @returns a new Float instance wrapping the float parsed from value
* @throws NumberFormatException on error.
*/
- static Float valueOf( const std::string& value );
+ static Float valueOf(const String& value);
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);
+ static const unsigned int SINGLE_EXPONENT_MASK;
+ static const unsigned int SINGLE_MANTISSA_MASK;
+ static const unsigned int SINGLE_NAN_BITS;
};
View
242 activemq-cpp/src/main/decaf/lang/Integer.cpp
@@ -33,32 +33,36 @@ const int Integer::MAX_VALUE = (int)0x7FFFFFFF;
const int Integer::MIN_VALUE = (int)0x80000000;
////////////////////////////////////////////////////////////////////////////////
-Integer::Integer( int value ) :value(value) {
+Integer::Integer(int value) : value(value) {
}
////////////////////////////////////////////////////////////////////////////////
-Integer::Integer( const std::string& value ) : value() {
- this->value = parseInt( value );
+Integer::Integer(const std::string& value) : value() {
+ this->value = parseInt(value);
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::compareTo( const Integer& i ) const {
+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 {
+int Integer::compareTo(const int& i) const {
return this->value < i ? -1 : this->value == i ? 0 : 1;
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::bitCount( int value ) {
+Integer::~Integer() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::bitCount(int value) {
- if( value == 0 ) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
+ unsigned int uvalue = (unsigned int) value;
// 32-bit recursive reduction using SWAR...
// but first step is mapping 2-bit values
@@ -68,17 +72,17 @@ int Integer::bitCount( int value ) {
uvalue = (((uvalue >> 4) + uvalue) & 0x0F0F0F0F);
uvalue += (uvalue >> 8);
uvalue += (uvalue >> 16);
- return(uvalue & 0x0000003F);
+ return (uvalue & 0x0000003F);
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::reverseBytes( int value ) {
+int Integer::reverseBytes(int value) {
- if( value == 0 ) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
+ unsigned int uvalue = (unsigned int) value;
unsigned int b3 = uvalue >> 24;
unsigned int b2 = (uvalue >> 8) & 0xFF00;
@@ -88,13 +92,13 @@ int Integer::reverseBytes( int value ) {
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::reverse( int value ) {
+int Integer::reverse(int value) {
- if( value == 0 ) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
+ unsigned int uvalue = (unsigned int) value;
uvalue = (((uvalue & 0xAAAAAAAA) >> 1) | ((uvalue & 0x55555555) << 1));
uvalue = (((uvalue & 0xCCCCCCCC) >> 2) | ((uvalue & 0x33333333) << 2));
@@ -105,33 +109,33 @@ int Integer::reverse( int value ) {
////////////////////////////////////////////////////////////////////////////////
std::string Integer::toString() const {
- return Integer::toString( this->value, 10 );
+ return Integer::toString(this->value, 10);
}
////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toString( int value ) {
- return Integer::toString( value, 10 );
+std::string Integer::toString(int value) {
+ return Integer::toString(value, 10);
}
////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toString( int value, int radix ) {
+std::string Integer::toString(int value, int radix) {
- if( radix < Character::MIN_RADIX || radix > Character::MAX_RADIX ) {
+ if (radix < Character::MIN_RADIX || radix > Character::MAX_RADIX) {
radix = 10;
}
- if( value == 0 ) {
+ if (value == 0) {
return "0";
}
int count = 2, j = value;
bool negative = value < 0;
- if( !negative ) {
+ if (!negative) {
count = 1;
j = -value;
}
- while( (value /= radix) != 0 ) {
+ while ((value /= radix) != 0) {
count++;
}
@@ -141,37 +145,37 @@ std::string Integer::toString( int value, int radix ) {
char* buffer = new char[length + 1];
do {
- int ch = 0 - ( j % radix );
- if( ch > 9 ) {
+ int ch = 0 - (j % radix);
+ if (ch > 9) {
ch = ch - 10 + 'a';
} else {
ch += '0';
}
- buffer[--count] = (char)ch;
- } while( (j /= radix) != 0 );
+ buffer[--count] = (char) ch;
+ } while ((j /= radix) != 0);
- if( negative ) {
+ if (negative) {
buffer[0] = '-';
}
// Ensure there's a null
buffer[length] = 0;
- std::string result( &buffer[0] );
- delete [] buffer;
+ std::string result(&buffer[0]);
+ delete[] buffer;
return result;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toBinaryString( int value ) {
+std::string Integer::toBinaryString(int value) {
int count = 1;
int j = value;
- if( value < 0 ) {
+ if (value < 0) {
count = 32;
} else {
- while ( (j >>= 1) != 0) {
+ while ((j >>= 1) != 0) {
count++;
}
}
@@ -182,28 +186,28 @@ std::string Integer::toBinaryString( int value ) {
char* buffer = new char[length + 1];
do {
- buffer[--count] = (char)( (value & 1) + '0' );
+ buffer[--count] = (char) ((value & 1) + '0');
value >>= 1;
- } while( count > 0 );
+ } while (count > 0);
// Ensure there's a null
buffer[length] = 0;
- std::string result( &buffer[0] );
- delete [] buffer;
+ std::string result(&buffer[0]);
+ delete[] buffer;
return result;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toOctalString( int value ) {
+std::string Integer::toOctalString(int value) {
int count = 1, j = value;
unsigned int uvalue = (unsigned int) value;
- if( value < 0 ) {
+ if (value < 0) {
count = 11; // (8 * sizeof(value) + 2) / 3;
} else {
- while ( (j >>= 3) != 0 ) {
+ while ((j >>= 3) != 0) {
count++;
}
}
@@ -214,28 +218,28 @@ std::string Integer::toOctalString( int value ) {
char* buffer = new char[length + 1];
do {
- buffer[--count] = (char)( (uvalue & 7) + '0' );
+ buffer[--count] = (char) ((uvalue & 7) + '0');
uvalue >>= 3;
- } while( count > 0 );
+ } while (count > 0);
// Ensure there's a null
buffer[length] = 0;
- std::string result( &buffer[0] );
- delete [] buffer;
+ std::string result(&buffer[0]);
+ delete[] buffer;
return result;
}
////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toHexString( int value ) {
+std::string Integer::toHexString(int value) {
int count = 1;
int j = value;
- if( value < 0 ) {
+ if (value < 0) {
count = 8;
} else {
- while( (j >>= 4) != 0 ) {
+ while ((j >>= 4) != 0) {
count++;
}
}
@@ -247,32 +251,32 @@ std::string Integer::toHexString( int value ) {
do {
int t = value & 15;
- if( t > 9 ) {
+ if (t > 9) {
t = t - 10 + 'a';
} else {
t += '0';
}
- buffer[--count] = (char)t;
+ buffer[--count] = (char) t;
value >>= 4;
- } while( count > 0 );
+ } while (count > 0);
// Ensure there's a null
buffer[length] = 0;
- std::string result( &buffer[0] );
- delete [] buffer;
+ std::string result(&buffer[0]);
+ delete[] buffer;
return result;
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::parseInt( const std::string& value ) {
- return Integer::parseInt( value, 10 );
+int Integer::parseInt(const String& value) {
+ return Integer::parseInt(value, 10);
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::parseInt( const std::string& value, int radix ) {
+int Integer::parseInt(const String& value, int radix) {
- if( radix < Character::MIN_RADIX ||
+ if (radix < Character::MIN_RADIX ||
radix > Character::MAX_RADIX ) {
throw NumberFormatException(
__FILE__, __LINE__,
@@ -280,63 +284,61 @@ int Integer::parseInt( const std::string& value, int radix ) {
}
int length = (int)value.length(), i = 0;
- if( length == 0 ) {
+ if (length == 0) {
throw NumberFormatException(
__FILE__, __LINE__,
"Integer:decode - Invalid: zero length string");
}
- bool negative = value[i] == '-';
- if( negative && ++i == length ) {
+ bool negative = value.charAt(i) == '-';
+ if (negative && ++i == length) {
throw NumberFormatException(
__FILE__, __LINE__,
"Integer:decode - Invalid only a minus sign given");
}
- return Integer::parse( value, i, radix, negative );
+ return Integer::parse(value, i, radix, negative);
}
////////////////////////////////////////////////////////////////////////////////
-Integer Integer::valueOf( const std::string& value ) {
-
- return Integer( Integer::parseInt( value ) );
+Integer Integer::valueOf(const String& value) {
+ return Integer(Integer::parseInt(value));
}
////////////////////////////////////////////////////////////////////////////////
-Integer Integer::valueOf( const std::string& value, int radix ) {
-
- return Integer( Integer::parseInt( value, radix ) );
+Integer Integer::valueOf(const String& value, int radix) {
+ return Integer(Integer::parseInt(value, radix));
}
////////////////////////////////////////////////////////////////////////////////
-Integer Integer::decode( const std::string& value ) {
+Integer Integer::decode(const String& value) {
- int length = (int)value.length(), i = 0;
- if( length == 0 ) {
+ int length = (int) value.length(), i = 0;
+ if (length == 0) {
throw NumberFormatException(
__FILE__, __LINE__,
"Integer:decode - Invalid zero size string");
}
- char firstDigit = value[i];
+ char firstDigit = value.charAt(i);
bool negative = firstDigit == '-';
- if( negative ) {
- if( length == 1 ) {
+ if (negative) {
+ if (length == 1) {
throw NumberFormatException(
__FILE__, __LINE__,
"Integer:decode - Invalid zero string, minus only");
}
- firstDigit = value[++i];
+ firstDigit = value.charAt(++i);
}
int base = 10;
- if( firstDigit == '0' ) {
- if( ++i == length ) {
- return valueOf( 0 );
+ if (firstDigit == '0') {
+ if (++i == length) {
+ return valueOf(0);
}
- if( ( firstDigit = value[i] ) == 'x' || firstDigit == 'X' ) {
+ if ((firstDigit = value.charAt(i)) == 'x' || firstDigit == 'X') {
if( i == length ) {
throw NumberFormatException(
__FILE__, __LINE__,
@@ -347,8 +349,8 @@ Integer Integer::decode( const std::string& value ) {
} else {
base = 8;
}
- } else if( firstDigit == '#' ) {
- if( i == length ) {
+ } else if (firstDigit == '#') {
+ if (i == length) {
throw NumberFormatException(
__FILE__, __LINE__,
"Integer:decode - Invalid zero string, minus only");
@@ -357,120 +359,116 @@ Integer Integer::decode( const std::string& value ) {
base = 16;
}
- int result = parse( value, i, base, negative );
- return valueOf( result );
+ int result = parse(value, i, base, negative);
+ return valueOf(result);
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::parse( const std::string& value, int offset, int radix, bool negative ) {
+int Integer::parse(const String& value, int offset, int radix, bool negative) {
int max = Integer::MIN_VALUE / radix;
- int result = 0, length = (int)value.size();
+ int result = 0, length = (int) value.length();
- while( offset < length ) {
- int digit = Character::digit( value[offset++], radix );
- if( digit == -1 ) {
+ while (offset < length) {
+ int digit = Character::digit(value.charAt(offset++), radix);
+ if (digit == -1) {
throw NumberFormatException(
__FILE__, __LINE__,
- "Integer::parse - number string is invalid: ",
- value.c_str() );
+ "Integer::parse - number string is invalid: ", value.c_str());
}
- if( max > result ) {
+ if (max > result) {
throw NumberFormatException(
__FILE__, __LINE__,
- "Integer::parse - number string is invalid: ",
- value.c_str() );
+ "Integer::parse - number string is invalid: ", value.c_str());
}
int next = result * radix - digit;
- if( next > result ) {
+ if (next > result) {
throw NumberFormatException(
__FILE__, __LINE__,
- "Integer::parse - number string is invalid: ",
- value.c_str() );
+ "Integer::parse - number string is invalid: ", value.c_str());
}
result = next;
}
- if( !negative ) {
+ if (!negative) {
result = -result;
- if( result < 0 ) {
+ if (result < 0) {
throw NumberFormatException(
__FILE__, __LINE__,
- "Integer::parse - number string is invalid: ",
- value.c_str() );
+ "Integer::parse - number string is invalid: ", value.c_str());
}
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::highestOneBit( int value ) {
+int Integer::highestOneBit(int value) {
- if( value == 0 ) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
+ 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));
+ return (uvalue & ~(uvalue >> 1));
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::lowestOneBit( int value ) {
- if( value == 0 ) {
+int Integer::lowestOneBit(int value) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
- return ( uvalue & (-uvalue) );
+ unsigned int uvalue = (unsigned int) value;
+ return (uvalue & (-uvalue));
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::numberOfLeadingZeros( int value ) {
+int Integer::numberOfLeadingZeros(int value) {
- if( value == 0 ) {
+ if (value == 0) {
return 0;
}
- unsigned int uvalue = (unsigned int)value;
+ 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 );
+ return Integer::bitCount(~uvalue);
}
////////////////////////////////////////////////////////////////////////////////
-int Integer::numberOfTrailingZeros( int value ) {
- if( value == 0 ) {
+int Integer::numberOfTrailingZeros(int value) {
+ if (value == 0) {