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/01/19 16:28:36 UTC
svn commit: r497843 - in
/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src:
main/activemq/util/PrimitiveMap.cpp main/activemq/util/PrimitiveMap.h
test/activemq/util/PrimitiveMapTest.cpp
Author: tabish
Date: Fri Jan 19 07:28:35 2007
New Revision: 497843
URL: http://svn.apache.org/viewvc?view=rev&rev=497843
Log:
http://issues.apache.org/activemq/browse/AMQCPP-30
Modified:
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/PrimitiveMapTest.cpp
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=497843&r1=497842&r2=497843
==============================================================================
--- 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 Fri Jan 19 07:28:35 2007
@@ -195,6 +195,24 @@
}
////////////////////////////////////////////////////////////////////////////////
+std::vector<unsigned char> PrimitiveMap::getByteArray( const std::string& key ) const
+ throw( activemq::exceptions::NoSuchElementException ) {
+
+ ValueNode node = valueNodeMap.getValue( key );
+ return node.getByteArray();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void PrimitiveMap::setByteArray( const std::string& key,
+ const std::vector<unsigned char>& value ) {
+
+ ValueNode node;
+ node.setByteArray( value );
+
+ valueNodeMap.setValue( key, node );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void PrimitiveMap::remove( const string& key ){
valueNodeMap.remove( key );
}
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=497843&r1=497842&r2=497843
==============================================================================
--- 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 Fri Jan 19 07:28:35 2007
@@ -305,8 +305,31 @@
return *value.stringValue;
}
+ void setByteArray( const std::vector<unsigned char>& lvalue ){
+ clear();
+ valueType = BYTE_ARRAY_TYPE;
+ value.byteArrayValue = new std::vector<unsigned char>( lvalue );
+ }
+
+ std::vector<unsigned char> getByteArray() const throw( activemq::exceptions::NoSuchElementException ) {
+
+ if( valueType != BYTE_ARRAY_TYPE ){
+ throw activemq::exceptions::NoSuchElementException(
+ __FILE__,
+ __LINE__,
+ "Value is not BYTE_ARRAY_TYPE" );
+ }
+
+ if( value.byteArrayValue == NULL ){
+ return std::vector<unsigned char>();
+ }
+
+ return *value.byteArrayValue;
+ }
+
};
+
private:
activemq::util::Map<std::string, ValueNode> valueNodeMap;
@@ -371,6 +394,10 @@
throw(activemq::exceptions::NoSuchElementException);
virtual void setString( const std::string& key, const std::string& value );
+ virtual std::vector<unsigned char> getByteArray( const std::string& key ) const
+ throw( activemq::exceptions::NoSuchElementException );
+ virtual void setByteArray( const std::string& key, const std::vector<unsigned char>& value );
+
/**
* Removes the value (key/value pair) for the specified key from
* the map.
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=497843&r1=497842&r2=497843
==============================================================================
--- 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 Fri Jan 19 07:28:35 2007
@@ -63,7 +63,17 @@
node.setString( "hello" );
CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::STRING_TYPE );
CPPUNIT_ASSERT( node.getString() == "hello" );
-
+
+ std::vector<unsigned char> byteArray;
+ byteArray.push_back( 'a' );
+ byteArray.push_back( 'b' );
+ byteArray.push_back( 'c' );
+ byteArray.push_back( 'd' );
+
+ node.setByteArray( byteArray );
+ CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::BYTE_ARRAY_TYPE );
+ CPPUNIT_ASSERT( node.getByteArray() == byteArray );
+
try{
node.getFloat();
CPPUNIT_ASSERT( false );
@@ -142,6 +152,20 @@
} catch( activemq::exceptions::NoSuchElementException& e ){}
pmap.setString( "string", "hello" );
CPPUNIT_ASSERT( pmap.getString("string") == "hello" );
+
+ std::vector<unsigned char> byteArray;
+ byteArray.push_back( 'a' );
+ byteArray.push_back( 'b' );
+ byteArray.push_back( 'c' );
+ byteArray.push_back( 'd' );
+
+ try{
+ pmap.getByteArray( "byteArray" );
+ CPPUNIT_ASSERT( false );
+ } catch( activemq::exceptions::NoSuchElementException& e ){}
+ pmap.setByteArray( "byteArray", byteArray );
+ CPPUNIT_ASSERT( pmap.getByteArray("byteArray") == byteArray );
+
}
void PrimitiveMapTest::testRemove(){