Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbAdapterItr< T, I > Class Template Reference

A proxy class retranslating values of an "input" type into the "output" one. More...

#include <CdbAdapterItr.hh>

Inheritance diagram for CdbAdapterItr< T, I >:

CdbIItr< T > List of all members.

Public Member Functions

virtual ~CdbAdapterItr ()
 The destructor.

virtual CdbStatus reset ()
 Reset an iterator to its initial state.

virtual bool next ()
 Advance an iterator to the next position.

virtual T value ()
 Obtain the currently reffered value.

virtual bool isValid ()
 Check if an iterator is valid.


Protected Member Functions

 CdbAdapterItr (CdbIItr< I > *theInputItrPtr)
 The normal constructor.

 CdbAdapterItr (const CdbAdapterItr< T, I > &theItr)
 The copy constructor.

virtual T toValue (const I &) const=0
 User defined translation for the currently referred value.

virtual bool isAccepted (const I &) const
 Optional user defined filter for input objects.


Detailed Description

template<class T, class I>
class CdbAdapterItr< T, I >

A proxy class retranslating values of an "input" type into the "output" one.

This abstract class is meant to be used for rapid building of CDB API iterators of the "output" type out of input iterators of the "input" type of elements. The class is parameterized by two parameters:

T - "output" type of the iterator values produced by the current iterator I - "input" type of an input iterator's elements

A basic idea is that a value of the I type needs to be translated into the corresponding value of the T type. The translation is done through a special virtual method to be overloaded by a subclass.

In addition, the iterator provides an optional filtering mechanism to evaluate each input object withing the iterator's "::next()" method. That would allow (if needed by a subclass) to exclude certain objects out of the input sequence from being translated and delivered though the "::value()" and "::toValue()" method. The name of the method is "::isAccepted()". If the method returns "true" then the object is accepted, otherwise - it's rejected, and the iterator will go to the next object input object and so on. By default the method will accept all objects.

See also:
CdbAdapterItr::toValue()

CdbAdapterItr::isAccepted()

EXAMPLE:

#include "CdbBase/CdbAdapterItr.hh"

class MyItr : public CdbAdapterItr<std::string, unsigned int> { public: MyItr( const CdbIItr<unsigned int>& theInputItr ) : CdbAdapterItr<std::string, unsigned int>( theInputItr ) { } protected: virtual std::string toValue( const unsigned int& theValue ) const { ... } virtual bool isAccepted( const unsigned int& theValue ) const { return ( theValue >= 0 ); } };

IMPLEMENTATION NOTE:

This particular implementation of the iterator has not been optimized to cache the translated values locally. This feature will be implemented later. Just keep this performance issue in mind when using the iterator.

Definition at line 59 of file CdbAdapterItr.hh.


Constructor & Destructor Documentation

template<class T, class I>
CdbAdapterItr< T, I >::CdbAdapterItr CdbIItr< I > *    theInputItrPtr [protected]
 

The normal constructor.

We'll take an input iterator whose values need to be retranslated to deliver values of specified "output" type as the iterator will advance.

DESIGN NOTE:

The iterator will take over the specified one.

Definition at line 19 of file CdbAdapterItr.cc.

template<class T, class I>
CdbAdapterItr< T, I >::CdbAdapterItr const CdbAdapterItr< T, I > &    theItr [protected]
 

The copy constructor.

Definition at line 32 of file CdbAdapterItr.cc.

template<class T, class I>
CdbAdapterItr< T, I >::~CdbAdapterItr   [virtual]
 

The destructor.

Definition at line 38 of file CdbAdapterItr.cc.


Member Function Documentation

template<class T, class I>
virtual bool CdbAdapterItr< T, I >::isAccepted const I &    const [inline, protected, virtual]
 

Optional user defined filter for input objects.

This method is being called by the "::next()" method of the current implementation of the itarator for each input object in order to determine if that object needs to be translated or filtered out.

If the method returns "true" then the object is accepted, otherwise - it's rejected, and the iterator will go to the next object input object and so on.

The default implementation of the method would accept all objects.

The method can be optionally implemented by a subclass.

Returns:
"true" to accept an object, and "false" - to reject.

Definition at line 158 of file CdbAdapterItr.hh.

Referenced by CdbAdapterItr< T, I >::next().

template<class T, class I>
bool CdbAdapterItr< T, I >::isValid   [virtual]
 

Check if an iterator is valid.

This implements the corresponding method of the base class.

See also:
CdbIItr::isValid()

Implements CdbIItr< T >.

Definition at line 86 of file CdbAdapterItr.cc.

References CdbIItr< I >::isValid().

template<class T, class I>
bool CdbAdapterItr< T, I >::next   [virtual]
 

Advance an iterator to the next position.

This implements the corresponding method of the base class.

See also:
CdbIItr::next()

Implements CdbIItr< T >.

Definition at line 57 of file CdbAdapterItr.cc.

References CdbAdapterItr< T, I >::isAccepted(), CdbIItr< I >::next(), and CdbIItr< I >::value().

template<class T, class I>
CdbStatus CdbAdapterItr< T, I >::reset   [virtual]
 

Reset an iterator to its initial state.

This implements the corresponding method of the base class.

See also:
CdbIItr::reset

CdbStatus

Implements CdbIItr< T >.

Definition at line 49 of file CdbAdapterItr.cc.

References CdbIItr< I >::reset().

template<class T, class I>
virtual T CdbAdapterItr< T, I >::toValue const I &    const [protected, pure virtual]
 

User defined translation for the currently referred value.

This method is being called by the current implementation of the itarator to translate the desired information out of the currently refered element of the input iterator passed to the class's constructor.

The method is supposed to be implemented by a subclass.

Returns:
the current value the iterator is set on

Implemented in CdbSTD2CStrAdapterItr.

Referenced by CdbAdapterItr< T, I >::value().

template<class T, class I>
T CdbAdapterItr< T, I >::value   [virtual]
 

Obtain the currently reffered value.

This implements the corresponding method of the base class.

See also:
CdbIItr::value()
Returns:
the current value the iterator is set on

Implements CdbIItr< T >.

Definition at line 71 of file CdbAdapterItr.cc.

References CdbIItr< I >::isValid(), CdbAdapterItr< T, I >::toValue(), and CdbIItr< I >::value().


The documentation for this class was generated from the following files:
Generated on Mon Dec 5 18:22:17 2005 for CDB by doxygen1.3-rc3