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/05/31 22:24:59 UTC

svn commit: r662076 - in /activemq/activemq-cpp/trunk/src/main/activemq/util: PrimitiveList.cpp PrimitiveList.h PrimitiveMap.cpp PrimitiveMap.h PrimitiveValueNode.cpp PrimitiveValueNode.h

Author: tabish
Date: Sat May 31 13:24:58 2008
New Revision: 662076

URL: http://svn.apache.org/viewvc?rev=662076&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-172

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.h
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.h
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.h

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.cpp?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.cpp Sat May 31 13:24:58 2008
@@ -31,6 +31,11 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+PrimitiveList::PrimitiveList( const decaf::util::List<PrimitiveValueNode>& src )
+  : List<PrimitiveValueNode>( src ){
+}
+
+////////////////////////////////////////////////////////////////////////////////
 PrimitiveList::PrimitiveList( const PrimitiveList& src )
   : List<PrimitiveValueNode>( src ){
 }

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.h?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveList.h Sat May 31 13:24:58 2008
@@ -45,7 +45,13 @@
 
         /**
          * Copy Constructor
-         * @param list - the PrimitiveList to copy
+         * @param src - the Decaf List of PrimtiveNodeValues to copy
+         */
+        PrimitiveList( const decaf::util::List<PrimitiveValueNode>& src );
+
+        /**
+         * Copy Constructor
+         * @param src - the PrimitiveList to copy
          */
         PrimitiveList( const PrimitiveList& src );
 

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.cpp?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.cpp Sat May 31 13:24:58 2008
@@ -32,6 +32,11 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+PrimitiveMap::PrimitiveMap( const decaf::util::Map<std::string, PrimitiveValueNode>& src )
+  : decaf::util::Map<std::string, PrimitiveValueNode>( src ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
 PrimitiveMap::PrimitiveMap( const PrimitiveMap& src )
   : decaf::util::Map<std::string, PrimitiveValueNode>( src ) {
 }

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.h?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveMap.h Sat May 31 13:24:58 2008
@@ -44,6 +44,12 @@
 
         /**
          * Copy Constructor
+         * @param map - the Decaf Map of PrimitiveValueNodes to copy
+         */
+        PrimitiveMap( const decaf::util::Map<std::string, PrimitiveValueNode>& src );
+
+        /**
+         * Copy Constructor
          * @param map - the PrimitiveMap to copy
          */
         PrimitiveMap( const PrimitiveMap& src );

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.cpp?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.cpp Sat May 31 13:24:58 2008
@@ -17,6 +17,7 @@
 
 #include "PrimitiveValueNode.h"
 
+#include <activemq/util/PrimitiveList.h>
 #include <activemq/util/PrimitiveMap.h>
 
 using namespace std;
@@ -89,6 +90,20 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+PrimitiveValueNode::PrimitiveValueNode(
+    const decaf::util::List<PrimitiveValueNode>& value ) {
+
+    this->setList( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+PrimitiveValueNode::PrimitiveValueNode(
+    const decaf::util::Map<std::string, PrimitiveValueNode>& value ) {
+
+    this->setMap( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 PrimitiveValueNode::PrimitiveValueNode( const PrimitiveValueNode& node ){
     valueType = NULL_TYPE;
     memset( &value, 0, sizeof(value) );
@@ -98,16 +113,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 PrimitiveValueNode& PrimitiveValueNode::operator =( const PrimitiveValueNode& node ){
     clear();
-    valueType = node.valueType;
-
-    if( valueType == STRING_TYPE && node.value.stringValue != NULL ){
-        value.stringValue = new std::string( *node.value.stringValue );
-    } else if( valueType == BYTE_ARRAY_TYPE && node.value.byteArrayValue != NULL ){
-        value.byteArrayValue = new std::vector<unsigned char>( *node.value.byteArrayValue );
-    } else{
-        value = node.value;
-    }
-
+    this->setValue( node.getValue(), node.getValueType() );
     return *this;
 }
 
@@ -148,6 +154,12 @@
     } else if( valueType == BYTE_ARRAY_TYPE &&
         *value.byteArrayValue == *node.value.byteArrayValue ) {
             return true;
+    } else if( valueType == LIST_TYPE &&
+        value.listValue->equals( *node.value.listValue ) ) {
+            return true;
+    } else if( valueType == MAP_TYPE &&
+        value.mapValue->equals( *node.value.mapValue ) ) {
+            return true;
     }
 
     return false;
@@ -155,17 +167,55 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void PrimitiveValueNode::clear(){
+
     if( valueType == STRING_TYPE && value.stringValue != NULL ){
         delete value.stringValue;
-    }
-    if( valueType == BYTE_ARRAY_TYPE && value.byteArrayValue != NULL ){
+    } else if( valueType == BYTE_ARRAY_TYPE && value.byteArrayValue != NULL ){
         delete value.byteArrayValue;
+    } else if( valueType == LIST_TYPE && value.listValue != NULL ){
+        delete value.listValue;
+    } else if( valueType == MAP_TYPE && value.mapValue != NULL ){
+        delete value.mapValue;
     }
+
     valueType = NULL_TYPE;
     memset( &value, 0, sizeof(value) );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void PrimitiveValueNode::setValue(
+    const PrimitiveValue& value, PrimitiveValueTypeEnum valueType ) {
+
+    if( valueType == BOOLEAN_TYPE ) {
+        this->setBool( value.boolValue );
+    } else if( valueType == BYTE_TYPE ) {
+        this->setByte( value.byteValue );
+    } else if( valueType == CHAR_TYPE ) {
+        this->setChar( value.charValue );
+    } else if( valueType == SHORT_TYPE ) {
+        this->setShort( value.shortValue );
+    } else if(  valueType == INTEGER_TYPE ) {
+        this->setInt( value.intValue );
+    } else if( valueType == LONG_TYPE ) {
+        this->setLong( value.longValue );
+    } else if( valueType == DOUBLE_TYPE ) {
+        this->setDouble( value.doubleValue );
+    } else if( valueType == FLOAT_TYPE ) {
+        this->setFloat( value.floatValue );
+    } else if( valueType == STRING_TYPE || valueType == BIG_STRING_TYPE ) {
+        this->setString( *value.stringValue );
+    } else if( valueType == BYTE_ARRAY_TYPE ) {
+        this->setByteArray( *value.byteArrayValue );
+    } else if( valueType == LIST_TYPE ) {
+        this->setList( *value.listValue );
+    } else if( valueType == MAP_TYPE ) {
+        this->setMap( *value.mapValue );
+    } else {
+        this->clear();
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void PrimitiveValueNode::setBool( bool lvalue ){
     clear();
     valueType = BOOLEAN_TYPE;
@@ -349,6 +399,58 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void PrimitiveValueNode::setList( const decaf::util::List<PrimitiveValueNode>& lvalue ){
+    clear();
+    valueType = LIST_TYPE;
+    value.listValue = new decaf::util::List<PrimitiveValueNode>( lvalue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::util::List<PrimitiveValueNode> PrimitiveValueNode::getList() const
+    throw( decaf::lang::exceptions::NoSuchElementException ) {
+
+    if( valueType != LIST_TYPE ){
+        throw decaf::lang::exceptions::NoSuchElementException(
+            __FILE__,
+            __LINE__,
+            "PrimitiveValue is not LIST_TYPE" );
+    }
+
+    if( value.listValue == NULL ){
+        return decaf::util::List<PrimitiveValueNode>();
+    }
+
+    return *value.listValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void PrimitiveValueNode::setMap(
+    const decaf::util::Map<std::string, PrimitiveValueNode>& lvalue ){
+
+    clear();
+    valueType = MAP_TYPE;
+    value.mapValue = new decaf::util::Map<std::string, PrimitiveValueNode>( lvalue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::util::Map<std::string, PrimitiveValueNode> PrimitiveValueNode::getMap() const
+    throw( decaf::lang::exceptions::NoSuchElementException ) {
+
+    if( valueType != MAP_TYPE ){
+        throw decaf::lang::exceptions::NoSuchElementException(
+            __FILE__,
+            __LINE__,
+            "PrimitiveValue is not MAP_TYPE" );
+    }
+
+    if( value.mapValue == NULL ){
+        return decaf::util::Map<std::string, PrimitiveValueNode>();
+    }
+
+    return *value.mapValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
 std::string PrimitiveValueNode::toString() const {
     std::ostringstream stream;
 
@@ -368,7 +470,7 @@
         stream << value.doubleValue;
     } else if( valueType == FLOAT_TYPE ) {
         stream << value.floatValue;
-    } else if( valueType == STRING_TYPE ) {
+    } else if( valueType == STRING_TYPE || valueType == BIG_STRING_TYPE ) {
         stream << *value.stringValue;
     } else if( valueType == BYTE_ARRAY_TYPE ) {
         std::vector<unsigned char>::const_iterator iter =
@@ -376,7 +478,10 @@
         for( ; iter != value.byteArrayValue->end(); ++iter ) {
             stream << '[' << (int)(*iter) << ']';
         }
+    } else if( valueType == LIST_TYPE ) {
+        stream << PrimitiveList( *value.listValue ).toString();
+    } else if( valueType == MAP_TYPE ) {
+        stream << PrimitiveMap( *value.mapValue ).toString();
     }
-
     return stream.str();
 }

Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.h?rev=662076&r1=662075&r2=662076&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/PrimitiveValueNode.h Sat May 31 13:24:58 2008
@@ -20,13 +20,12 @@
 
 #include <activemq/util/Config.h>
 #include <decaf/lang/exceptions/NoSuchElementException.h>
+#include <decaf/util/Map.h>
+#include <decaf/util/List.h>
 
 namespace activemq{
 namespace util{
 
-    class PrimitiveMap;
-    class PrimitiveList;
-
     /**
      * Class that wraps around a single value of one of the
      * many types.  Manages memory for complex types, such
@@ -73,9 +72,9 @@
             double doubleValue;
             float floatValue;
             std::string* stringValue;
-            PrimitiveMap* mapValue;
-            PrimitiveList* listValue;
             std::vector<unsigned char>* byteArrayValue;
+            decaf::util::List<PrimitiveValueNode>* listValue;
+            decaf::util::Map<std::string, PrimitiveValueNode>* mapValue;
 
         };
 
@@ -158,6 +157,19 @@
         PrimitiveValueNode( const std::vector<unsigned char>& value );
 
         /**
+         * Primtive List Constructor
+         * @param value - the new value to store.
+         */
+        PrimitiveValueNode( const decaf::util::List<PrimitiveValueNode>& value );
+
+        /**
+         * Primtive Map Value Constructor
+         * @param value - the new value to store.
+         */
+        PrimitiveValueNode(
+            const decaf::util::Map<std::string, PrimitiveValueNode>& value );
+
+        /**
          * Copy constructor
          * @param another node to copy.
          */
@@ -200,10 +212,7 @@
          * Sets the internal PrimitiveVale object to the new value
          * along with the tag for the type that it consists of.
          */
-        void setValue( const PrimitiveValue& value, PrimitiveValueTypeEnum valueType ) {
-            this->value = value;
-            this->valueType = valueType;
-        }
+        void setValue( const PrimitiveValue& value, PrimitiveValueTypeEnum valueType );
 
         /**
          * Clears the value from this wrapper converting it back to a blank
@@ -382,6 +391,40 @@
             throw( decaf::lang::exceptions::NoSuchElementException );
 
         /**
+         * Sets the value of this value node to the new value specified,
+         * this method overwrites any data that was previously at the index
+         * given.
+         * @param value - the new value to assign to the element at index
+         */
+        void setList( const decaf::util::List<PrimitiveValueNode>& lvalue );
+
+        /**
+         * Gets the Primtive List value of this Node.
+         * @return value contained at the given index
+         * @throw NoSuchElementException this node cannot be returned as the
+         * requested type.
+         */
+        decaf::util::List<PrimitiveValueNode> getList() const
+            throw( decaf::lang::exceptions::NoSuchElementException );
+
+        /**
+         * Sets the value of this value node to the new value specified,
+         * this method overwrites any data that was previously at the index
+         * given.
+         * @param value - the new value to assign to the element at index
+         */
+        void setMap( const decaf::util::Map<std::string, PrimitiveValueNode>& lvalue );
+
+        /**
+         * Gets the Primtive Map value of this Node.
+         * @return value contained at the given index
+         * @throw NoSuchElementException this node cannot be returned as the
+         * requested type.
+         */
+        decaf::util::Map<std::string, PrimitiveValueNode> getMap() const
+            throw( decaf::lang::exceptions::NoSuchElementException );
+
+        /**
          * Creates a string representation of this value.
          * @return string value of this type wrapper.
          */