You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/07/27 16:31:05 UTC
svn commit: r560244 - in
/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Short.cpp Short.h
Author: tabish
Date: Fri Jul 27 07:31:04 2007
New Revision: 560244
URL: http://svn.apache.org/viewvc?view=rev&rev=560244
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
Implementing the Primitive Wrappers fully
Modified:
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.cpp
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.h
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.cpp?view=diff&rev=560244&r1=560243&r2=560244
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.cpp Fri Jul 27 07:31:04 2007
@@ -34,3 +34,56 @@
int Short::compareTo( const Short& b ) const {
return value == b.value ? 0 : ( value > b.value ? 1 : -1 );
}
+
+////////////////////////////////////////////////////////////////////////////////
+short Short::parseShort( const std::string& s, int radix )
+ throw ( exceptions::NumberFormatException ) {
+
+ // TODO
+ return s.size() + radix;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short Short::parseShort( const std::string& s )
+ throw ( exceptions::NumberFormatException ) {
+ return parseShort( s, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Short Short::decode( const std::string& value )
+ throw ( exceptions::NumberFormatException ) {
+
+ // TODO
+ return Short( value.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short Short::reverseBytes( short value ) {
+
+ short temp = value;
+
+ // TODO
+ //temp += ( value & 0xF0 ) >> 8;
+ //temp += ( value & 0x0F ) << 8;
+
+ return temp;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Short Short::valueOf( short value ) {
+ return Short( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Short Short::valueOf( const std::string& value )
+ throw ( exceptions::NumberFormatException ) {
+
+ return Short( parseShort( value, 10 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Short Short::valueOf( const std::string& value, int radix )
+ throw ( exceptions::NumberFormatException ) {
+
+ return Short( parseShort( value, radix ) );
+}
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.h?view=diff&rev=560244&r1=560243&r2=560244
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Short.h Fri Jul 27 07:31:04 2007
@@ -20,7 +20,7 @@
#include <decaf/lang/Number.h>
#include <decaf/lang/Comparable.h>
-//#include <decaf/lang/exceptions/NumberFormatException.h>
+#include <decaf/lang/exceptions/NumberFormatException.h>
#include <string>
namespace decaf{
@@ -36,6 +36,24 @@
public:
/**
+ * Max Value for this Object's primitive type
+ */
+ static const short MAX_VALUE = ((1 << sizeof(short)) - 1);
+
+ /**
+ * Max Value for this Object's primitive type
+ */
+ static const short MIN_VALUE = (-(1 << sizeof(short)));
+
+ /**
+ * Size of this objects primitive type
+ */
+ static const int SIZE = sizeof( short );
+
+
+ public:
+
+ /**
* @param value - short to wrap
*/
Short( short value );
@@ -115,6 +133,30 @@
public: // statics
/**
+ * Decodes a String into a Short. 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
+ * Short.parseShort 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 Short object containing the decoded value
+ * @throws NumberFomatException if the string is not formatted correctly.
+ */
+ static Short 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 short value.
+ */
+ static short reverseBytes( short value );
+
+ /**
* Parses the string argument as a signed short 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
@@ -137,8 +179,8 @@
* @return the short represented by the string argument in the specified radix.
* @throws NumberFormatException - If String does not contain a parsable short.
*/
-// static short parseShort( const std::string& s, int radix )
-// throw ( exceptions::NumberFormatException );
+ static short parseShort( const std::string& s, int radix )
+ throw ( exceptions::NumberFormatException );
/**
* Parses the string argument as a signed decimal short. The characters
@@ -151,8 +193,43 @@
* @returns the converted short value
* @throws NumberFormatException if the string is not a short.
*/
-// static short parseShort( const std::string& s )
-// throw ( exceptions::NumberFormatException );
+ static short parseShort( const std::string& s )
+ throw ( exceptions::NumberFormatException );
+
+ /**
+ * Returns a Short instance representing the specified short value.
+ * @param value - the short to wrap
+ * @return the new Short object wrapping value.
+ */
+ static Short valueOf( short value );
+
+ /**
+ * Returns a Short object holding the value given by the specified std::string.
+ * The argument is interpreted as representing a signed decimal short,
+ * exactly as if the argument were given to the parseShort( std::string )
+ * method. The result is a Short object that represents the short value
+ * specified by the string.
+ * @param value - std::string to parse as base 10
+ * @return new Short Object wrapping the primitive
+ * @throws NumberFormatException if the string is not a decimal short.
+ */
+ static Short valueOf( const std::string& value )
+ throw ( exceptions::NumberFormatException );
+
+ /**
+ * Returns a Short 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 short in the
+ * radix specified by the second argument, exactly as if the argument were
+ * given to the parseShort( std::string, int ) method. The result is a
+ * Short object that represents the short value specified by the string.
+ * @param value - std::string to parse as base ( radix )
+ * @param radix - base of the string to parse.
+ * @return new Short Object wrapping the primitive
+ * @throws NumberFormatException if the string is not a valid short.
+ */
+ static Short valueOf( const std::string& value, int radix )
+ throw ( exceptions::NumberFormatException );
};