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/26 20:39:30 UTC
svn commit: r559930 - in
/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Boolean.cpp
Boolean.h Comparable.h
Author: tabish
Date: Thu Jul 26 11:39:29 2007
New Revision: 559930
URL: http://svn.apache.org/viewvc?view=rev&rev=559930
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/Boolean.cpp
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.h
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Comparable.h
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.cpp?view=diff&rev=559930&r1=559929&r2=559930
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.cpp Thu Jul 26 11:39:29 2007
@@ -17,11 +17,53 @@
#include "Boolean.h"
+using namespace decaf;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-bool Boolean::parseBoolean( const std::string& value )
-{
+const Boolean Boolean::_FALSE( false );
+const Boolean Boolean::_TRUE( true );
+
+////////////////////////////////////////////////////////////////////////////////
+Boolean::Boolean( bool value ) {
+ this->value = value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Boolean::Boolean( const std::string& value ) {
+ this->value = parseBoolean( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Boolean::compareTo( const Boolean& b ) const {
+ if( this->value == b.value ) {
+ return 0;
+ } else if( this->value && !b.value ) {
+ return 1;
+ } else {
+ return -1;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Boolean::toString() const {
+ std::ostringstream ostream;
+ ostream << std::boolalpha << this->value;
+ return ostream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Boolean Boolean::valueOf( const std::string& value ) {
+ return Boolean( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Boolean Boolean::valueOf( bool value ) {
+ return Boolean( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Boolean::parseBoolean( const std::string& value ) {
bool ret = 0;
std::istringstream istream(value);
istream.clear();
@@ -30,8 +72,7 @@
}
////////////////////////////////////////////////////////////////////////////////
-std::string Boolean::toString( bool value )
-{
+std::string Boolean::toString( bool value ) {
std::ostringstream ostream;
ostream << std::boolalpha << value;
return ostream.str();
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.h?view=diff&rev=559930&r1=559929&r2=559930
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Boolean.h Thu Jul 26 11:39:29 2007
@@ -19,16 +19,84 @@
#define _DECAF_LANG_BOOLEAN_H_
#include <decaf/lang/Number.h>
+#include <decaf/lang/Comparable.h>
namespace decaf{
namespace lang{
- class DECAF_API Boolean : public Number
- {
+ class DECAF_API Boolean : public Number,
+ public Comparable<Boolean> {
+ private:
+
+ // This objects boolean value
+ bool value;
+
+ public:
+
+ /**
+ * The Class object representing the primitive false boolean.
+ */
+ static const Boolean _FALSE;
+
+ /**
+ * The Class object representing the primitive type boolean.
+ */
+ static const Boolean _TRUE;
+
public:
- Boolean() {}
+ /**
+ * @param value - primitive boolean to wrap.
+ */
+ Boolean( bool value );
+
+ /**
+ * @param value - String value to convert to a boolean.
+ */
+ Boolean( const std::string& value );
+
virtual ~Boolean() {}
+
+ /**
+ * @returns the primitive boolean value of this object
+ */
+ bool booleanValue() const {
+ return value;
+ }
+
+ /**
+ * @returns the string representation of this Booleans value.
+ */
+ std::string toString() const;
+
+ /**
+ * Compares this Boolean instance with another.
+ * @param b - the Boolean instance to be compared
+ * @return zero if this object represents the same boolean value as the
+ * argument; a positive value if this object represents true and the
+ * argument represents false; and a negative value if this object
+ * represents false and the argument represents true
+ */
+ virtual int compareTo( const Boolean& b ) const;
+
+ /**
+ * @returns true if the two Boolean Objects have the same value.
+ */
+ bool equals( const Boolean& b ) const {
+ return this->value == b.value;
+ }
+
+ public: // Statics
+
+ /**
+ * @returns a Boolean instance of the primitive boolean value
+ */
+ static Boolean valueOf( bool value );
+
+ /**
+ * @returns a Boolean instance of the string value
+ */
+ static Boolean valueOf( const std::string& value );
/**
* Parses the String passed and extracts an bool.
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Comparable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Comparable.h?view=diff&rev=559930&r1=559929&r2=559930
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Comparable.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Comparable.h Thu Jul 26 11:39:29 2007
@@ -10,7 +10,7 @@
* ordering, and the class's compareTo method is referred to as its natural
* comparison method.
*/
- tempalte< typename T >
+ template< typename T >
class Comparable{
public:
@@ -44,7 +44,7 @@
* @returns a negative integer, zero, or a positive integer as this
* object is less than, equal to, or greater than the specified object.
*/
- virtual int compareTo( const T& value ) = 0;
+ virtual int compareTo( const T& value ) const = 0;
};