Public Types | List of all members
blaze::PtrIterator< Type > Class Template Reference

Implementation of an iterator for pointer vectors.The PtrIterator class follows the example of the random-access iterator classes of the STL. However, the focus of this iterator implementation is the use with (polymorphic) pointers. The implementation of the Blaze library eases the use of iterators over a range of pointers and improves the semantics on these pointers.
. More...

#include <PtrIterator.h>

Public Types

typedef std::random_access_iterator_tag IteratorCategory
 The iterator category.
 
typedef Type * ValueType
 Type of the underlying pointers.
 
typedef Type * PointerType
 Pointer return type.
 
typedef ValueType const & ReferenceType
 Reference return type.
 
typedef ValueType const * IteratorType
 Type of the internal pointer.
 
typedef std::ptrdiff_t DifferenceType
 Difference between two iterators.
 
typedef IteratorCategory iterator_category
 The iterator category.
 
typedef ValueType value_type
 Type of the underlying pointers.
 
typedef PointerType pointer
 Pointer return type.
 
typedef ReferenceType reference
 Reference return type.
 
typedef DifferenceType difference_type
 Difference between two iterators.
 

Public Member Functions

Constructors
 PtrIterator ()
 Default constructor for PtrIterator.
 
 PtrIterator (const IteratorType &it)
 Standard constructor for PtrIterator. More...
 
template<typename Other >
 PtrIterator (const PtrIterator< Other > &it)
 Conversion constructor from different PtrIterator instances. More...
 
Operators
PtrIteratoroperator++ ()
 Pre-increment operator. More...
 
PtrIterator operator++ (int)
 Post-increment operator. More...
 
PtrIteratoroperator-- ()
 Pre-decrement operator. More...
 
PtrIterator operator-- (int)
 Post-decrement operator. More...
 
PtrIteratoroperator+= (DifferenceType n)
 Shifting the iterator by n elements to the higher elements. More...
 
PtrIterator operator+ (DifferenceType n) const
 Shifting the iterator by n elements to the higher elements. More...
 
PtrIteratoroperator-= (DifferenceType n)
 Shifting the iterator by n elements to the lower elements. More...
 
PtrIterator operator- (DifferenceType n) const
 Shifting the iterator by n elements to the lower elements. More...
 
DifferenceType operator- (const PtrIterator &it) const
 Calculating the number of elements between two pointer iterators. More...
 
Access operators
PointerType operator[] (DifferenceType n) const
 Subscript operator for the direct element access. More...
 
PointerType operator* () const
 Returns a handle to the element at the current iterator position. More...
 
PointerType operator-> () const
 Direct access to the element at the current iterator position. More...
 
Utility functions
const IteratorTypebase () const
 Access to the underlying member of the pointer iterator. More...
 

Private Attributes

Member variables
IteratorType it_
 Pointer to the current memory location.
 

Detailed Description

template<typename Type>
class blaze::PtrIterator< Type >

Implementation of an iterator for pointer vectors.

The PtrIterator class follows the example of the random-access iterator classes of the STL. However, the focus of this iterator implementation is the use with (polymorphic) pointers. The implementation of the Blaze library eases the use of iterators over a range of pointers and improves the semantics on these pointers.
.

In contrast to the STL iterators, the PtrIterator class slightly changes the meaning of the access operators. Consider the following example:

// Definition of class A
class A
{
public:
A( int i=0 ):i_(i) {}
void set( int i ) { i_ = i; }
int get() const { return i_; }
private:
int i_;
};
// Definition of a pointer vector for class A
typedef blaze::PtrVector<A> AVector;
AVector vector;
AVector::Iterator it = vector.begin();
// The subscript operator returns a handle to the underlying object
A* a1 = it[0];
// The dereference operator returns a handle to the underlying object
A* a2 = *it;
// The member access operator offers direct access to the underlying object
it->set( 2 );

The constant iterators (iterator over constant objects) prohibit the access to non-const member functions. Therefore the following operation results in a compile-time error:

AVector vector;
AVector::ConstIterator it = vector.begin();
it->set( 2 ); // Compile-time error!

Constructor & Destructor Documentation

template<typename Type >
blaze::PtrIterator< Type >::PtrIterator ( const IteratorType it)
inlineexplicit

Standard constructor for PtrIterator.

Parameters
itThe value of the iterator.
template<typename Type >
template<typename Other >
blaze::PtrIterator< Type >::PtrIterator ( const PtrIterator< Other > &  it)
inline

Conversion constructor from different PtrIterator instances.

Parameters
itThe foreign PtrIterator instance to be copied.

Member Function Documentation

template<typename Type >
const PtrIterator< Type >::IteratorType & blaze::PtrIterator< Type >::base ( ) const
inline

Access to the underlying member of the pointer iterator.

Returns
Pointer to the current memory location.
template<typename Type >
PtrIterator< Type >::PointerType blaze::PtrIterator< Type >::operator* ( ) const
inline

Returns a handle to the element at the current iterator position.

Returns
Handle to the element at the current iterator position.
template<typename Type >
PtrIterator< Type > blaze::PtrIterator< Type >::operator+ ( DifferenceType  n) const
inline

Shifting the iterator by n elements to the higher elements.

Parameters
nThe number of elements.
Returns
The shifted pointer iterator.
template<typename Type >
PtrIterator< Type > & blaze::PtrIterator< Type >::operator++ ( )
inline

Pre-increment operator.

Returns
Reference to the incremented pointer iterator.
template<typename Type >
PtrIterator< Type > blaze::PtrIterator< Type >::operator++ ( int  )
inline

Post-increment operator.

Returns
The incremented pointer iterator.
template<typename Type >
PtrIterator< Type > & blaze::PtrIterator< Type >::operator+= ( DifferenceType  n)
inline

Shifting the iterator by n elements to the higher elements.

Parameters
nThe number of elements.
Returns
Reference to the shifted pointer iterator.
template<typename Type >
PtrIterator< Type > blaze::PtrIterator< Type >::operator- ( DifferenceType  n) const
inline

Shifting the iterator by n elements to the lower elements.

Parameters
nThe number of elements.
Returns
The shifted pointer iterator.
template<typename Type >
PtrIterator< Type >::DifferenceType blaze::PtrIterator< Type >::operator- ( const PtrIterator< Type > &  it) const
inline

Calculating the number of elements between two pointer iterators.

Parameters
itThe right hand side iterator.
Returns
The number of elements between the two pointer iterators.
template<typename Type >
PtrIterator< Type > & blaze::PtrIterator< Type >::operator-- ( )
inline

Pre-decrement operator.

Returns
Reference to the decremented pointer iterator.
template<typename Type >
PtrIterator< Type > blaze::PtrIterator< Type >::operator-- ( int  )
inline

Post-decrement operator.

Returns
The decremented pointer iterator.
template<typename Type >
PtrIterator< Type > & blaze::PtrIterator< Type >::operator-= ( DifferenceType  n)
inline

Shifting the iterator by n elements to the lower elements.

Parameters
nThe number of elements.
Returns
Reference to the shifted pointer iterator.
template<typename Type >
PtrIterator< Type >::PointerType blaze::PtrIterator< Type >::operator-> ( ) const
inline

Direct access to the element at the current iterator position.

Returns
Reference to the element at the current iterator position.
template<typename Type >
PtrIterator< Type >::PointerType blaze::PtrIterator< Type >::operator[] ( DifferenceType  index) const
inline

Subscript operator for the direct element access.

Parameters
indexAccess index. Accesses the element index elements away from the current iterator position.
Returns
Handle to the accessed element.

The documentation for this class was generated from the following file: