activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r497476 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/util/ test/activemq/util/
Date Thu, 18 Jan 2007 16:06:09 GMT
Author: tabish
Date: Thu Jan 18 08:06:09 2007
New Revision: 497476

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

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Map.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Map.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Map.h?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Map.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Map.h Thu Jan
18 08:06:09 2007
@@ -52,12 +52,26 @@
          * @param key The key to look up.
          * @return true if this map contains the value, otherwise false.
          */
-        virtual bool contains( const K& key ) const;
+        virtual bool containsKey( const K& key ) const;
         
         /**
+         * Indicates whether or this map contains a value for the
+         * given value, i.e. they are equal, this is done by operator==
+         * so the types must pass equivalence testing in this manner.
+         * @param value The Value to look up.
+         * @return true if this map contains the value, otherwise false.
+         */
+        virtual bool containsValue( const V& value ) const;
+
+        /**
+         * @return if the Map contains any element or not, TRUE or FALSE
+         */
+        virtual bool isEmpty() const;
+
+        /**
          * @return The number of elements (key/value pairs) in this map.
          */
-        virtual int count() const;
+        virtual unsigned int size() const;
         
         /**
          * Gets the value for the specified key.
@@ -101,7 +115,7 @@
     
     ////////////////////////////////////////////////////////////////////////////
     template <typename K, typename V>
-    bool Map<K,V>::contains(const K& key) const{
+    bool Map<K,V>::containsKey(const K& key) const{
         typename std::map<K,V>::const_iterator iter;
         iter = valueMap.find(key);
         return iter != valueMap.end();
@@ -109,7 +123,31 @@
     
     ////////////////////////////////////////////////////////////////////////////
     template <typename K, typename V>
-    int Map<K,V>::count() const{
+    bool Map<K,V>::containsValue( const V& value ) const {
+
+        if( valueMap.empty() ){
+            return false;
+        }
+
+        typename std::map<K,V>::const_iterator iter = valueMap.begin();        
+        for( ; iter != valueMap.end(); ++iter ){
+            if( (*iter).second == value ) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    template <typename K, typename V>
+    bool Map<K,V>::isEmpty() const{
+        return valueMap.empty();
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    template <typename K, typename V>
+    unsigned int Map<K,V>::size() const{
         return valueMap.size();
     }
     

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
Thu Jan 18 08:06:09 2007
@@ -40,13 +40,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool PrimitiveMap::contains( const string& key ) const{
     
-    return valueNodeMap.contains( key );
+    return valueNodeMap.containsKey( key );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int PrimitiveMap::count() const{
+unsigned int PrimitiveMap::size() const{
     
-    return valueNodeMap.count();
+    return valueNodeMap.size();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h
Thu Jan 18 08:06:09 2007
@@ -44,8 +44,8 @@
             LONG_TYPE               = 6,
             DOUBLE_TYPE             = 7,
             FLOAT_TYPE              = 8,
-            STRING_TYPE             = 9
-            //BYTE_ARRAY_TYPE         = 10,
+            STRING_TYPE             = 9,
+            BYTE_ARRAY_TYPE         = 10
             //MAP_TYPE                = 11,
             //LIST_TYPE               = 12,
             //BIG_STRING_TYPE         = 13
@@ -65,6 +65,7 @@
             double doubleValue;
             float floatValue;
             std::string* stringValue;
+            std::vector<unsigned char>* byteArrayValue;
         };
     
         /**
@@ -105,6 +106,8 @@
                 
                 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;
                 }
@@ -112,6 +115,47 @@
                 return *this;
             }
             
+            bool operator==( const ValueNode& node ) const{
+
+                if( valueType != node.valueType ) {
+                     return false; 
+                }
+
+                if( valueType == BOOLEAN_TYPE &&
+                    value.boolValue == node.value.boolValue ) {
+                        return true;
+                } else if( valueType == BYTE_TYPE &&
+                    value.byteValue == node.value.byteValue ) {
+                        return true;
+                } else if( valueType == CHAR_TYPE &&
+                    value.charValue == node.value.charValue ) {
+                        return true;
+                } else if( valueType == SHORT_TYPE &&
+                    value.shortValue == node.value.shortValue ) {
+                        return true;
+                } else if(  valueType == INTEGER_TYPE &&
+                    value.intValue == node.value.intValue ) {
+                        return true;
+                } else if( valueType == LONG_TYPE &&
+                    value.longValue == node.value.longValue ) {
+                        return true;
+                } else if( valueType == DOUBLE_TYPE &&
+                    value.doubleValue == node.value.doubleValue ) {
+                        return true;
+                } else if( valueType == FLOAT_TYPE &&
+                    value.floatValue == node.value.floatValue ) {
+                        return true;
+                } else if( valueType == STRING_TYPE &&
+                    *value.stringValue == *node.value.stringValue ) {
+                        return true;
+                } else if( valueType == BYTE_ARRAY_TYPE &&
+                    *value.byteArrayValue == *node.value.byteArrayValue ) {
+                        return true;
+                }
+                
+                return false;
+            }
+            
             ValueTypeEnum getValueType() const { return valueType; }
             
             void clear(){
@@ -288,7 +332,7 @@
         /**
          * @return The number of elements (key/value pairs) in this map.
          */
-        virtual int count() const;
+        virtual unsigned int size() const;
         
 
         virtual bool getBool( const std::string& key ) const 

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.cpp?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.cpp
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.cpp
Thu Jan 18 08:06:09 2007
@@ -31,15 +31,15 @@
 {
 }
 
