Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 50323 invoked from network); 1 Jun 2007 17:29:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Jun 2007 17:29:39 -0000 Received: (qmail 96607 invoked by uid 500); 1 Jun 2007 17:29:42 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 96585 invoked by uid 500); 1 Jun 2007 17:29:42 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 96574 invoked by uid 99); 1 Jun 2007 17:29:42 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2007 10:29:42 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2007 10:29:37 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 04D231A981A; Fri, 1 Jun 2007 10:29:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r543540 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util: Map.h Queue.h Set.h Date: Fri, 01 Jun 2007 17:29:16 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070601172917.04D231A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Fri Jun 1 10:29:16 2007 New Revision: 543540 URL: http://svn.apache.org/viewvc?view=rev&rev=543540 Log: http://issues.apache.org/activemq/browse/AMQCPP-103 Building Decaf lib Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Map.h activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Queue.h activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Set.h Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Map.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Map.h?view=auto&rev=543540 ============================================================================== --- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Map.h (added) +++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Map.h Fri Jun 1 10:29:16 2007 @@ -0,0 +1,329 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DECAF_UTIL_MAP_H_ +#define _DECAF_UTIL_MAP_H_ + +#include +#include +#include +#include +#include + +namespace decaf{ +namespace util{ + + /** + * Map template that wraps around a std::map to provide + * a more user-friendly interface and to provide common + * functions that do not exist in std::map. + */ + template class Map : public concurrent::Synchronizable + { + private: + + std::map valueMap; + concurrent::Mutex mutex; + + public: + + /** + * Default constructor - does nothing. + */ + Map(){}; + + /** + * Copy constructor - copies the content of the given map into this + * one. + * @param source The source map. + */ + Map( const Map& source ){ + copy( source ); + } + + virtual ~Map(){}; + + /** + * Comparison, equality is dependant 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. + */ + virtual bool equals( const Map& source ) const; + + /** + * 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. + */ + virtual void copy( const Map& source ); + + /** + * Removes all keys and values from this map. + */ + virtual void 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. + */ + 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 std::size_t size() const; + + /** + * Gets the value for the specified key. + * @param key The search key. + * @return The value for the given key. + * @throws activemq::exceptions::NoSuchElementException + */ + virtual V getValue( const K& key ) const + throw( lang::exceptions::NoSuchElementException ); + + /** + * Sets the value for the specified key. + * @param key The target key. + * @param value The value to be set. + */ + virtual void setValue( const K& key, V value ); + + /** + * Removes the value (key/value pair) for the specified key from + * the map. + * @param key The search key. + */ + virtual void remove( const K& key ); + + /** + * @return the entire set of keys in this map as a std::vector. + */ + virtual std::vector getKeys() const; + + /** + * @return the entire set of values in this map as a std::vector. + */ + virtual std::vector getValues() const; + + public: // Methods from Synchronizable + + /** + * 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 millisecsonds 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(); + } + }; + + //////////////////////////////////////////////////////////////////////////// + template + bool Map::equals( const Map& source ) const { + return this->valueMap == source.valueMap; + } + + //////////////////////////////////////////////////////////////////////////// + template + void Map::copy( const Map& source ) { + + // Get an iterator to the beginning of the source map. + typename std::map::const_iterator iter; + iter = source.valueMap.begin(); + + // Erase the content of this object. + clear(); + + // Add all of the entries to this map. + for( ; iter != source.valueMap.end(); iter++ ){ + setValue( iter->first, iter->second ); + } + + } + + //////////////////////////////////////////////////////////////////////////// + template + void Map::clear(){ + valueMap.clear(); + } + + //////////////////////////////////////////////////////////////////////////// + template + bool Map::containsKey(const K& key) const{ + typename std::map::const_iterator iter; + iter = valueMap.find(key); + return iter != valueMap.end(); + } + + //////////////////////////////////////////////////////////////////////////// + template + bool Map::containsValue( const V& value ) const { + + if( valueMap.empty() ){ + return false; + } + + typename std::map::const_iterator iter = valueMap.begin(); + for( ; iter != valueMap.end(); ++iter ){ + if( (*iter).second == value ) { + return true; + } + } + + return false; + } + + //////////////////////////////////////////////////////////////////////////// + template + bool Map::isEmpty() const{ + return valueMap.empty(); + } + + //////////////////////////////////////////////////////////////////////////// + template + std::size_t Map::size() const{ + return valueMap.size(); + } + + //////////////////////////////////////////////////////////////////////////// + template + V Map::getValue( const K& key ) const + throw(activemq::exceptions::NoSuchElementException){ + + typename std::map::const_iterator iter; + iter = valueMap.find(key); + if( iter == valueMap.end() ){ + throw activemq::exceptions::NoSuchElementException( __FILE__, + __LINE__, + "Key does not exist in map" ); + } + + return iter->second; + } + + //////////////////////////////////////////////////////////////////////////// + template + void Map::setValue( const K& key, V value ){ + valueMap[key] = value; + } + + //////////////////////////////////////////////////////////////////////////// + template + void Map::remove( const K& key ){ + valueMap.erase(key); + } + + //////////////////////////////////////////////////////////////////////////// + template + std::vector Map::getKeys() const{ + std::vector keys(valueMap.size()); + + typename std::map::const_iterator iter; + iter=valueMap.begin(); + for( int ix=0; iter != valueMap.end(); ++iter, ++ix ){ + keys[ix] = iter->first; + } + + return keys; + } + + //////////////////////////////////////////////////////////////////////////// + template + std::vector Map::getValues() const{ + std::vector values(valueMap.size()); + + typename std::map::const_iterator iter; + iter=valueMap.begin(); + for( int ix=0; iter != valueMap.end(); ++iter, ++ix ){ + values[ix] = iter->second; + } + + return values; + } + +}} + +#endif /*_DECAF_UTIL_MAP_H_*/ Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Queue.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Queue.h?view=auto&rev=543540 ============================================================================== --- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Queue.h (added) +++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Queue.h Fri Jun 1 10:29:16 2007 @@ -0,0 +1,362 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _DECAF_UTIL_QUEUE_H +#define _DECAF_UTIL_QUEUE_H + +#include +#include +#include +#include + +namespace decaf{ +namespace util{ + + /** + * The Queue class accepts messages with an psuh(m) command + * where m is the message to be queued. It destructively + * returns the message with pop(). pop() returns messages in + * the order they were enqueued. + * + * Queue is implemented with an instance of the STL queue object. + * The interface is essentially the same as that of the STL queue + * except that the pop method actually reaturns a reference to the + * element popped. This frees the app from having to call the + * front method before calling pop. + * + * Queue sq; // make a queue to hold string messages + * sq.push(s); // enqueues a message m + * string s = sq.pop(); // dequeues a message + * + * = DESIGN CONSIDERATIONS + * + * The Queue class inherits from the Synchronizable interface and + * provides methods for locking and unlocking this queue as well as + * waiting on this queue. In a multi-threaded app this can allow + * for multiple threads to be reading from and writing to the same + * Queue. + * + * Clients should consider that in a multiple threaded app it is + * possible that items could be placed on the queue faster than + * you are taking them off, so protection should be placed in your + * polling loop to ensure that you don't get stuck there. + */ + + template class Queue : public concurrent::Synchronizable + { + public: + + Queue(); + virtual ~Queue(); + + /** + * Empties this queue. + */ + void clear(); + + /** + * Returns a Reference to the element at the head of the queue + * @return reference to a queue type object or (safe) + */ + T& front(); + + /** + * Returns a Reference to the element at the head of the queue + * @return reference to a queue type object or (safe) + */ + const T& front() const; + + /** + * Returns a Reference to the element at the tail of the queue + * @return reference to a queue type object or (safe) + */ + T& back(); + + /** + * Returns a Reference to the element at the tail of the queue + * @return reference to a queue type object or (safe) + */ + const T& back() const; + + /** + * Places a new Object at the Tail of the queue + * @param t - Queue Object Type reference. + */ + void push( const T &t ); + + /** + * Places a new Object at the front of the queue + * @param t - Queue Object Type reference. + */ + void enqueueFront( const T &t ); + + /** + * Removes and returns the element that is at the Head of the queue + * @return reference to a queue type object or (safe) + */ + T pop(); + + /** + * Gets the Number of elements currently in the Queue + * @return Queue Size + */ + size_t size() const; + + /** + * Checks if this Queue is currently empty + * @return boolean indicating queue emptiness + */ + bool empty() const; + + /** + * @return the all values in this queue as a std::vector. + */ + virtual std::vector toArray() const; + + /** + * Reverses the order of the contents of this queue and stores them + * in the target queue. + * @param target - The target queue that will receive the contents of + * this queue in reverse order. + */ + void reverse( Queue& target ) const; + + /** + * Locks the object. + */ + virtual void lock() throw( lang::Exception ){ + mutex.lock(); + } + + /** + * Unlocks the object. + */ + 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. + */ + 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 time 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. + */ + 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. + */ + virtual void notifyAll() throw( lang::Exception ){ + mutex.notifyAll(); + } + + public: // Statics + + /** + * Fetch a reference to the safe value this object will return + * when there is nothing to fetch from the queue. + * @return Reference to this Queues safe object + */ + static const T& getSafeValue() { return safe; } + + private: + + // The real queue + std::list queue; + + // Object used for sync + concurrent::Mutex mutex; + + // Safe value used when pop, front or back are + // called and the queue is empty. + static T safe; + + }; + + //-----{ Static Init }----------------------------------------------------// + template + T Queue::safe; + + //-----{ Retrieve current length of Queue }-------------------------------// + + template inline size_t Queue::size() const + { + return queue.size(); + } + + //-----{ Retrieve whether Queue is empty or not }-------------------------// + + template inline bool Queue::empty() const + { + return queue.empty(); + } + + //-----{ Defulat Constructor }--------------------------------------------// + + template + Queue::Queue() + { + } + + //-----{ Default Destructor }---------------------------------------------// + + template Queue::~Queue() + { + } + + template + void Queue::clear() + { + queue.clear(); + } + + //-----{ Add Elements to Back of Queue }----------------------------------// + + template + void Queue::push( const T &t ) + { + queue.push_back( t ); + } + + template + void Queue::enqueueFront( const T &t ) + { + queue.push_front( t ); + } + + //-----{ Remove Elements from Front of Queue }----------------------------// + + template + T Queue::pop() + { + if(queue.empty()) + { + return safe; + } + + // Pop the element into a temp, since we need to remain locked. + // this means getting front and then popping. + T temp = queue.front(); + queue.pop_front(); + + return temp; + } + + //-----{ Returnreference to element at front of Queue }-------------------// + + template + T& Queue::front() + { + if( queue.empty() ) + { + return safe; + } + + return queue.front(); + } + + //-----{ Returnreference to element at front of Queue }-------------------// + + template + const T& Queue::front() const + { + if( queue.empty() ) + { + return safe; + } + + return queue.front(); + } + + //-----{ Returnreference to element at back of Queue }--------------------// + + template + T& Queue::back() + { + if( queue.empty() ) + { + return safe; + } + + return queue.back(); + } + + //-----{ Returnreference to element at back of Queue }--------------------// + + template + const T& Queue::back() const + { + if( queue.empty() ) + { + return safe; + } + + return queue.back(); + } + + template + void Queue::reverse( Queue& target ) const + { + typename std::list::const_reverse_iterator iter; + iter = queue.rbegin(); + for( ; iter != queue.rend(); ++iter ) { + target.push( *iter ); + } + } + + //////////////////////////////////////////////////////////////////////////// + template + std::vector Queue::toArray() const{ + std::vector valueArray(queue.size()); + + typename std::list::const_iterator iter; + iter=queue.begin(); + for( int ix=0; iter != queue.end(); ++iter, ++ix ){ + valueArray[ix] = *iter; + } + + return valueArray; + } + +}} + +#endif /* _DECAF_UTIL_QUEUE_H */ Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Set.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Set.h?view=auto&rev=543540 ============================================================================== --- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Set.h (added) +++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/Set.h Fri Jun 1 10:29:16 2007 @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DECAF_UTIL_SET_H_ +#define _DECAF_UTIL_SET_H_ + +#include +#include +#include +#include +#include + +namespace decaf{ +namespace util{ + + /** + * Map template that wraps around a std::map to provide + * a more user-friendly interface and to provide common + * functions that do not exist in std::map. + */ + template class Set : public concurrent::Synchronizable + { + private: + + std::set values; + concurrent::Mutex mutex; + + public: + + /** + * Default constructor - does nothing. + */ + Set(){} + + /** + * Copy constructor - copies the content of the given set into this + * one. + * @param source The source set. + */ + Set( const Set& source ){ + copy( source ); + } + + virtual ~Set(){} + + /** + * Copies the content of the source set into this set. Erases + * all existing data in this st. + * @param source The source object to copy from. + */ + virtual void copy( const Set& source ); + + /** + * Removes all values from this set. + */ + virtual void clear(); + + /** + * Indicates whether or this set contains the given value. + * @param value The value to look up. + * @return true if this set contains the value, otherwise false. + */ + virtual bool contains( const E& value ) const; + + /** + * @return if the set contains any element or not, TRUE or FALSE + */ + virtual bool isEmpty() const; + + /** + * @return The number of elements in this set. + */ + virtual std::size_t size() const; + + /** + * Adds the given value to the set. + * @param value The value to add. + */ + virtual void add( const E& value ); + + /** + * Removes the value from the set. + * @param value The value to be removed. + */ + virtual void remove( const E& value ); + + /** + * @return the all values in this set as a std::vector. + */ + virtual std::vector toArray() const; + + public: // Methods from Synchronizable + + /** + * 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 millisecsonds 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(); + } + }; + + //////////////////////////////////////////////////////////////////////////// + template + void Set::copy( const Set& source ) { + + // Add all of the entries to this map. + values = source.values; + } + + //////////////////////////////////////////////////////////////////////////// + template + void Set::clear(){ + values.clear(); + } + + //////////////////////////////////////////////////////////////////////////// + template + bool Set::contains(const E& value) const{ + typename std::set::const_iterator iter; + iter = values.find(value); + return iter != values.end(); + } + + //////////////////////////////////////////////////////////////////////////// + template + bool Set::isEmpty() const{ + return values.empty(); + } + + //////////////////////////////////////////////////////////////////////////// + template + std::size_t Set::size() const{ + return values.size(); + } + + //////////////////////////////////////////////////////////////////////////// + template + void Set::add( const E& value ){ + values.insert(value); + } + + //////////////////////////////////////////////////////////////////////////// + template + void Set::remove( const E& value ){ + values.erase(value); + } + + //////////////////////////////////////////////////////////////////////////// + template + std::vector Set::toArray() const{ + std::vector valueArray(values.size()); + + typename std::set::const_iterator iter; + iter=values.begin(); + for( int ix=0; iter != values.end(); ++iter, ++ix ){ + valueArray[ix] = *iter; + } + + return valueArray; + } + +}} + +#endif /*_DECAF_UTIL_SET_H_*/