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 2009/02/13 21:38:57 UTC
svn commit: r744235 - in /activemq/activemq-cpp/trunk/src:
main/activemq/state/ main/decaf/util/ main/decaf/util/concurrent/ test/
test/decaf/util/
Author: tabish
Date: Fri Feb 13 20:38:57 2009
New Revision: 744235
URL: http://svn.apache.org/viewvc?rev=744235&view=rev
Log:
More refinements to the decaf Map classes and some additional Testing.
Removed:
activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.cpp
activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.h
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.cpp
activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.h
activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h
activemq/activemq-cpp/trunk/src/main/decaf/util/StlMap.h
activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/ConcurrentStlMap.h
activemq/activemq-cpp/trunk/src/test/Makefile.am
activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.cpp
activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.h
activemq/activemq-cpp/trunk/src/test/testRegistry.cpp
Modified: activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.cpp?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.cpp Fri Feb 13 20:38:57 2009
@@ -23,15 +23,13 @@
using namespace activemq::state;
////////////////////////////////////////////////////////////////////////////////
-ConnectionState::ConnectionState( commands::ConnectionInfo* info ) : disposed( false ) {
+ConnectionState::ConnectionState( const Pointer<ConnectionInfo>& info ) : disposed( false ) {
- this->info.reset( info->cloneDataStructure() );
+ this->info = info;
}
////////////////////////////////////////////////////////////////////////////////
ConnectionState::~ConnectionState() {
-
- // TODO - Free all pointers.
}
////////////////////////////////////////////////////////////////////////////////
@@ -45,12 +43,22 @@
}
////////////////////////////////////////////////////////////////////////////////
+void ConnectionState::reset( const Pointer<ConnectionInfo>& info ) {
+
+ this->info = info;
+ transactions.clear();
+ sessions.clear();
+ tempDestinations.clear();
+ disposed.set( false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void ConnectionState::shutdown() {
if( this->disposed.compareAndSet( false, true ) ) {
- std::vector<SessionState*> values = this->sessions.values();
- std::vector<SessionState*>::iterator iter = values.begin();
+ std::vector< Pointer<SessionState> > values = this->sessions.values();
+ std::vector< Pointer<SessionState> >::iterator iter = values.begin();
for( ; iter != values.end(); ++iter ) {
(*iter)->shutdown();
Modified: activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.h?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionState.h Fri Feb 13 20:38:57 2009
@@ -31,8 +31,9 @@
#include <activemq/state/TransactionState.h>
#include <decaf/util/concurrent/atomic/AtomicBoolean.h>
-#include <decaf/util/StlMap.h>
+#include <decaf/util/concurrent/ConcurrentStlMap.h>
#include <decaf/util/StlList.h>
+#include <decaf/lang/Pointer.h>
#include <string>
#include <memory>
@@ -40,62 +41,68 @@
namespace activemq {
namespace state {
+ using decaf::lang::Pointer;
+ using decaf::util::concurrent::ConcurrentStlMap;
+ using namespace activemq::commands;
+
class ConnectionState {
private:
- std::auto_ptr<commands::ConnectionInfo> info;
- decaf::util::StlMap< commands::TransactionId, TransactionState* > transactions;
- decaf::util::StlMap< commands::SessionId, SessionState* > sessions;
- decaf::util::StlList< commands::DestinationInfo* > tempDestinations;
+ Pointer< ConnectionInfo > info;
+ ConcurrentStlMap< Pointer<TransactionId>,
+ Pointer<TransactionState>,
+ TransactionId::COMPARATOR > transactions;
+ ConcurrentStlMap< Pointer<SessionId>,
+ Pointer<SessionState>,
+ SessionId::COMPARATOR > sessions;
+ decaf::util::StlList< Pointer<DestinationInfo> > tempDestinations;
decaf::util::concurrent::atomic::AtomicBoolean disposed;
public:
- ConnectionState( commands::ConnectionInfo* info );
+ ConnectionState( const Pointer<ConnectionInfo>& info );
virtual ~ConnectionState();
std::string toString() const;
- const commands::ConnectionInfo* getInfo() const {
- return this->info.get();
+ const Pointer<commands::ConnectionInfo>& getInfo() const {
+ return this->info;
}
void checkShutdown() const;
void shutdown();
-// void reset(ConnectionInfo info) {
-// this.info = info;
-// transactions.clear();
-// sessions.clear();
-// tempDestinations.clear();
-// shutdown.set(false);
-// }
-//
-// void addTempDestination(DestinationInfo info) {
-// checkShutdown();
-// tempDestinations.add(info);
-// }
-//
-// void removeTempDestination(ActiveMQDestination destination) {
-// for (Iterator<DestinationInfo> iter = tempDestinations.iterator(); iter.hasNext();) {
-// DestinationInfo di = iter.next();
-// if (di.getDestination().equals(destination)) {
-// iter.remove();
-// }
-// }
-// }
-//
-// void addTransactionState(TransactionId id) {
-// checkShutdown();
-// transactions.put(id, new TransactionState(id));
-// }
-//
-// TransactionState getTransactionState(TransactionId id) {
-// return transactions.get(id);
-// }
-//
+ void reset( const Pointer<ConnectionInfo>& info );
+
+ void addTempDestination( const Pointer<DestinationInfo>& info ) {
+ checkShutdown();
+ tempDestinations.add( info );
+ }
+
+ void removeTempDestination( const Pointer<ActiveMQDestination>& destination ) {
+
+ std::auto_ptr< decaf::util::Iterator< Pointer<DestinationInfo> > > iter(
+ tempDestinations.iterator() );
+
+ while( iter->hasNext() ) {
+ Pointer<DestinationInfo> di = iter->next();
+ if( di->getDestination()->equals( destination.get() ) ) {
+ iter->remove();
+ }
+ }
+ }
+
+ void addTransactionState( const Pointer<TransactionId>& id ) {
+ checkShutdown();
+ transactions.put( id, Pointer<TransactionState>( new TransactionState( id ) ) );
+ }
+
+ const Pointer<TransactionState>& getTransactionState( const Pointer<TransactionId>& id ) const {
+ return transactions.get( id );
+ }
+
// Collection<TransactionState> getTransactionStates() {
// return transactions.values();
// }
@@ -104,23 +111,20 @@
// return transactions.remove(id);
// }
//
-// void addSession(SessionInfo info) {
-// checkShutdown();
-// sessions.put(info.getSessionId(), new SessionState(info));
-// }
-//
+ void addSession( const Pointer<SessionInfo>& info ) {
+ checkShutdown();
+ sessions.put(
+ info->getSessionId(), Pointer<SessionState>( new SessionState( info ) ) );
+ }
+
// SessionState removeSession(SessionId id) {
// return sessions.remove(id);
// }
-//
-// SessionState getSessionState(SessionId id) {
-// return sessions.get(id);
-// }
-//
-// ConnectionInfo getInfo() {
-// return info;
-// }
-//
+
+ const Pointer<SessionState>& getSessionState( const Pointer<SessionId>& id ) const {
+ return sessions.get( id );
+ }
+
// Set<SessionId> getSessionIds() {
// return sessions.keySet();
// }
Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h Fri Feb 13 20:38:57 2009
@@ -19,6 +19,7 @@
#define _DECAF_UTIL_MAP_H_
#include <vector>
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
#include <decaf/lang/exceptions/NoSuchElementException.h>
#include <decaf/util/concurrent/Synchronizable.h>
#include <decaf/util/concurrent/Mutex.h>
@@ -81,8 +82,9 @@
/**
* Removes all keys and values from this map.
+ * @throw UnsupportedOperationException if this map is unmodifiable.
*/
- virtual void clear() = 0;
+ virtual void clear() throw( decaf::lang::exceptions::UnsupportedOperationException ) = 0;
/**
* Indicates whether or this map contains a value for the
@@ -112,34 +114,51 @@
virtual std::size_t size() const = 0;
/**
- * Gets the value for the specified key.
+ * Gets the value mapped to the specified key in the Map. If there is no
+ * element in the map whose key is equivalent to the key provided then a
+ * NoSuchElementException is thrown.
+ *
* @param key The search key.
- * @return The value for the given key.
+ * @return A reference to the value for the given key.
+ *
* @throws NoSuchElementException
*/
- virtual V get( const K& key ) const
+ virtual V& get( const K& key )
+ throw( lang::exceptions::NoSuchElementException ) = 0;
+ virtual const V& get( const K& key ) const
throw( lang::exceptions::NoSuchElementException ) = 0;
/**
* Sets the value for the specified key.
* @param key The target key.
* @param value The value to be set.
+ *
+ * @throw UnsupportedOperationException if this map is unmodifiable.
*/
- virtual void put( const K& key, V value ) = 0;
+ virtual void put( const K& key, const V& value )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) = 0;
/**
* Stores a copy of the Mappings contained in the other Map in this one.
* @param key The target key.
* @param value The value to be set.
*/
- virtual void putAll( const Map<K,V,COMPARATOR>& other ) = 0;
+ virtual void putAll( const Map<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) = 0;
/**
* Removes the value (key/value pair) for the specified key from
- * the map.
+ * the map, returns a copy of the value that was mapped to the key.
+ *
* @param key The search key.
- */
- virtual void remove( const K& key ) = 0;
+ * @return a copy of the element that was previously mapped to the given key
+ *
+ * @throw NoSuchElementException if this key is not in the Map.
+ * @throw UnsupportedOperationException if this map is unmodifiable.
+ */
+ virtual V remove( const K& key )
+ throw ( decaf::lang::exceptions::NoSuchElementException,
+ decaf::lang::exceptions::UnsupportedOperationException ) = 0;
/**
* @return the entire set of keys in this map as a std::vector.
Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/StlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/StlMap.h?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/StlMap.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/StlMap.h Fri Feb 13 20:38:57 2009
@@ -68,10 +68,7 @@
virtual ~StlMap() {}
/**
- * Comparison, equality is dependent on the method of determining
- * if the element are equal.
- * @param source - Map to compare to this one.
- * @returns true if the Map passed is equal in value to this one.
+ * {@inheritDoc}
*/
virtual bool equals( const StlMap& source ) const {
return this->valueMap == source.valueMap;
@@ -95,9 +92,7 @@
}
/**
- * Copies the content of the source map into this map. Erases
- * all existing data in this map.
- * @param source The source object to copy from.
+ * {@inheritDoc}
*/
virtual void copy( const StlMap& source ) {
this->valueMap.clear();
@@ -110,17 +105,14 @@
}
/**
- * Removes all keys and values from this map.
+ * {@inheritDoc}
*/
- virtual void clear() {
+ virtual void clear() throw( decaf::lang::exceptions::UnsupportedOperationException ) {
valueMap.clear();
}
/**
- * Indicates whether or this map contains a value for the
- * given key.
- * @param key The key to look up.
- * @return true if this map contains the value, otherwise false.
+ * {@inheritDoc}
*/
virtual bool containsKey( const K& key ) const {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
@@ -129,11 +121,7 @@
}
/**
- * 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.
+ * {@inheritDoc}
*/
virtual bool containsValue( const V& value ) const {
@@ -152,30 +140,39 @@
}
/**
- * @return if the Map contains any element or not, TRUE or FALSE
+ * {@inheritDoc}
*/
virtual bool isEmpty() const {
return valueMap.empty();
}
/**
- * @return The number of elements (key/value pairs) in this map.
+ * {@inheritDoc}
*/
virtual std::size_t size() const {
return valueMap.size();
}
/**
- * Gets the value for the specified key.
- * @param key The search key.
- * @return The value for the given key.
- * @throws NoSuchElementException
+ * {@inheritDoc}
*/
- virtual V get( const K& key ) const
+ virtual V& get( const K& key )
+ throw( lang::exceptions::NoSuchElementException ) {
+
+ typename std::map<K,V,COMPARATOR>::iterator iter;
+ iter = valueMap.find( key );
+ if( iter == valueMap.end() ){
+ throw lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key does not exist in map" );
+ }
+
+ return iter->second;
+ }
+ virtual const V& get( const K& key ) const
throw( lang::exceptions::NoSuchElementException ) {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
- iter = valueMap.find(key);
+ iter = valueMap.find( key );
if( iter == valueMap.end() ){
throw lang::exceptions::NoSuchElementException(
__FILE__, __LINE__, "Key does not exist in map" );
@@ -185,23 +182,25 @@
}
/**
- * Sets the value for the specified key.
- * @param key The target key.
- * @param value The value to be set.
+ * {@inheritDoc}
*/
- virtual void put( const K& key, V value ) {
+ virtual void put( const K& key, const V& value )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
valueMap[key] = value;
}
/**
- * Stores a copy of the Mappings contained in the other Map in this one.
- * @param key The target key.
- * @param value The value to be set.
+ * {@inheritDoc}
*/
- virtual void putAll( const StlMap<K,V,COMPARATOR>& other ) {
+ virtual void putAll( const StlMap<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
this->valueMap.insert( other.valueMap.begin(), other.valueMap.end() );
}
- virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
+ virtual void putAll( const Map<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
std::vector<K> keys = other.keySet();
typename std::vector<K>::const_iterator iter = keys.begin();
@@ -212,16 +211,25 @@
}
/**
- * Removes the value (key/value pair) for the specified key from
- * the map.
- * @param key The search key.
+ * {@inheritDoc}
*/
- virtual void remove( const K& key ) {
- valueMap.erase( key );
+ virtual V remove( const K& key )
+ throw ( decaf::lang::exceptions::NoSuchElementException,
+ decaf::lang::exceptions::UnsupportedOperationException ) {
+
+ typename std::map<K,V,COMPARATOR>::iterator iter = valueMap.find( key );
+ if( iter == valueMap.end() ) {
+ throw decaf::lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key is not present in this Map." );
+ }
+
+ V result = iter->second;
+ valueMap.erase( iter );
+ return result;
}
/**
- * @return the entire set of keys in this map as a std::vector.
+ * {@inheritDoc}
*/
virtual std::vector<K> keySet() const{
std::vector<K> keys( valueMap.size() );
@@ -236,7 +244,7 @@
}
/**
- * @return the entire set of values in this map as a std::vector.
+ * {@inheritDoc}
*/
virtual std::vector<V> values() const {
std::vector<V> values( valueMap.size() );
@@ -250,67 +258,32 @@
return values;
}
- public: // Methods from Synchronizable
+ public:
- /**
- * Locks the object.
- * @throws ActiveMQException
- */
virtual void lock() throw( lang::Exception ) {
mutex.lock();
}
- /**
- * Unlocks the object.
- * @throws ActiveMQException
- */
virtual void unlock() throw( lang::Exception ) {
mutex.unlock();
}
- /**
- * Waits on a signal from this object, which is generated
- * by a call to Notify. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void wait() throw( lang::Exception ) {
mutex.wait();
}
- /**
- * Waits on a signal from this object, which is generated
- * by a call to Notify. Must have this object locked before
- * calling. This wait will timeout after the specified time
- * interval.
- * @param millisecs the time in milliseconds to wait, or
- * WAIT_INIFINITE
- * @throws ActiveMQException
- */
- virtual void wait( unsigned long millisecs )
- throw( lang::Exception ) {
+ virtual void wait( unsigned long millisecs ) throw( lang::Exception ) {
mutex.wait(millisecs);
}
- /**
- * Signals a waiter on this object that it can now wake
- * up and continue. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void notify() throw( lang::Exception ) {
mutex.notify();
}
- /**
- * Signals the waiters on this object that it can now wake
- * up and continue. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void notifyAll() throw( lang::Exception ) {
mutex.notifyAll();
}
+
};
}}
Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/ConcurrentStlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/ConcurrentStlMap.h?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/ConcurrentStlMap.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/ConcurrentStlMap.h Fri Feb 13 20:38:57 2009
@@ -75,10 +75,7 @@
virtual ~ConcurrentStlMap() {}
/**
- * Comparison, equality is dependent on the method of determining
- * if the element are equal.
- * @param source - Map to compare to this one.
- * @returns true if the Map passed is equal in value to this one.
+ * {@inheritDoc}
*/
virtual bool equals( const ConcurrentStlMap& source ) const {
synchronized( &mutex ) {
@@ -109,9 +106,7 @@
}
/**
- * Copies the content of the source map into this map. Erases
- * all existing data in this map.
- * @param source The source object to copy from.
+ * {@inheritDoc}
*/
virtual void copy( const ConcurrentStlMap& source ) {
synchronized( &mutex ) {
@@ -128,19 +123,16 @@
}
/**
- * Removes all keys and values from this map.
+ * {@inheritDoc}
*/
- virtual void clear() {
+ virtual void clear() throw( decaf::lang::exceptions::UnsupportedOperationException ) {
synchronized( &mutex ) {
valueMap.clear();
}
}
/**
- * Indicates whether or this map contains a value for the
- * given key.
- * @param key The key to look up.
- * @return true if this map contains the value, otherwise false.
+ * {@inheritDoc}
*/
virtual bool containsKey( const K& key ) const {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
@@ -149,14 +141,12 @@
iter = valueMap.find(key);
return iter != valueMap.end();
}
+
+ return false;
}
/**
- * 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.
+ * {@inheritDoc}
*/
virtual bool containsValue( const V& value ) const {
@@ -178,7 +168,7 @@
}
/**
- * @return if the Map contains any element or not, TRUE or FALSE
+ * {@inheritDoc}
*/
virtual bool isEmpty() const {
synchronized( &mutex ) {
@@ -189,7 +179,7 @@
}
/**
- * @return The number of elements (key/value pairs) in this map.
+ * {@inheritDoc}
*/
virtual std::size_t size() const {
synchronized( &mutex ) {
@@ -200,49 +190,63 @@
}
/**
- * Gets the value for the specified key.
- * @param key The search key.
- * @return The value for the given key.
- * @throws NoSuchElementException
+ * {@inheritDoc}
*/
- virtual V get( const K& key ) const
+ virtual V& get( const K& key )
throw( lang::exceptions::NoSuchElementException ) {
- typename std::map<K,V,COMPARATOR>::const_iterator iter;
+ typename std::map<K,V,COMPARATOR>::iterator iter;
synchronized( &mutex ) {
- iter = valueMap.find(key);
- if( iter == valueMap.end() ){
- throw lang::exceptions::NoSuchElementException(
- __FILE__, __LINE__, "Key does not exist in map" );
+ iter = valueMap.find( key );
+ if( iter != valueMap.end() ){
+ return iter->second;
}
+ }
+
+ throw lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key does not exist in map" );
+ }
+ virtual const V& get( const K& key ) const
+ throw( lang::exceptions::NoSuchElementException ) {
+
+ typename std::map<K,V,COMPARATOR>::const_iterator iter;
- return iter->second;
+ synchronized( &mutex ) {
+ iter = valueMap.find( key );
+ if( iter != valueMap.end() ){
+ return iter->second;
+ }
}
+
+ throw lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key does not exist in map" );
}
/**
- * Sets the value for the specified key.
- * @param key The target key.
- * @param value The value to be set.
+ * {@inheritDoc}
*/
- virtual void put( const K& key, V value ) {
+ virtual void put( const K& key, const V& value )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
synchronized( &mutex ) {
valueMap[key] = value;
}
}
/**
- * Stores a copy of the Mappings contained in the other Map in this one.
- * @param key The target key.
- * @param value The value to be set.
+ * {@inheritDoc}
*/
- virtual void putAll( const ConcurrentStlMap<K,V,COMPARATOR>& other ) {
+ virtual void putAll( const ConcurrentStlMap<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
synchronized( &mutex ) {
this->valueMap.insert( other.valueMap.begin(), other.valueMap.end() );
}
}
- virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
+ virtual void putAll( const Map<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
synchronized( &mutex ) {
std::vector<K> keys = other.keySet();
@@ -254,39 +258,54 @@
}
/**
- * Removes the value (key/value pair) for the specified key from
- * the map.
- * @param key The search key.
+ * {@inheritDoc}
*/
- virtual void remove( const K& key ) {
+ virtual V remove( const K& key )
+ throw ( decaf::lang::exceptions::NoSuchElementException,
+ decaf::lang::exceptions::UnsupportedOperationException ) {
+
+ V result;
+
synchronized( &mutex ) {
- valueMap.erase( key );
+ typename std::map<K,V,COMPARATOR>::iterator iter = valueMap.find( key );
+ if( iter == valueMap.end() ) {
+ throw decaf::lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key is not present in this Map." );
+ }
+
+ result = iter->second;
+ valueMap.erase( iter );
}
+
+ return result;
}
+
/**
- * @return the entire set of keys in this map as a std::vector.
+ * {@inheritDoc}
*/
virtual std::vector<K> keySet() const {
+
+ std::vector<K> keys( valueMap.size() );
synchronized( &mutex ) {
- std::vector<K> keys( valueMap.size() );
typename std::map<K,V,COMPARATOR>::const_iterator iter;
iter=valueMap.begin();
for( int ix=0; iter != valueMap.end(); ++iter, ++ix ){
keys[ix] = iter->first;
}
-
- return keys;
}
+
+ return keys;
}
/**
- * @return the entire set of values in this map as a std::vector.
+ * {@inheritDoc}
*/
virtual std::vector<V> values() const {
+
+ std::vector<V> values( valueMap.size() );
synchronized( &mutex ) {
- std::vector<V> values( valueMap.size() );
typename std::map<K,V,COMPARATOR>::const_iterator iter;
iter=valueMap.begin();
@@ -294,8 +313,8 @@
values[ix] = iter->second;
}
- return values;
}
+ return values;
}
/**
@@ -428,66 +447,32 @@
__FILE__, __LINE__, "Value to Replace was not in the Map." );
}
- public: // Methods from Synchronizable
+ public:
- /**
- * Locks the object.
- * @throws ActiveMQException
- */
virtual void lock() throw( lang::Exception ) {
mutex.lock();
}
- /**
- * Unlocks the object.
- * @throws ActiveMQException
- */
virtual void unlock() throw( lang::Exception ) {
mutex.unlock();
}
- /**
- * Waits on a signal from this object, which is generated
- * by a call to Notify. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void wait() throw( lang::Exception ) {
mutex.wait();
}
- /**
- * Waits on a signal from this object, which is generated
- * by a call to Notify. Must have this object locked before
- * calling. This wait will timeout after the specified time
- * interval.
- * @param millisecs the time in milliseconds to wait, or
- * WAIT_INIFINITE
- * @throws ActiveMQException
- */
virtual void wait( unsigned long millisecs ) throw( lang::Exception ) {
mutex.wait(millisecs);
}
- /**
- * Signals a waiter on this object that it can now wake
- * up and continue. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void notify() throw( lang::Exception ) {
mutex.notify();
}
- /**
- * Signals the waiters on this object that it can now wake
- * up and continue. Must have this object locked before
- * calling.
- * @throws ActiveMQException
- */
virtual void notifyAll() throw( lang::Exception ) {
mutex.notifyAll();
}
+
};
}}}
Modified: activemq/activemq-cpp/trunk/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/Makefile.am?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/test/Makefile.am Fri Feb 13 20:38:57 2009
@@ -98,7 +98,6 @@
decaf/util/DateTest.cpp \
decaf/util/UUIDTest.cpp \
decaf/util/RandomTest.cpp \
- decaf/util/MapTest.cpp \
decaf/util/StlMapTest.cpp \
decaf/util/QueueTest.cpp \
decaf/util/ListTest.cpp \
@@ -199,7 +198,6 @@
decaf/util/UUIDTest.h \
decaf/util/RandomTest.h \
decaf/util/ListTest.h \
- decaf/util/MapTest.h \
decaf/util/StlMapTest.h \
decaf/util/QueueTest.h \
decaf/util/SetTest.h \
Modified: activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.cpp?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.cpp Fri Feb 13 20:38:57 2009
@@ -24,51 +24,96 @@
using namespace decaf;
using namespace decaf::util;
-template <typename K, typename V, typename COMPARATOR = std::less<K> > class STLTestMap :
- public Map<K, V, COMPARATOR> {
+template <typename K, typename V, typename COMPARATOR = std::less<K> >
+class StlTestMap : public Map<K, V, COMPARATOR> {
private:
std::map<K,V,COMPARATOR> valueMap;
+ concurrent::Mutex mutex;
public:
- STLTestMap() : Map<K,V,COMPARATOR>() {}
-
- STLTestMap( const STLTestMap& source ) : Map<K,V,COMPARATOR>() {
+ /**
+ * Default constructor - does nothing.
+ */
+ StlTestMap() : Map<K,V,COMPARATOR>() {}
+
+ /**
+ * Copy constructor - copies the content of the given map into this
+ * one.
+ * @param source The source map.
+ */
+ StlTestMap( const StlTestMap& source ) : Map<K,V,COMPARATOR>() {
copy( source );
}
- STLTestMap( const Map<K,V,COMPARATOR>& source ) : Map<K,V,COMPARATOR>() {
+ /**
+ * Copy constructor - copies the content of the given map into this
+ * one.
+ * @param source The source map.
+ */
+ StlTestMap( const Map<K,V,COMPARATOR>& source ) : Map<K,V,COMPARATOR>() {
copy( source );
}
- virtual ~STLTestMap() {}
+ virtual ~StlTestMap() {}
- virtual bool equals( const STLTestMap& source ) const {
+ /**
+ * {@inheritDoc}
+ */
+ virtual bool equals( const StlTestMap& source ) const {
return this->valueMap == source.valueMap;
}
- virtual bool equals( const Map<K,V,COMPARATOR>& source DECAF_UNUSED ) const {
- return false; // TODO - this->valueMap == source.valueMap;
+
+ virtual bool equals( const Map<K,V,COMPARATOR>& source ) const {
+ std::vector<K> keys = source.keySet();
+
+ typename std::vector<K>::const_iterator iter = keys.begin();
+ for( ; iter != keys.end(); ++iter ) {
+ if( !this->containsKey( *iter ) ) {
+ return false;
+ }
+
+ if( !( this->get( *iter ) == source.get( *iter ) ) ) {
+ return false;
+ }
+ }
+
+ return true;
}
- virtual void copy( const STLTestMap& source ) {
- valueMap.clear();
- valueMap.insert( source.valueMap.begin(), source.valueMap.end() );
+ /**
+ * {@inheritDoc}
+ */
+ virtual void copy( const StlTestMap& source ) {
+ this->valueMap.clear();
+ this->valueMap.insert( source.valueMap.begin(), source.valueMap.end() );
}
- virtual void copy( const Map<K,V,COMPARATOR>& source DECAF_UNUSED ) {
- // TODO
+
+ virtual void copy( const Map<K,V,COMPARATOR>& source ) {
+ this->clear();
+ this->putAll( source );
}
- virtual void clear() {
+ /**
+ * {@inheritDoc}
+ */
+ virtual void clear() throw( decaf::lang::exceptions::UnsupportedOperationException ) {
valueMap.clear();
}
+ /**
+ * {@inheritDoc}
+ */
virtual bool containsKey( const K& key ) const {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
iter = valueMap.find(key);
return iter != valueMap.end();
}
+ /**
+ * {@inheritDoc}
+ */
virtual bool containsValue( const V& value ) const {
if( valueMap.empty() ){
@@ -85,19 +130,40 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ */
virtual bool isEmpty() const {
return valueMap.empty();
}
+ /**
+ * {@inheritDoc}
+ */
virtual std::size_t size() const {
return valueMap.size();
}
- virtual V get( const K& key ) const
+ /**
+ * {@inheritDoc}
+ */
+ virtual V& get( const K& key )
+ throw( lang::exceptions::NoSuchElementException ) {
+
+ typename std::map<K,V,COMPARATOR>::iterator iter;
+ iter = valueMap.find( key );
+ if( iter == valueMap.end() ){
+ throw lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key does not exist in map" );
+ }
+
+ return iter->second;
+ }
+ virtual const V& get( const K& key ) const
throw( lang::exceptions::NoSuchElementException ) {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
- iter = valueMap.find(key);
+ iter = valueMap.find( key );
if( iter == valueMap.end() ){
throw lang::exceptions::NoSuchElementException(
__FILE__, __LINE__, "Key does not exist in map" );
@@ -106,21 +172,56 @@
return iter->second;
}
- virtual void put( const K& key, V value ) {
+ /**
+ * {@inheritDoc}
+ */
+ virtual void put( const K& key, const V& value )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
valueMap[key] = value;
}
- virtual void putAll( const StlMap<K,V,COMPARATOR>& other DECAF_UNUSED ) {
- // TODO
+ /**
+ * {@inheritDoc}
+ */
+ virtual void putAll( const StlTestMap<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
+ this->valueMap.insert( other.valueMap.begin(), other.valueMap.end() );
}
- virtual void putAll( const Map<K,V,COMPARATOR>& other DECAF_UNUSED ) {
- // TODO
+ virtual void putAll( const Map<K,V,COMPARATOR>& other )
+ throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+
+ std::vector<K> keys = other.keySet();
+
+ typename std::vector<K>::const_iterator iter = keys.begin();
+ for( ; iter != keys.end(); ++iter ) {
+
+ this->put( *iter, other.get( *iter ) );
+ }
}
- virtual void remove( const K& key ) {
- valueMap.erase( key );
+ /**
+ * {@inheritDoc}
+ */
+ virtual V remove( const K& key )
+ throw ( decaf::lang::exceptions::NoSuchElementException,
+ decaf::lang::exceptions::UnsupportedOperationException ) {
+
+ typename std::map<K,V,COMPARATOR>::iterator iter = valueMap.find( key );
+ if( iter == valueMap.end() ) {
+ throw decaf::lang::exceptions::NoSuchElementException(
+ __FILE__, __LINE__, "Key is not present in this Map." );
+ }
+
+ V result = iter->second;
+ valueMap.erase( iter );
+ return result;
}
+ /**
+ * {@inheritDoc}
+ */
virtual std::vector<K> keySet() const{
std::vector<K> keys( valueMap.size() );
@@ -133,6 +234,9 @@
return keys;
}
+ /**
+ * {@inheritDoc}
+ */
virtual std::vector<V> values() const {
std::vector<V> values( valueMap.size() );
@@ -148,17 +252,29 @@
public:
virtual void lock() throw( lang::Exception ) {
+ mutex.lock();
}
+
virtual void unlock() throw( lang::Exception ) {
+ mutex.unlock();
}
+
virtual void wait() throw( lang::Exception ) {
+ mutex.wait();
}
+
virtual void wait( unsigned long millisecs ) throw( lang::Exception ) {
+ mutex.wait(millisecs);
}
+
virtual void notify() throw( lang::Exception ) {
+ mutex.notify();
}
+
virtual void notifyAll() throw( lang::Exception ) {
+ mutex.notifyAll();
}
+
};
////////////////////////////////////////////////////////////////////////////////
@@ -173,26 +289,189 @@
map1.get( "TEST" ),
decaf::lang::exceptions::NoSuchElementException );
- StlMap<string, int> destMap;
- STLTestMap<string, int> srcMap;
-
+ StlTestMap<string, int> srcMap;
srcMap.put( "A", 1 );
srcMap.put( "B", 1 );
srcMap.put( "C", 1 );
+ StlMap<string, int> destMap( srcMap );
+
CPPUNIT_ASSERT( srcMap.size() == 3 );
+ CPPUNIT_ASSERT( destMap.size() == 3 );
+ CPPUNIT_ASSERT( destMap.get( "B" ) == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testContainsKey(){
+
+ StlMap<string, bool> boolMap;
+ CPPUNIT_ASSERT(boolMap.containsKey("bob") == false);
+
+ boolMap.put( "bob", true );
+
+ CPPUNIT_ASSERT(boolMap.containsKey("bob") == true );
+ CPPUNIT_ASSERT(boolMap.containsKey("fred") == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testContiansValue() {
+
+ StlMap<string, bool> boolMap;
+
+ boolMap.put( "fred", true );
+ boolMap.put( "fred1", false );
+ CPPUNIT_ASSERT( boolMap.containsValue(true) == true );
+ boolMap.remove( "fred" );
+ CPPUNIT_ASSERT( boolMap.containsValue(true) == false );
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testClear() {
+
+ StlMap<string, bool> boolMap;
+ boolMap.put( "bob", true );
+ boolMap.put( "fred", true );
+
+ CPPUNIT_ASSERT(boolMap.size() == 2 );
+ boolMap.clear();
+ CPPUNIT_ASSERT(boolMap.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testCopy() {
+
+ StlMap<string, int> destMap;
+ StlTestMap<string, int> srcMap;
+ StlMap<string, int> srcMap2;
+
CPPUNIT_ASSERT( destMap.size() == 0 );
+ srcMap.put( "A", 1 );
+ srcMap.put( "B", 2 );
+ srcMap.put( "C", 3 );
+ srcMap.put( "D", 4 );
+ srcMap.put( "E", 5 );
+ srcMap.put( "F", 6 );
+
destMap.copy( srcMap );
+ CPPUNIT_ASSERT( destMap.size() == 6 );
+ CPPUNIT_ASSERT( destMap.get( "A" ) == 1 );
+ CPPUNIT_ASSERT( destMap.get( "B" ) == 2 );
+ CPPUNIT_ASSERT( destMap.get( "C" ) == 3 );
+ CPPUNIT_ASSERT( destMap.get( "D" ) == 4 );
+ CPPUNIT_ASSERT( destMap.get( "E" ) == 5 );
+ CPPUNIT_ASSERT( destMap.get( "F" ) == 6 );
+
+ destMap.copy( srcMap2 );
+ CPPUNIT_ASSERT( destMap.size() == 0 );
+
+ srcMap2.put( "A", 1 );
+ srcMap2.put( "B", 2 );
+ srcMap2.put( "C", 3 );
+ srcMap2.put( "D", 4 );
+ srcMap2.put( "E", 5 );
+
+ destMap.copy( srcMap2 );
+ CPPUNIT_ASSERT( destMap.size() == 5 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testIsEmpty() {
+
+ StlMap<string, bool> boolMap;
+ boolMap.put( "bob", true );
+ boolMap.put( "fred", true );
+
+ CPPUNIT_ASSERT(boolMap.isEmpty() == false );
+ boolMap.clear();
+ CPPUNIT_ASSERT(boolMap.isEmpty() == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testSize() {
+
+ StlMap<string, bool> boolMap;
+
+ CPPUNIT_ASSERT(boolMap.size() == 0 );
+ boolMap.put( "bob", true );
+ CPPUNIT_ASSERT(boolMap.size() == 1 );
+ boolMap.put( "fred", true );
+ CPPUNIT_ASSERT(boolMap.size() == 2 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testGet() {
+
+ StlMap<string, bool> boolMap;
+
+ boolMap.put( "fred", true );
+ CPPUNIT_ASSERT( boolMap.get("fred") == true );
+
+ boolMap.put( "bob", false );
+ CPPUNIT_ASSERT( boolMap.get("bob") == false );
+ CPPUNIT_ASSERT( boolMap.get("fred") == true );
+
+ try{
+ boolMap.get( "mike" );
+ CPPUNIT_ASSERT(false);
+ } catch( decaf::lang::exceptions::NoSuchElementException& e ){
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testPut() {
+
+ StlMap<string, bool> boolMap;
+
+ boolMap.put( "fred", true );
+ CPPUNIT_ASSERT( boolMap.get("fred") == true );
+
+ boolMap.put( "bob", false );
+ CPPUNIT_ASSERT( boolMap.get("bob") == false );
+ CPPUNIT_ASSERT( boolMap.get("fred") == true );
+
+ boolMap.put( "bob", true );
+ CPPUNIT_ASSERT( boolMap.get("bob") == true );
+ CPPUNIT_ASSERT( boolMap.get("fred") == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testPutAll() {
+
+ StlMap<string, int> destMap;
+ StlTestMap<string, int> srcMap;
+ StlTestMap<string, int> srcMap2;
+
+ srcMap.put( "A", 1 );
+ srcMap.put( "B", 1 );
+ srcMap.put( "C", 1 );
+
CPPUNIT_ASSERT( srcMap.size() == 3 );
- CPPUNIT_ASSERT( destMap.size() == 3 );
+ CPPUNIT_ASSERT( destMap.size() == 0 );
- STLTestMap<string, int> srcMap2;
- srcMap2.put( "D", 1 );
- srcMap2.put( "E", 1 );
- srcMap2.put( "F", 1 );
+ srcMap.put( "D", 1 );
+ srcMap.put( "E", 1 );
+ srcMap.put( "F", 1 );
+ destMap.putAll( srcMap );
+ CPPUNIT_ASSERT( destMap.size() == 6 );
destMap.putAll( srcMap2 );
CPPUNIT_ASSERT( destMap.size() == 6 );
+}
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testRemove() {
+ StlMap<string, bool> boolMap;
+
+ boolMap.put( "fred", true );
+ CPPUNIT_ASSERT( boolMap.containsKey("fred") == true );
+ CPPUNIT_ASSERT( boolMap.remove( "fred" ) == true );
+ CPPUNIT_ASSERT( boolMap.containsKey("fred") == false );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a NoSuchElementException",
+ boolMap.remove( "fred" ),
+ decaf::lang::exceptions::NoSuchElementException );
}
+
Modified: activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.h?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.h (original)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/StlMapTest.h Fri Feb 13 20:38:57 2009
@@ -28,6 +28,16 @@
{
CPPUNIT_TEST_SUITE( StlMapTest );
CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testContainsKey );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testCopy );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testPut );
+ CPPUNIT_TEST( testPutAll );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testContiansValue );
+ CPPUNIT_TEST( testIsEmpty );
CPPUNIT_TEST_SUITE_END();
public:
@@ -36,6 +46,16 @@
virtual ~StlMapTest() {}
void testConstructor();
+ void testContainsKey();
+ void testClear();
+ void testCopy();
+ void testSize();
+ void testGet();
+ void testPut();
+ void testPutAll();
+ void testRemove();
+ void testContiansValue();
+ void testIsEmpty();
};
Modified: activemq/activemq-cpp/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/testRegistry.cpp?rev=744235&r1=744234&r2=744235&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/testRegistry.cpp Fri Feb 13 20:38:57 2009
@@ -214,17 +214,15 @@
//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::DateTest );
//#include <decaf/util/UUIDTest.h>
//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::UUIDTest );
-//#include <decaf/util/ListTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::ListTest );
-#include <decaf/util/MapTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::MapTest );
+#include <decaf/util/ListTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::ListTest );
#include <decaf/util/StlMapTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::StlMapTest );
-//#include <decaf/util/QueueTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::QueueTest );
+#include <decaf/util/QueueTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::QueueTest );
//#include <decaf/util/RandomTest.h>
//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::RandomTest );
-//#include <decaf/util/SetTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::SetTest );
+#include <decaf/util/SetTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::SetTest );
//#include <decaf/util/StringTokenizerTest.h>
//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::StringTokenizerTest );