Loading...
Searching...
No Matches
forwardIterator.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_CONCEPT_FORWARDITERATOR_H
#define BALL_CONCEPT_FORWARDITERATOR_H
#ifndef BALL_CONCEPT_BASEITERATOR_H
# include <BALL/CONCEPT/baseIterator.h>
#endif
namespace BALL
{
template <typename Container, typename DataType, typename Position, typename Traits>
class ConstForwardIterator
: public BaseIterator<Container, DataType, Position, Traits>
{
public:
typedef std::forward_iterator_tag iterator_category;
// convenience typedef
typedef BaseIterator<Container, DataType, Position, Traits> Base;
BALL_INLINE ConstForwardIterator() {}
BALL_INLINE ConstForwardIterator(const ConstForwardIterator& iterator)
: BaseIterator<Container, DataType, Position, Traits>(iterator)
{
}
BALL_INLINE ~ConstForwardIterator() {}
BALL_INLINE ConstForwardIterator& operator = (const ConstForwardIterator& iterator)
{
BaseIterator<Container, DataType, Position, Traits>::operator = (iterator);
return *this;
}
BALL_INLINE void swap(ConstForwardIterator& iterator) { std::swap(ConstForwardIterator<Container, DataType, Position, Traits>::getTraits(), iterator.getTraits()); }
BALL_INLINE void toBegin();
BALL_INLINE bool isBegin() const;
BALL_INLINE void toEnd();
BALL_INLINE bool isEnd() const;
static ConstForwardIterator begin(const Container& container);
static ConstForwardIterator end(const Container& container);
BALL_INLINE ConstForwardIterator& operator ++ ()
{
BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
Base::getTraits().forward();
return *this;
}
BALL_INLINE ConstForwardIterator operator ++ (int)
{
BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
ConstForwardIterator tmp(*this);
++(*this);
return tmp;
}
protected:
BALL_INLINE ConstForwardIterator(const Container& container)
: BaseIterator<Container, DataType, Position, Traits>(container)
{
}
};
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstForwardIterator<Container, DataType, Position, Traits>::toBegin()
{
BALL_PRECONDITION_EXCEPTION(!Base::isSingular(), "cannot move singular iterator to begin")
Base::getTraits().toBegin();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstForwardIterator<Container, DataType, Position, Traits>
ConstForwardIterator<Container, DataType, Position, Traits>::begin(const Container& container)
{
ConstForwardIterator<Container, DataType, Position, Traits> iterator(container);
iterator.toBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
bool ConstForwardIterator<Container, DataType, Position, Traits>::isBegin() const
{
if (Base::getTraits().isSingular())
{
return false;
}
return Base::getTraits().isBegin();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstForwardIterator<Container, DataType, Position, Traits>::toEnd()
{
BALL_PRECONDITION_EXCEPTION(!Base::isSingular(), "cannot move singular iterator to end")
Base::getTraits().toEnd();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstForwardIterator<Container, DataType, Position, Traits>
ConstForwardIterator<Container, DataType, Position, Traits>::end(const Container& container)
{
ConstForwardIterator iterator(container);
iterator.toEnd();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
bool ConstForwardIterator<Container, DataType, Position, Traits>::isEnd() const
{
if (Base::isSingular())
{
return false;
}
return Base::getTraits().isEnd();
}
template <typename Container, typename DataType, typename Position, typename Traits>
class ForwardIterator
: public ConstForwardIterator<Container, DataType, Position, Traits>
{
public:
typedef DataType& reference;
typedef DataType* pointer;
// convenience typedef
typedef ConstForwardIterator<Container, DataType, Position, Traits> Base;
BALL_INLINE ForwardIterator() {}
BALL_INLINE ForwardIterator(const ForwardIterator& iterator)
: ConstForwardIterator<Container, DataType, Position, Traits>(iterator)
{
}
BALL_INLINE ~ForwardIterator() {}
BALL_INLINE ForwardIterator& operator = (const ForwardIterator& iterator)
{
ConstForwardIterator<Container, DataType, Position, Traits>::operator = (iterator);
return *this;
}
BALL_INLINE void swap(ForwardIterator& iterator) { std::swap(Base::getTraits(), iterator.getTraits()); }
static ForwardIterator begin(const Container& container);
static ForwardIterator end(const Container& container);
BALL_INLINE reference operator * () const
{
return (reference)Base::getTraits().getData();
}
BALL_INLINE pointer operator -> () const
{
return (pointer)&Base::getTraits().getData();
}
BALL_INLINE ForwardIterator& operator ++ ()
{
BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
Base::getTraits().forward();
return *this;
}
BALL_INLINE ForwardIterator operator ++ (int)
{
BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
ForwardIterator tmp(*this);
++(*this);
return tmp;
}
protected:
BALL_INLINE ForwardIterator(const Container& container)
: Base(container)
{
}
};
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ForwardIterator<Container, DataType, Position, Traits>
ForwardIterator<Container, DataType, Position, Traits>::begin(const Container& container)
{
ForwardIterator iterator(container);
iterator.toBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ForwardIterator<Container, DataType, Position, Traits>
ForwardIterator<Container, DataType, Position, Traits>::end(const Container& container)
{
ForwardIterator iterator(container);
iterator.toEnd();
return iterator;
}
} // namespace BALL
#endif // BALL_CONCEPT_FORWARDITERATOR_H
baseIterator.h
BALL::BaseIterator::operator=
BALL_INLINE BaseIterator & operator=(const BaseIterator &iterator)
Definition baseIterator.h:109
BALL::BaseIterator::getTraits
BALL_INLINE const Traits & getTraits() const
Get a constant reference to the traits of this iterator.
Definition baseIterator.h:130
BALL::BaseIterator::isValid
BALL_INLINE bool isValid() const
Definition baseIterator.h:175
BALL::BaseIterator::isSingular
BALL_INLINE bool isSingular() const
Definition baseIterator.h:170
BALL::BaseIterator::BaseIterator
BALL_INLINE BaseIterator()
Default constructor.
Definition baseIterator.h:89
BALL::ConstForwardIterator
Definition forwardIterator.h:26
BALL::ConstForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits >::iterator_category
std::forward_iterator_tag iterator_category
Definition forwardIterator.h:34
BALL::ConstForwardIterator::isEnd
BALL_INLINE bool isEnd() const
Check whether the iterator points behind the last item of the container.
Definition forwardIterator.h:184
BALL::ConstForwardIterator::ConstForwardIterator
BALL_INLINE ConstForwardIterator()
Default constructor.
Definition forwardIterator.h:44
BALL::ConstForwardIterator::toEnd
BALL_INLINE void toEnd()
Definition forwardIterator.h:166
BALL::ConstForwardIterator::isBegin
BALL_INLINE bool isBegin() const
Check whether the iterator points to the first item of the container.
Definition forwardIterator.h:154
BALL::ConstForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits >::Base
BaseIterator< Composite, Composite, Composite *, AncestorIteratorTraits > Base
Definition forwardIterator.h:36
BALL::ConstForwardIterator::toBegin
BALL_INLINE void toBegin()
Definition forwardIterator.h:136
BALL::ConstForwardIterator::begin
static ConstForwardIterator begin(const Container &container)
Definition forwardIterator.h:145
BALL::ConstForwardIterator::ConstForwardIterator
BALL_INLINE ConstForwardIterator(const Container &container)
Definition forwardIterator.h:127
BALL::ConstForwardIterator::~ConstForwardIterator
BALL_INLINE ~ConstForwardIterator()
Definition forwardIterator.h:53
BALL::ConstForwardIterator::end
static ConstForwardIterator end(const Container &container)
Definition forwardIterator.h:175
BALL::ConstForwardIterator::operator++
BALL_INLINE ConstForwardIterator & operator++()
Definition forwardIterator.h:104
BALL::ConstForwardIterator::ConstForwardIterator
BALL_INLINE ConstForwardIterator(const ConstForwardIterator &iterator)
Copy constructor.
Definition forwardIterator.h:47
BALL::ConstForwardIterator::swap
BALL_INLINE void swap(ConstForwardIterator &iterator)
Definition forwardIterator.h:68
BALL::ConstForwardIterator::operator=
BALL_INLINE ConstForwardIterator & operator=(const ConstForwardIterator &iterator)
Definition forwardIterator.h:61
BALL::ForwardIterator
Definition forwardIterator.h:199
BALL::ForwardIterator::operator=
BALL_INLINE ForwardIterator & operator=(const ForwardIterator &iterator)
Definition forwardIterator.h:235
BALL::ForwardIterator::operator->
BALL_INLINE pointer operator->() const
Definition forwardIterator.h:266
BALL::ForwardIterator::begin
static ForwardIterator begin(const Container &container)
Definition forwardIterator.h:307
BALL::ForwardIterator::ForwardIterator
BALL_INLINE ForwardIterator(const Container &container)
Definition forwardIterator.h:297
BALL::ForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits >::reference
Composite & reference
Definition forwardIterator.h:207
BALL::ForwardIterator::ForwardIterator
BALL_INLINE ForwardIterator()
Definition forwardIterator.h:219
BALL::ForwardIterator::~ForwardIterator
BALL_INLINE ~ForwardIterator()
Definition forwardIterator.h:228
BALL::ForwardIterator::ForwardIterator
BALL_INLINE ForwardIterator(const ForwardIterator &iterator)
Definition forwardIterator.h:222
BALL::ForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits >::pointer
Composite * pointer
Definition forwardIterator.h:209
BALL::ForwardIterator::operator++
BALL_INLINE ForwardIterator & operator++()
Definition forwardIterator.h:274
BALL::ForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits >::Base
ConstForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits > Base
Definition forwardIterator.h:211
BALL::ForwardIterator::swap
BALL_INLINE void swap(ForwardIterator &iterator)
Definition forwardIterator.h:242
BALL::ForwardIterator::end
static ForwardIterator end(const Container &container)
Definition forwardIterator.h:317
BALL::ForwardIterator::operator*
BALL_INLINE reference operator*() const
Definition forwardIterator.h:260
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
BALL_PRECONDITION_EXCEPTION
#define BALL_PRECONDITION_EXCEPTION(condition, message)
Definition debug.h:89
BALL
Definition constants.h:13
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140