Loading...
Searching...
No Matches
genericiterator.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_GENERICITERATOR_HH
#define DUNE_GENERICITERATOR_HH
#include <dune/common/iteratorfacades.hh>
#include <cassert>
namespace Dune {
template<class R>
struct const_reference
{
typedef const R type;
};
template<class R>
struct const_reference<const R>
{
typedef const R type;
};
template<class R>
struct const_reference<R&>
{
typedef const R& type;
};
template<class R>
struct const_reference<const R&>
{
typedef const R& type;
};
template<class R>
struct mutable_reference
{
typedef R type;
};
template<class R>
struct mutable_reference<const R>
{
typedef R type;
};
template<class R>
struct mutable_reference<R&>
{
typedef R& type;
};
template<class R>
struct mutable_reference<const R&>
{
typedef R& type;
};
template<class C, class T, class R=T&, class D = std::ptrdiff_t,
template<class,class,class,class> class IteratorFacade=RandomAccessIteratorFacade>
class GenericIterator :
public IteratorFacade<GenericIterator<C,T,R,D,IteratorFacade>,T,R,D>
{
friend class GenericIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type, D, IteratorFacade>;
friend class GenericIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type, D, IteratorFacade>;
typedef GenericIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type, D, IteratorFacade> MutableIterator;
typedef GenericIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type, D, IteratorFacade> ConstIterator;
public:
typedef C Container;
typedef T Value;
typedef D DifferenceType;
typedef R Reference;
// Constructors needed by the base iterators
GenericIterator() : container_(0), position_(0)
{}
GenericIterator(Container& cont, DifferenceType pos)
: container_(&cont), position_(pos)
{}
GenericIterator(const MutableIterator& other) : container_(other.container_), position_(other.position_)
{}
GenericIterator(const ConstIterator& other) : container_(other.container_), position_(other.position_)
{}
// Methods needed by the forward iterator
bool equals(const MutableIterator & other) const
{
return position_ == other.position_ && container_ == other.container_;
}
bool equals(const ConstIterator & other) const
{
return position_ == other.position_ && container_ == other.container_;
}
Reference dereference() const {
return container_->operator[](position_);
}
void increment(){
++position_;
}
// Additional function needed by BidirectionalIterator
void decrement(){
--position_;
}
// Additional function needed by RandomAccessIterator
Reference elementAt(DifferenceType i) const {
return container_->operator[](position_+i);
}
void advance(DifferenceType n){
position_=position_+n;
}
DifferenceType distanceTo(const MutableIterator& other) const
{
assert(other.container_==container_);
return other.position_ - position_;
}
DifferenceType distanceTo(const ConstIterator& other) const
{
assert(other.container_==container_);
return other.position_ - position_;
}
private:
Container *container_;
DifferenceType position_;
};
} // end namespace Dune
#endif
iteratorfacades.hh
This file implements iterator facade classes for writing stl conformant iterators.
std
STL namespace.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::const_reference
Get the 'const' version of a reference to a mutable object.
Definition genericiterator.hh:87
Dune::const_reference::type
const R type
Definition genericiterator.hh:88
Dune::const_reference< const R >::type
const R type
Definition genericiterator.hh:94
Dune::const_reference< R & >::type
const R & type
Definition genericiterator.hh:100
Dune::const_reference< const R & >::type
const R & type
Definition genericiterator.hh:106
Dune::mutable_reference
get the 'mutable' version of a reference to a const object
Definition genericiterator.hh:116
Dune::mutable_reference::type
R type
Definition genericiterator.hh:117
Dune::mutable_reference< const R >::type
R type
Definition genericiterator.hh:123
Dune::mutable_reference< R & >::type
R & type
Definition genericiterator.hh:129
Dune::GenericIterator::GenericIterator
GenericIterator(const MutableIterator &other)
Copy constructor.
Definition genericiterator.hh:211
Dune::GenericIterator::equals
bool equals(const MutableIterator &other) const
Definition genericiterator.hh:227
Dune::GenericIterator::elementAt
Reference elementAt(DifferenceType i) const
Definition genericiterator.hh:251
Dune::GenericIterator::increment
void increment()
Definition genericiterator.hh:241
Dune::GenericIterator::GenericIterator
GenericIterator(const ConstIterator &other)
Copy constructor.
Definition genericiterator.hh:223
Dune::GenericIterator::advance
void advance(DifferenceType n)
Definition genericiterator.hh:255
Dune::GenericIterator::GenericIterator
GenericIterator(Container &cont, DifferenceType pos)
Constructor.
Definition genericiterator.hh:200
Dune::GenericIterator< BitSetVector< block_size, Allocator >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade >::DifferenceType
std::ptrdiff_t DifferenceType
Definition genericiterator.hh:182
Dune::GenericIterator< BitSetVector< block_size, Allocator >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade >::Reference
reference Reference
Definition genericiterator.hh:187
Dune::GenericIterator::distanceTo
DifferenceType distanceTo(const MutableIterator &other) const
Definition genericiterator.hh:259
Dune::GenericIterator< BitSetVector< block_size, Allocator >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade >::Container
BitSetVector< block_size, Allocator > Container
Definition genericiterator.hh:170
Dune::GenericIterator< BitSetVector< block_size, Allocator >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade >::Value
value_type Value
Definition genericiterator.hh:177
Dune::GenericIterator::distanceTo
DifferenceType distanceTo(const ConstIterator &other) const
Definition genericiterator.hh:265
Dune::GenericIterator::decrement
void decrement()
Definition genericiterator.hh:246
Dune::GenericIterator::GenericIterator
GenericIterator()
Definition genericiterator.hh:190
Dune::GenericIterator::dereference
Reference dereference() const
Definition genericiterator.hh:237
Dune::GenericIterator::equals
bool equals(const ConstIterator &other) const
Definition genericiterator.hh:232
Dune::RandomAccessIteratorFacade
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:435
Dune::type