Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 86867 invoked from network); 13 Feb 2009 22:48:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Feb 2009 22:48:25 -0000 Received: (qmail 96989 invoked by uid 500); 13 Feb 2009 22:48:25 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 96969 invoked by uid 500); 13 Feb 2009 22:48:25 -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 96950 invoked by uid 99); 13 Feb 2009 22:48:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2009 14:48:25 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2009 22:48:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F151E23889D0; Fri, 13 Feb 2009 22:48:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r744273 - in /activemq/activemq-cpp/trunk/src/main/decaf/util: AbstractCollection.h Collection.h List.h StlList.h Date: Fri, 13 Feb 2009 22:48:02 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090213224803.F151E23889D0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Fri Feb 13 22:47:59 2009 New Revision: 744273 URL: http://svn.apache.org/viewvc?rev=744273&view=rev Log: Refine the Collections classes some more. Added: activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h (with props) Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h activemq/activemq-cpp/trunk/src/main/decaf/util/List.h activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h Added: activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h?rev=744273&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h (added) +++ activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h Fri Feb 13 22:47:59 2009 @@ -0,0 +1,207 @@ +/* + * 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_ABSTRACTCOLLECTION_H_ +#define _DECAF_UTIL_ABSTRACTCOLLECTION_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace decaf { +namespace util { + + /** + * This class provides a skeletal implementation of the Collection interface, to + * minimize the effort required to implement this interface. + * + * To implement an unmodifiable collection, the programmer needs only to extend this + * class and provide implementations for the iterator and size methods. (The iterator + * returned by the iterator method must implement hasNext and next.) + * + * To implement a modifiable collection, the programmer must additionally override + * this class's add method (which otherwise throws an UnsupportedOperationException), + * and the iterator returned by the iterator method must additionally implement its + * remove method. + * + * The programmer should generally provide a void (no argument) and Collection + * constructor, as per the recommendation in the Collection interface specification. + * + * The documentation for each non-abstract method in this class describes its + * implementation in detail. Each of these methods may be overridden if the collection + * being implemented admits a more efficient implementation. + * + * @since 1.0 + */ + template< typename E > + class AbstractCollection : public decaf::util::Collection { + public: + + virtual ~AbstractCollection() {} + + virtual bool add( const E& value DECAF_UNUSED ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) { + + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "AbstractCollection add is not implemented."); + } + + virtual bool addAll( const Collection& collection ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) { + + bool result = false; + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + if( this->add( iter->next() ) ) { + result = true; + } + } + + return result; + } + + virtual void clear() + throw ( lang::exceptions::UnsupportedOperationException ) { + + std::auto_ptr< Iterator > iter( this->iterator() ); + while( iter->hasNext() ) { + iter->next(); + iter->remove(); + } + } + + virtual void copy( const Collection& collection ) { + this->clear(); + + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + this->add( iter->next() ); + } + } + + virtual bool contains( const E& value ) const throw ( lang::Exception ) { + + bool result = false; + std::auto_ptr< Iterator > iter( this->iterator() ); + while( iter->hasNext() ) { + if( iter->next() == value ) { + result = true; + } + } + + return result; + } + + virtual bool containsAll( const Collection& collection ) const + throw ( lang::Exception ) { + + bool result = false; + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + if( this->contains( iter->next() ) ) { + result = true; + } + } + + return result; + } + + virtual bool equals( const Collection& collection ) const { + if( this->size() != collection.size() ) { + return false; + } + + std::auto_ptr< Iterator > srcIter( collection.iterator() ); + std::auto_ptr< Iterator > thisIter( this->iterator() ); + + while( srcIter->hasNext() ) { + if( !( thisIter->next() == srcIter->next() ) ) { + return false; + } + } + + return true; + } + + virtual bool isEmpty() const { + return this->size() == 0; + } + + virtual bool remove( const E& value DECAF_UNUSED ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) { + + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "AbstractCollection add is not implemented."); + } + + virtual bool removeAll( const Collection& collection ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) { + + bool result = false; + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + if( this->remove( iter->next() ) ) { + result = true; + } + } + + return result; + } + + virtual bool retainAll( const Collection& collection ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) { + + bool result = false; + std::auto_ptr< Iterator > iter( this->iterator() ); + while( iter->hasNext() ) { + if( !collection.contains( iter->next() ) ) { + iter->remove(); + result = true; + } + } + + return result; + } + + virtual std::vector toArray() const { + std::vector valueArray; + valueArray.reserve( this->size() ); + + std::auto_ptr< Iterator > iter( this->iterator() ); + while( iter->hasNext() ) { + valueArray.push_back( iter->next() ); + } + + return valueArray; + } + + }; + +}} + +#endif /*_DECAF_UTIL_ABSTRACTCOLLECTION_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h?rev=744273&r1=744272&r2=744273&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h (original) +++ activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h Fri Feb 13 22:47:59 2009 @@ -72,24 +72,61 @@ virtual ~Collection() {} /** - * Returns the number of elements in this collection. If this collection - * contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. - * @returns the number of elements in this collection + * Returns true if this collection changed as a result of the call. + * (Returns false if this collection does not permit duplicates and + * already contains the specified element.) + * + * Collections that support this operation may place limitations on + * what elements may be added to this collection. In particular, + * some collections will refuse to add null elements, and others + * will impose restrictions on the type of elements that may be + * added. Collection classes should clearly specify in their + * documentation any restrictions on what elements may be added. + * + * If a collection refuses to add a particular element for any + * reason other than that it already contains the element, it must + * throw an exception (rather than returning false). This preserves + * the invariant that a collection always contains the specified + * element after this call returns. + * + * For non-pointer values, i.e. class instances or string's the object + * will be copied into the collection, thus the object must support + * being copied, must not hide the copy constructor and assignment + * operator. + * + * @param value - reference to the element to add. + * @returns true if the element was added + * @throw UnsupportedOperationException + * @throw IllegalArgumentException */ - virtual std::size_t size() const = 0; + virtual bool add( const E& value ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) = 0; /** - * @returns true if this collection contains no elements. + * Adds all of the elements in the specified collection to this + * collection. The behavior of this operation is undefined if the + * specified collection is modified while the operation is in progress. + * (This implies that the behavior of this call is undefined if the + * specified collection is this collection, and this collection is + * nonempty.) + * @param source - Collection whose elements are added to this one. + * @return true if this collection changed as a result of the call + * @throw UnsupportedOperationException + * @throw IllegalArgumentException */ - virtual bool isEmpty() const = 0; + virtual bool addAll( const Collection& source ) + throw ( lang::exceptions::UnsupportedOperationException, + lang::exceptions::IllegalArgumentException ) = 0; /** - * Compares the passed collection to this one, if they contain the - * same elements, i.e. all their elements are equivalent, then it - * returns true. - * @returns true if the Collections contain the same elements. + * Removes all of the elements from this collection (optional operation). + * This collection will be empty after this method returns unless it throws + * an exception. + * @throw UnsupportedOperationException */ - virtual bool equals( const Collection& value ) const = 0; + virtual void clear() + throw ( lang::exceptions::UnsupportedOperationException ) = 0; /** * Returns true if this collection contains the specified element. More @@ -111,47 +148,17 @@ throw ( lang::Exception ) = 0; /** - * Returns an array containing all of the elements in this collection. If - * the collection makes any guarantees as to what order its elements are - * returned by its iterator, this method must return the elements in the - * same order. - * - * This method acts as bridge between array-based and collection-based APIs. - * @returns an array of the elements in this collection. + * Compares the passed collection to this one, if they contain the + * same elements, i.e. all their elements are equivalent, then it + * returns true. + * @returns true if the Collections contain the same elements. */ - virtual std::vector toArray() const = 0; + virtual bool equals( const Collection& value ) const = 0; /** - * Returns true if this collection changed as a result of the call. - * (Returns false if this collection does not permit duplicates and - * already contains the specified element.) - * - * Collections that support this operation may place limitations on - * what elements may be added to this collection. In particular, - * some collections will refuse to add null elements, and others - * will impose restrictions on the type of elements that may be - * added. Collection classes should clearly specify in their - * documentation any restrictions on what elements may be added. - * - * If a collection refuses to add a particular element for any - * reason other than that it already contains the element, it must - * throw an exception (rather than returning false). This preserves - * the invariant that a collection always contains the specified - * element after this call returns. - * - * For non-pointer values, i.e. class instances or string's the object - * will be copied into the collection, thus the object must support - * being copied, must not hide the copy constructor and assignment - * operator. - * - * @param value - reference to the element to add. - * @returns true if the element was added - * @throw UnsupportedOperationException - * @throw IllegalArgumentException + * @returns true if this collection contains no elements. */ - virtual bool add( const E& value ) - throw ( lang::exceptions::UnsupportedOperationException, - lang::exceptions::IllegalArgumentException ) = 0; + virtual bool isEmpty() const = 0; /** * Removes a single instance of the specified element from the @@ -170,22 +177,6 @@ lang::exceptions::IllegalArgumentException ) = 0; /** - * Adds all of the elements in the specified collection to this - * collection. The behavior of this operation is undefined if the - * specified collection is modified while the operation is in progress. - * (This implies that the behavior of this call is undefined if the - * specified collection is this collection, and this collection is - * nonempty.) - * @param source - Collection whose elements are added to this one. - * @return true if this collection changed as a result of the call - * @throw UnsupportedOperationException - * @throw IllegalArgumentException - */ - virtual bool addAll( const Collection& source ) - throw ( lang::exceptions::UnsupportedOperationException, - lang::exceptions::IllegalArgumentException ) = 0; - - /** * Removes all this collection's elements that are also contained in * the specified collection (optional operation). After this call returns, * this collection will contain no elements in common with the specified @@ -214,13 +205,22 @@ lang::exceptions::IllegalArgumentException ) = 0; /** - * Removes all of the elements from this collection (optional operation). - * This collection will be empty after this method returns unless it throws - * an exception. - * @throw UnsupportedOperationException + * Returns the number of elements in this collection. If this collection + * contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. + * @returns the number of elements in this collection */ - virtual void clear() - throw ( lang::exceptions::UnsupportedOperationException ) = 0; + virtual std::size_t size() const = 0; + + /** + * Returns an array containing all of the elements in this collection. If + * the collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the + * same order. + * + * This method acts as bridge between array-based and collection-based APIs. + * @returns an array of the elements in this collection. + */ + virtual std::vector toArray() const = 0; }; Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/List.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/List.h?rev=744273&r1=744272&r2=744273&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/main/decaf/util/List.h (original) +++ activemq/activemq-cpp/trunk/src/main/decaf/util/List.h Fri Feb 13 22:47:59 2009 @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include namespace decaf{ @@ -43,7 +43,7 @@ * to insert them, but we expect this usage to be rare. */ template - class DECAF_API List : public decaf::util::Collection { + class DECAF_API List : public decaf::util::AbstractCollection { public: virtual ~List() {} Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h?rev=744273&r1=744272&r2=744273&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h (original) +++ activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h Fri Feb 13 22:47:59 2009 @@ -35,9 +35,8 @@ namespace util{ /** - * Set template that wraps around a std::set to provide a more - * user-friendly interface and to provide common functions that do - * not exist in std::list. + * List class that wraps the STL list object to provide a simpler interface and + * additional methods not provided by the STL type. */ template class DECAF_API StlList : public decaf::util::List { @@ -57,11 +56,6 @@ public: - StlListIterator( typename std::list* list ) { - this->current = list->begin(); - this->prev = list->end(); - this->list = list; - } StlListIterator( typename std::list* list, std::size_t index ) { this->current = list->begin(); std::advance( this->current, index ); @@ -162,11 +156,6 @@ public: - ConstStlListIterator( const typename std::list* list ) { - this->current = list->begin(); - this->prev = list->end(); - this->list = list; - } ConstStlListIterator( const typename std::list* list, std::size_t index ) { this->current = list->begin(); std::advance( this->current, index ); @@ -282,41 +271,25 @@ virtual bool equals( const StlList& source ) const { return this->values == source.values; } - virtual bool equals( const Collection& source ) const { - if( this->values.size() != source.size() ) { - return false; - } - - std::auto_ptr< Iterator > srcIter( source.iterator() ); - std::auto_ptr< Iterator > thisIter( this->iterator() ); - - while( srcIter->hasNext() ) { - if( !( thisIter->next() == srcIter->next() ) ) { - return false; - } - } - - return true; - } /** * {@inheritDoc} */ virtual Iterator* iterator() { - return new StlListIterator( &values ); + return new StlListIterator( &values, 0 ); } virtual Iterator* iterator() const { - return new ConstStlListIterator( &values ); + return new ConstStlListIterator( &values, 0 ); } /** * {@inheritDoc} */ virtual ListIterator* listIterator() { - return new StlListIterator( &values ); + return new StlListIterator( &values, 0 ); } virtual ListIterator* listIterator() const { - return new ConstStlListIterator( &values ); + return new ConstStlListIterator( &values, 0 ); } /** @@ -352,14 +325,6 @@ this->values.clear(); this->values = source.values; } - virtual void copy( const Collection& source ) { - this->values.clear(); - - std::auto_ptr< Iterator > srcIter( source.iterator() ); - while( srcIter->hasNext() ) { - this->add( srcIter->next() ); - } - } /** * {@inheritDoc} @@ -380,22 +345,6 @@ /** * {@inheritDoc} */ - virtual bool containsAll( const Collection& source ) const - throw ( lang::Exception ) { - - std::auto_ptr< Iterator > srcIter( source.iterator() ); - while( srcIter->hasNext() ) { - if( !this->contains( srcIter->next() ) ) { - return false; - } - } - - return true; - } - - /** - * {@inheritDoc} - */ virtual std::size_t indexOf( const E& value ) throw ( decaf::lang::exceptions::NoSuchElementException ) { @@ -518,16 +467,6 @@ /** * {@inheritDoc} */ - virtual bool addAll( const Collection& source ) - throw ( lang::exceptions::UnsupportedOperationException, - lang::exceptions::IllegalArgumentException ) { - - return this->addAll( 0, source ); - } - - /** - * {@inheritDoc} - */ virtual bool addAll( std::size_t index, const Collection& source ) throw ( decaf::lang::exceptions::UnsupportedOperationException, decaf::lang::exceptions::IndexOutOfBoundsException ) { @@ -580,56 +519,6 @@ return oldValue; } - /** - * {@inheritDoc} - */ - virtual bool removeAll( const Collection& source ) - throw ( lang::exceptions::UnsupportedOperationException, - lang::exceptions::IllegalArgumentException ) { - - std::size_t origSize = this->size(); - std::auto_ptr< Iterator > srcIter( source.iterator() ); - while( srcIter->hasNext() ) { - this->remove( srcIter->next() ); - } - - return origSize == this->size(); - } - - /** - * {@inheritDoc} - */ - virtual bool retainAll( const Collection& collection ) - throw ( lang::exceptions::UnsupportedOperationException, - lang::exceptions::IllegalArgumentException ) { - - bool result = false; - std::auto_ptr< Iterator > iter( this->iterator() ); - while( iter->hasNext() ) { - if( !collection.contains( iter->next() ) ) { - iter->remove(); - result = true; - } - } - - return result; - } - - /** - * {@inheritDoc} - */ - virtual std::vector toArray() const { - std::vector valueArray( values.size() ); - - typename std::list::const_iterator iter; - iter=values.begin(); - for( int ix=0; iter != values.end(); ++iter, ++ix ){ - valueArray[ix] = *iter; - } - - return valueArray; - } - public: virtual void lock() throw( lang::Exception ) {