Loading...
Searching...
No Matches
bidirectionalIterator.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_CONCEPT_BIDIRECTIONALITERATOR_H
#define BALL_CONCEPT_BIDIRECTIONALITERATOR_H
#ifndef BALL_CONCEPT_FORWARDITERATOR_H
# include <BALL/CONCEPT/forwardIterator.h>
#endif
namespace BALL
{
template <typename Container, typename DataType, typename Position, typename Traits>
class ConstBidirectionalIterator
: public ConstForwardIterator<Container, DataType, Position, Traits>
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
// convenience typedef
typedef ConstForwardIterator<Container, DataType, Position, Traits> Base;
BALL_INLINE ConstBidirectionalIterator() {}
BALL_INLINE ConstBidirectionalIterator(const ConstBidirectionalIterator& iterator)
: Base(iterator)
{
}
BALL_INLINE ~ConstBidirectionalIterator() {}
BALL_INLINE void toBegin();
BALL_INLINE bool isBegin() const { return Base::getTraits().isBegin(); }
void toEnd();
BALL_INLINE bool isEnd() const { return Base::getTraits().isEnd(); }
void toRBegin();
BALL_INLINE bool isRBegin() const { return Base::getTraits().isRBegin(); }
void toREnd();
BALL_INLINE bool isREnd() const { return Base::getTraits().isREnd(); }
BALL_INLINE ConstBidirectionalIterator& operator ++ ();
BALL_INLINE ConstBidirectionalIterator operator ++ (int);
BALL_INLINE ConstBidirectionalIterator& operator -- ();
BALL_INLINE ConstBidirectionalIterator operator -- (int);
static ConstBidirectionalIterator begin(const Container& container);
static ConstBidirectionalIterator end(const Container& container);
static ConstBidirectionalIterator rbegin(const Container& container);
static ConstBidirectionalIterator rend(const Container& container);
protected:
BALL_INLINE ConstBidirectionalIterator(const Container& container)
: Base(container)
{
}
};
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstBidirectionalIterator<Container, DataType, Position, Traits>::toBegin()
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to begin")
Base::getTraits().toBegin();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstBidirectionalIterator<Container, DataType, Position, Traits>::toEnd()
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to end")
Base::getTraits().toEnd();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstBidirectionalIterator<Container, DataType, Position, Traits>::toRBegin()
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to reverse begin")
Base::getTraits().toRBegin();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
void ConstBidirectionalIterator<Container, DataType, Position, Traits>::toREnd()
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to reverse end")
Base::getTraits().toREnd();
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>&
ConstBidirectionalIterator<Container, DataType, Position, Traits>::operator ++ ()
{
BALL_PRECONDITION_EXCEPTION(Base::getTraits().isValid(), "cannot increment an invalid iterator")
Base::getTraits().forward();
return *this;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::operator ++ (int)
{
BALL_PRECONDITION_EXCEPTION(Base::getTraits().isValid(), "cannot increment an invalid iterator")
ConstBidirectionalIterator iterator(*this);
++(*this);
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>&
ConstBidirectionalIterator<Container, DataType, Position, Traits>::operator -- ()
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot decrement unbound iterator")
Base::getTraits().backward();
return *this;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::operator -- (int)
{
BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot decrement an unbound iterator")
ConstBidirectionalIterator iterator(*this);
--(*this);
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::begin(const Container& container)
{
ConstBidirectionalIterator iterator(container);
iterator.toBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::end(const Container& container)
{
ConstBidirectionalIterator iterator(container);
iterator.toEnd();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::rbegin(const Container& container)
{
ConstBidirectionalIterator iterator(container);
iterator.toRBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
ConstBidirectionalIterator<Container, DataType, Position, Traits>
ConstBidirectionalIterator<Container, DataType, Position, Traits>::rend(const Container& container)
{
ConstBidirectionalIterator iterator(container);
iterator.toREnd();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
class BidirectionalIterator
: public ConstBidirectionalIterator<Container, DataType, Position, Traits>
{
public:
typedef DataType& reference;
typedef DataType* pointer;
// convenience typedef
typedef ConstBidirectionalIterator<Container, DataType, Position, Traits> Base;
BALL_INLINE BidirectionalIterator() {}
BALL_INLINE BidirectionalIterator(const BidirectionalIterator& iterator)
: ConstBidirectionalIterator<Container, DataType, Position, Traits>(iterator)
{
}
BALL_INLINE ~BidirectionalIterator() {}
BALL_INLINE reference operator * () const { return (reference)Base::getTraits().getData(); }
BALL_INLINE pointer operator -> () const { return (pointer)&Base::getTraits().getData(); }
BALL_INLINE BidirectionalIterator& operator ++ ();
BALL_INLINE BidirectionalIterator operator ++ (int);
BALL_INLINE BidirectionalIterator& operator -- ();
BALL_INLINE BidirectionalIterator operator -- (int);
static BidirectionalIterator begin(const Container& container);
static BidirectionalIterator end(const Container& container);
static BidirectionalIterator rbegin(const Container& container);
static BidirectionalIterator rend(const Container& container);
protected:
BALL_INLINE BidirectionalIterator(const Container& container) ;
};
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>&
BidirectionalIterator<Container, DataType, Position, Traits>::operator ++ ()
{
Base::operator ++ ();
return *this;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::operator ++ (int)
{
BidirectionalIterator iterator(*this);
this->operator ++ ();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>&
BidirectionalIterator<Container, DataType, Position, Traits>::operator -- ()
{
Base::operator -- ();
return *this;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::operator -- (int)
{
BidirectionalIterator iterator(*this);
this->operator -- ();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::begin(const Container& container)
{
BidirectionalIterator iterator(container);
iterator.toBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::end(const Container& container)
{
BidirectionalIterator iterator(container);
iterator.toEnd();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::rbegin(const Container& container)
{
BidirectionalIterator iterator(container);
iterator.toRBegin();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>
BidirectionalIterator<Container, DataType, Position, Traits>::rend(const Container& container)
{
BidirectionalIterator iterator(container);
iterator.toREnd();
return iterator;
}
template <typename Container, typename DataType, typename Position, typename Traits>
BALL_INLINE
BidirectionalIterator<Container, DataType, Position, Traits>::BidirectionalIterator(const Container& container)
: ConstBidirectionalIterator<Container, DataType, Position, Traits>(container)
{
}
} // namespace BALL
#endif // BALL_CONCEPT_BIDIRECTIONALITERATOR_H
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::BidirectionalIterator
Mutable bidirectional iterator.
Definition bidirectionalIterator.h:260
BALL::BidirectionalIterator::~BidirectionalIterator
BALL_INLINE ~BidirectionalIterator()
Destructor.
Definition bidirectionalIterator.h:290
BALL::BidirectionalIterator::operator++
BALL_INLINE BidirectionalIterator & operator++()
Definition bidirectionalIterator.h:355
BALL::BidirectionalIterator::end
static BidirectionalIterator end(const Container &container)
Definition bidirectionalIterator.h:403
BALL::BidirectionalIterator::pointer
DataType * pointer
Definition bidirectionalIterator.h:270
BALL::BidirectionalIterator::rbegin
static BidirectionalIterator rbegin(const Container &container)
Definition bidirectionalIterator.h:413
BALL::BidirectionalIterator::Base
ConstBidirectionalIterator< Container, DataType, Position, Traits > Base
Definition bidirectionalIterator.h:272
BALL::BidirectionalIterator::operator--
BALL_INLINE BidirectionalIterator & operator--()
Definition bidirectionalIterator.h:374
BALL::BidirectionalIterator::rend
static BidirectionalIterator rend(const Container &container)
Definition bidirectionalIterator.h:423
BALL::BidirectionalIterator::BidirectionalIterator
BALL_INLINE BidirectionalIterator(const Container &container)
Construct an iterator bound to a specific container.
Definition bidirectionalIterator.h:432
BALL::BidirectionalIterator::reference
DataType & reference
Definition bidirectionalIterator.h:268
BALL::BidirectionalIterator::operator*
BALL_INLINE reference operator*() const
Dereferentiation.
Definition bidirectionalIterator.h:299
BALL::BidirectionalIterator::operator->
BALL_INLINE pointer operator->() const
Pointer dereferentiation.
Definition bidirectionalIterator.h:302
BALL::BidirectionalIterator::begin
static BidirectionalIterator begin(const Container &container)
Definition bidirectionalIterator.h:393
BALL::BidirectionalIterator::BidirectionalIterator
BALL_INLINE BidirectionalIterator()
Default constructor.
Definition bidirectionalIterator.h:280
BALL::BidirectionalIterator::BidirectionalIterator
BALL_INLINE BidirectionalIterator(const BidirectionalIterator &iterator)
Copy constructor.
Definition bidirectionalIterator.h:283
BALL::ConstBidirectionalIterator
Definition bidirectionalIterator.h:25
BALL::ConstBidirectionalIterator::~ConstBidirectionalIterator
BALL_INLINE ~ConstBidirectionalIterator()
Definition bidirectionalIterator.h:52
BALL::ConstBidirectionalIterator::begin
static ConstBidirectionalIterator begin(const Container &container)
Definition bidirectionalIterator.h:219
BALL::ConstBidirectionalIterator::end
static ConstBidirectionalIterator end(const Container &container)
Definition bidirectionalIterator.h:229
BALL::ConstBidirectionalIterator::operator--
BALL_INLINE ConstBidirectionalIterator & operator--()
Definition bidirectionalIterator.h:198
BALL::ConstBidirectionalIterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition bidirectionalIterator.h:33
BALL::ConstBidirectionalIterator::isEnd
BALL_INLINE bool isEnd() const
Check whether the iterator points to the position after the last item of the container.
Definition bidirectionalIterator.h:73
BALL::ConstBidirectionalIterator::isRBegin
BALL_INLINE bool isRBegin() const
Test whether the iterator points to the "reverse" first element of the container.
Definition bidirectionalIterator.h:81
BALL::ConstBidirectionalIterator::toBegin
BALL_INLINE void toBegin()
Definition bidirectionalIterator.h:144
BALL::ConstBidirectionalIterator::ConstBidirectionalIterator
BALL_INLINE ConstBidirectionalIterator(const ConstBidirectionalIterator &iterator)
Definition bidirectionalIterator.h:46
BALL::ConstBidirectionalIterator::toEnd
void toEnd()
Definition bidirectionalIterator.h:152
BALL::ConstBidirectionalIterator::ConstBidirectionalIterator
BALL_INLINE ConstBidirectionalIterator()
Definition bidirectionalIterator.h:43
BALL::ConstBidirectionalIterator::rend
static ConstBidirectionalIterator rend(const Container &container)
Definition bidirectionalIterator.h:249
BALL::ConstBidirectionalIterator::toRBegin
void toRBegin()
Definition bidirectionalIterator.h:160
BALL::ConstBidirectionalIterator::toREnd
void toREnd()
Definition bidirectionalIterator.h:168
BALL::ConstBidirectionalIterator::rbegin
static ConstBidirectionalIterator rbegin(const Container &container)
Definition bidirectionalIterator.h:239
BALL::ConstBidirectionalIterator::isBegin
BALL_INLINE bool isBegin() const
Check whether the iterator points to the item at the beginning of the container.
Definition bidirectionalIterator.h:65
BALL::ConstBidirectionalIterator::isREnd
BALL_INLINE bool isREnd() const
Test wheter the iterator points to the position before the first element.
Definition bidirectionalIterator.h:89
BALL::ConstBidirectionalIterator::ConstBidirectionalIterator
BALL_INLINE ConstBidirectionalIterator(const Container &container)
Construct an iterator bound to a specific container.
Definition bidirectionalIterator.h:135
BALL::ConstBidirectionalIterator::operator++
BALL_INLINE ConstBidirectionalIterator & operator++()
Definition bidirectionalIterator.h:177
BALL::ConstBidirectionalIterator::Base
ConstForwardIterator< Container, DataType, Position, Traits > Base
Definition bidirectionalIterator.h:35
BALL::ConstForwardIterator::ConstForwardIterator
BALL_INLINE ConstForwardIterator()
Default constructor.
Definition forwardIterator.h:44
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
BALL_PRECONDITION_EXCEPTION
#define BALL_PRECONDITION_EXCEPTION(condition, message)
Definition debug.h:89
forwardIterator.h
BALL
Definition constants.h:13
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140