From: <bl...@us...> - 2003-04-28 08:53:23
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv19831/include/xtl Added Files: GetAtEnumerator.h Log Message: * added enumerator for class which expose a public getAt(int index ) method. UNTESTED. --- NEW FILE: GetAtEnumerator.h --- #ifndef XTL_GETATENUMERATOR_H_INCLUDED #define XTL_GETATENUMERATOR_H_INCLUDED #include <xtl/Enumerator.h> #include <xtl/EnumAdaptor.h> #include <xtl/Int2Type.h> #include <xtl/Type.h> #include <boost/type_traits.hpp> namespace Xtl { template<typename ObjectType ,typename EnumeratedType ,typename ReturnType=EnumeratedType ,typename Adaptor=IdendityEnumAdpator<EnumeratedType> > class GetAtEnumeratorImpl : public EnumeratorImpl<EnumeratedType> { public: typedef GetAtEnumeratorImpl<ObjectType,EnumeratedType,Adaptor> ThisType; typedef ReturnType (ObjectType::*GetAtMethod)(int index) const enum { isIdentityAdaptor = ::boost::is_convertible<IdendityEnumAdpator<EnumeratedType> ,Adaptor>::value }; StlEnumeratorImpl( const ObjectType &object, GetAtMethod getAtMethod, int currentIndex, int elementCount ) : object_( object ) , getAtMethod_( getAtMethod ) , current_( currentIndex ) , count_( elementCount ) { } StlEnumeratorImpl( const ObjectType &object, GetAtMethod getAtMethod, int currentIndex, int elementCount, Adaptor adaptor ) : object_( object ) , getAtMethod_( getAtMethod ) , current_( currentIndex ) , count_( elementCount ) , adaptor_( adaptor ) { } public: // overridden from EnumeratorImpl EnumeratedType getNext() { if ( currentIndex >= count_ ) throw EnumeratorError(); return doGetNext( Int2Type<isIdentityAdaptor>() ); } bool hasNext() const { return current_ < count_; } Ptr clone() const { return Ptr( new ThisType( object_, getAtMethod_, currentIndex, elementCount, adaptor_ ) ); } private: inline EnumeratedType doGetNext( Int2Type<true> ) { return (object_->*getAtMethod)( current_++ ); } inline EnumeratedType doGetNext( Int2Type<false> ) { return adaptor_( (object_->*getAtMethod)( current_++ ) ); } private: const ObjectType &object_; GetAtMethod getAtMethod_; int current_; int count_; Adaptor adaptor_; }; template<typename ObjectType ,typename EnumeratedType> Enumerator<EnumeratedType> enumGetAt( const ObjectType &object, EnumeratedType (ObjectType::getAtMethod)(int index) const, int startIndex, int elementCount ) { return Enumerator<EnumeratedType>( new GetAtEnumeratorImpl<ObjectType, EnumeratedType>( object, getAtMethod, startIndex, count ) ); } template<typename ObjectType ,typename ReturnType ,typename Adaptor> Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType> enumGetAtAdapt( const ObjectType &object, ReturnType (ObjectType::getAtMethod)(int index) const, int startIndex, int elementCount, Adaptor adaptor ) { typedef BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType EnumeratedType; return Enumerator<EnumeratedType>( new GetAtEnumeratorImpl<ObjectType, EnumeratedType, ReturnType, Adaptor>( object, getAtMethod, startIndex, count, adaptor ) ); } template<typename ObjectType ,typename EnumeratedType ,typename ReturnType> Enumerator<EnumeratedType> enumGetAt( const ObjectType &object, ReturnType (ObjectType::getAtMethod)(int index) const, int startIndex, int elementCount, Type<EnumeratedType> ) { return enumGetAtAdapt( object, getAtMethod, startIndex, elementCount, ConstructEnumAdaptor<EnumeratedType>() ); } } // namespace Xtl #endif // XTL_GETATENUMERATOR_H_INCLUDED |