Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

BaseIterator< Container, DataType, Position, Traits > Class Template Reference
[Iterators]

Generic Iterator Class. More...

#include <baseIterator.h>

Inheritance diagram for BaseIterator< Container, DataType, Position, Traits >:

ConstForwardIterator< Container, DataType, Position, Traits > ConstBidirectionalIterator< Container, DataType, Position, Traits > ForwardIterator< Container, DataType, Position, Traits > BidirectionalIterator< Container, DataType, Position, Traits > List of all members.

Public Types

Typedefs.
The names of these typedefs deviate from the usual BALL class names due to restrictions imposed by STL compliance.

typedef DataType value_type
typedef Position difference_type
typedef const DataType * pointer
typedef const DataType & reference
typedef std::input_iterator_tag iterator_category

Public Member Functions

Constructors and Destructors
 BaseIterator () throw ()
 Default constructor.
 BaseIterator (const BaseIterator &iterator) throw ()
 Copy constructor.
 ~BaseIterator () throw ()
 Destructor.
Assignment
BaseIteratoroperator= (const BaseIterator &iterator) throw ()
 Assignment operator.
void swap (BaseIterator &iterator) throw ()
 Swap two iterators.
Accessors
void invalidate () throw ()
 Invalidate the iterator.
void setTraits (const Traits &traits) throw ()
 Set the traits.
const Traits & getTraits () const throw ()
 Get a constant reference to the traits of this iterator.
Traits & getTraits () throw ()
 Get a constant reference to the traits of this iterator.
const Container * getContainer () const throw ()
 Get a constant pointer to the container of this iterator.
Converters
 operator const Position & () const throw ()
 Convert an iterator to Position.
reference operator * () const throw ()
 Convert an iterator to its Datatype by returning a reference to the current data.
pointer operator-> () const throw ()
 Return a pointer to the current data.
Predicates
bool operator== (const BaseIterator &iterator) const throw ()
 Equality operator.
bool operator!= (const BaseIterator &iterator) const throw ()
 Inequality operator.
bool isSingular () const throw ()
 Singularity predicate.
bool isValid () const throw ()
 Validity predicate.
bool operator+ () const throw ()
 Validity predicate.
bool operator- () const throw ()
 Invalidity perdicate.

Protected Member Functions

 BaseIterator (const Container &container) throw ()
 Constructor.

Detailed Description

template<typename Container, typename DataType, typename Position, typename Traits>
class BaseIterator< Container, DataType, Position, Traits >

Generic Iterator Class.

This template class implements the basic behaviour of an iterator. Iterators are basically STL-like iterators. They provide the full STL iterator interface, but also offer additional features.

BaseIterator itself is a base class to the other iterator classes only and should not be used by itself.
An important difference exists for the iterators of the kernel objects. For most kernel objects, multiple iterators exist. Therefore, we could not simply use begin() and end() like in STL, but we introduced specialized methods like AtomContainer::beginAtom and AtomContainer::endAtom . For similar reasons, the iterators for kernel classes are not implemented as nested classes of the respective kernel classes, but as independent classes to avoid code replication. An exception is Atom::BondIterator , which is relevant to Atom alone.
Each BALL iterator can be bound to a container, so once the iteration has started, it "knows" about the end() of the container. Therefore, BALL iterators additionally implement the unary plus operator to check for the validity of the iterator. this allows the convenient implementation of for loops, e.g. as follows:
        AtomIterator atom_it = system.beginAtom();
        for (; +atom_it; ++atom_it)
        {
          ....
        }


Constructor & Destructor Documentation

template<typename Container, typename DataType, typename Position, typename Traits>
BaseIterator< Container, DataType, Position, Traits >::BaseIterator const Container &  container  )  throw () [protected]
 

Constructor.

Protected to allow instantiation and use in derived classes only.


Member Function Documentation

template<typename Container, typename DataType, typename Position, typename Traits>
bool BaseIterator< Container, DataType, Position, Traits >::isSingular  )  const throw ()
 

Singularity predicate.

This method returns true if the iterator is singular, i.e., not associated with a container.

template<typename Container, typename DataType, typename Position, typename Traits>
bool BaseIterator< Container, DataType, Position, Traits >::isValid  )  const throw ()
 

Validity predicate.

Returns:
true if the iterator is valid (pointing at an element in a container)

template<typename Container, typename DataType, typename Position, typename Traits>
BaseIterator< Container, DataType, Position, Traits >::operator const Position &  )  const throw ()
 

Convert an iterator to Position.

This method returns the position of the iterator. Note that Position is a template within this context and not the BALL datatype.

template<typename Container, typename DataType, typename Position, typename Traits>
BaseIterator& BaseIterator< Container, DataType, Position, Traits >::operator= const BaseIterator< Container, DataType, Position, Traits > &  iterator  )  throw ()
 

Assignment operator.

Assigns the contents of an iterator to another iterator.

Parameters:
iterator the iterator to be copied