-void MapTest::testContains(){
+void MapTest::testContainsKey(){
     
     Map<string, bool> boolMap;
-    CPPUNIT_ASSERT(boolMap.contains("bob") == false);
+    CPPUNIT_ASSERT(boolMap.containsKey("bob") == false);
     
     boolMap.setValue( "bob", true );
     
-    CPPUNIT_ASSERT(boolMap.contains("bob") == true );
-    CPPUNIT_ASSERT(boolMap.contains("fred") == false );
+    CPPUNIT_ASSERT(boolMap.containsKey("bob") == true );
+    CPPUNIT_ASSERT(boolMap.containsKey("fred") == false );
 }
 
 void MapTest::testClear(){
@@ -48,26 +48,31 @@
     boolMap.setValue( "bob", true );
     boolMap.setValue( "fred", true );
     
-    CPPUNIT_ASSERT(boolMap.count() == 2 );
-    
+    CPPUNIT_ASSERT(boolMap.size() == 2 );
     boolMap.clear();
-    
-    CPPUNIT_ASSERT(boolMap.count() == 0 );
+    CPPUNIT_ASSERT(boolMap.size() == 0 );
 }
 
-void MapTest::testCount(){
+void MapTest::testIsEmpty(){
     
     Map<string, bool> boolMap;
-    
-    CPPUNIT_ASSERT(boolMap.count() == 0 );
-    
     boolMap.setValue( "bob", true );
+    boolMap.setValue( "fred", true );
+
+    CPPUNIT_ASSERT(boolMap.isEmpty() == false );
+    boolMap.clear();
+    CPPUNIT_ASSERT(boolMap.isEmpty() == true );
+}
+
+void MapTest::testSize(){
     
-    CPPUNIT_ASSERT(boolMap.count() == 1 );
+    Map<string, bool> boolMap;
     
+    CPPUNIT_ASSERT(boolMap.size() == 0 );
+    boolMap.setValue( "bob", true );
+    CPPUNIT_ASSERT(boolMap.size() == 1 );
     boolMap.setValue( "fred", true );
-    
-    CPPUNIT_ASSERT(boolMap.count() == 2 );
+    CPPUNIT_ASSERT(boolMap.size() == 2 );
 }
 
 void MapTest::testValue(){
@@ -92,8 +97,17 @@
     Map<string, bool> boolMap;
     
     boolMap.setValue( "fred", true );    
-    CPPUNIT_ASSERT( boolMap.contains("fred") == true );
+    CPPUNIT_ASSERT( boolMap.containsKey("fred") == true );
     boolMap.remove( "fred" );
-    CPPUNIT_ASSERT( boolMap.contains("fred") == false );    
+    CPPUNIT_ASSERT( boolMap.containsKey("fred") == false );    
 }
 
+void MapTest::testContiansValue(){
+    Map<string, bool> boolMap;
+    
+    boolMap.setValue( "fred", true );
+    boolMap.setValue( "fred1", false );
+    CPPUNIT_ASSERT( boolMap.containsValue(true) == true );
+    boolMap.remove( "fred" );
+    CPPUNIT_ASSERT( boolMap.containsValue(true) == false );
+}

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.h?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/MapTest.h Thu
Jan 18 08:06:09 2007
@@ -29,22 +29,27 @@
     class MapTest : public CppUnit::TestFixture
     {
         CPPUNIT_TEST_SUITE( MapTest );
-        CPPUNIT_TEST( testContains );
+        CPPUNIT_TEST( testContainsKey );
         CPPUNIT_TEST( testClear );
-        CPPUNIT_TEST( testCount );
+        CPPUNIT_TEST( testSize );
         CPPUNIT_TEST( testValue );
         CPPUNIT_TEST( testRemove );
+        CPPUNIT_TEST( testContiansValue );
+        CPPUNIT_TEST( testIsEmpty );
         CPPUNIT_TEST_SUITE_END();
         
     public:
     	MapTest();
     	virtual ~MapTest();
         
-        void testContains();
+        void testContainsKey();
         void testClear();
-        void testCount();
+        void testSize();
         void testValue();
         void testRemove();
+        void testContiansValue();
+        void testIsEmpty();
+        
     };
 
 }}

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp?view=diff&rev=497476&r1=497475&r2=497476
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp
Thu Jan 18 08:06:09 2007
@@ -160,15 +160,15 @@
 void PrimitiveMapTest::testCount(){
     
     PrimitiveMap pmap;
-    CPPUNIT_ASSERT( pmap.count() == 0 );
+    CPPUNIT_ASSERT( pmap.size() == 0 );
     pmap.setInt("int", 5 );
-    CPPUNIT_ASSERT( pmap.count() == 1);
+    CPPUNIT_ASSERT( pmap.size() == 1);
     pmap.setFloat( "float", 5.5f );
-    CPPUNIT_ASSERT( pmap.count() == 2 );
+    CPPUNIT_ASSERT( pmap.size() == 2 );
     pmap.setInt("int2", 6 );
-    CPPUNIT_ASSERT( pmap.count() == 3 );
+    CPPUNIT_ASSERT( pmap.size() == 3 );
     pmap.remove("int");
-    CPPUNIT_ASSERT( pmap.count() == 2 );
+    CPPUNIT_ASSERT( pmap.size() == 2 );
 }
 
 void PrimitiveMapTest::testClear(){
@@ -179,7 +179,7 @@
     pmap.setInt("int2", 6 );
     
     pmap.clear();
-    CPPUNIT_ASSERT( pmap.count() == 0 );
+    CPPUNIT_ASSERT( pmap.size() == 0 );
     
     try{
         pmap.getInt("int");



Mime
View raw message