All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Static Private Member Functions | List of all members
proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType > Class Template Reference

Simple iterator wrapper for manipulation of dereferenced result. More...

#include <AssociatedData.h>

Inheritance diagram for proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >:

Classes

class  ValuePtr
 Value box for use with pointer dereference operator->(). More...
 

Public Types

using iterator = Iter
 
Iterator traits

!< The type of base iterator wrapper.

using value_type = ValueType
 
using pointer = std::add_pointer_t< value_type >
 
using reference = std::add_lvalue_reference_t< value_type >
 
using iterator_category = std::forward_iterator_tag
 

Public Member Functions

 IteratorWrapperBase ()=default
 Default constructor: default-constructs the underlying iterator. More...
 
 IteratorWrapperBase (data_iterator_t const &from)
 Copy-from-base constructor. More...
 
iteratoroperator++ ()
 Prefix increment operator. More...
 
bool operator!= (data_iterator_t const &other) const
 Comparison with a data iterator (makes unnecessary to wrap end iterators). More...
 
bool operator!= (iterator const &other) const
 Comparison with another iterator. More...
 
auto operator[] (std::size_t index) const -> decltype(auto)
 
auto operator* () const -> decltype(auto)
 Dereference operator; need to be redefined by derived classes. More...
 
auto operator-> () const -> decltype(auto)
 Dereference operator; need to be redefined by derived classes. More...
 

Protected Types

using data_iterator_t = DataIter
 

Protected Member Functions

data_iterator_t const & asDataIterator () const
 

Static Protected Member Functions

static auto transform (data_iterator_t const &) -> decltype(auto)
 Transforms and returns the value at the specified data iterator. More...
 

Private Member Functions

iterator const & asIterator () const
 
iteratorasIterator ()
 

Static Private Member Functions

template<typename Value >
static ValuePtr< Value > makeValuePointer (Value &&value)
 

Detailed Description

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
class proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >

Simple iterator wrapper for manipulation of dereferenced result.

Template Parameters
Iterfinal iterator
BaseIterbase iterator
ValueTypetype returned by the new dereference operator

This class is designed to be used as base class for an iterator that redefines the dereference operations without changing anything else. An example of such iterator is:

using int_iterator_t = std::vector<int>::const_iterator;
class twice_iterator
: public IteratorWrapperBase<twice_iterator, int_iterator_t, float>
{
using base_iterator_t
= IteratorWrapperBase<twice_iterator, int_iterator_t, float>;
public:
using base_iterator_t::base_iterator_t; // inherit constructors
float operator*() const -> decltype(auto)
{ return 2.0F * base_iterator_t::operator*(); }
}; // twice_iterator

This new iterator twice_iterator effectively inherits int_iterator_t constructors (via base_iterator_t). Its operator++() returns a twice_iterator, so that operations like *++it are correctly handled.

Note that the derived classes need to redefine all the dereferencing operators that are supported:

The operator->() is not supported. Typically, operator*() returns a reference and operator->() a pointer to an existing structure. The operator*() is not required to return a reference when the iterator does not allow to modify the pointed data, and the wrapper can manipulate values and return temporary results. To have a similar feature for operator->() requires more work, as it should return a smart pointer that would perform the transformation on dereference.

Definition at line 103 of file AssociatedData.h.

Member Typedef Documentation

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::data_iterator_t = DataIter
protected

Definition at line 105 of file AssociatedData.h.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::iterator = Iter

Definition at line 108 of file AssociatedData.h.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::iterator_category = std::forward_iterator_tag

Definition at line 116 of file AssociatedData.h.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::pointer = std::add_pointer_t<value_type>

Definition at line 114 of file AssociatedData.h.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::reference = std::add_lvalue_reference_t<value_type>

Definition at line 115 of file AssociatedData.h.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
using proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::value_type = ValueType

Definition at line 113 of file AssociatedData.h.

Constructor & Destructor Documentation

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::IteratorWrapperBase ( )
default

Default constructor: default-constructs the underlying iterator.

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::IteratorWrapperBase ( data_iterator_t const &  from)
inline

Copy-from-base constructor.

Definition at line 123 of file AssociatedData.h.

Member Function Documentation

template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
data_iterator_t const& proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::asDataIterator ( ) const
inlineprotected

Definition at line 154 of file AssociatedData.h.

155  { return static_cast<data_iterator_t const&>(*this); }
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
iterator const& proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::asIterator ( ) const
inlineprivate

Definition at line 172 of file AssociatedData.h.

173  { return static_cast<iterator const&>(*this); }
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
iterator& proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::asIterator ( )
inlineprivate

Definition at line 174 of file AssociatedData.h.

174 { return static_cast<iterator&>(*this); }
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
template<typename Value >
static ValuePtr<Value> proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::makeValuePointer ( Value &&  value)
inlinestaticprivate

Definition at line 169 of file AssociatedData.h.

170  { return { std::forward<Value>(value) }; }
temporary value
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
bool proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator!= ( data_iterator_t const &  other) const
inline

Comparison with a data iterator (makes unnecessary to wrap end iterators).

Definition at line 130 of file AssociatedData.h.

131  { return other != asDataIterator(); }
data_iterator_t const & asDataIterator() const
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
bool proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator!= ( iterator const &  other) const
inline

Comparison with another iterator.

Definition at line 134 of file AssociatedData.h.

135  { return operator!=(other.asDataIterator()); }
bool operator!=(data_iterator_t const &other) const
Comparison with a data iterator (makes unnecessary to wrap end iterators).
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
auto proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator* ( ) const -> decltype(auto)
inline

Dereference operator; need to be redefined by derived classes.

Definition at line 141 of file AssociatedData.h.

142  { return asIterator().transform(asDataIterator()); }
data_iterator_t const & asDataIterator() const
iterator const & asIterator() const
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
iterator& proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator++ ( )
inline

Prefix increment operator.

Definition at line 126 of file AssociatedData.h.

127  { data_iterator_t::operator++(); return asIterator(); }
iterator const & asIterator() const
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
auto proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator-> ( ) const -> decltype(auto)
inline

Dereference operator; need to be redefined by derived classes.

Definition at line 145 of file AssociatedData.h.

146  { return makeValuePointer(operator*()); }
static ValuePtr< Value > makeValuePointer(Value &&value)
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
auto proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::operator[] ( std::size_t  index) const -> decltype(auto)
inline

Definition at line 137 of file AssociatedData.h.

138  { return asIterator().transform(asDataIterator() + index); }
data_iterator_t const & asDataIterator() const
iterator const & asIterator() const
template<typename Iter, typename DataIter, typename ValueType = typename DataIter::value_type>
static auto proxy::details::IteratorWrapperBase< Iter, DataIter, ValueType >::transform ( data_iterator_t const &  ) -> decltype(auto)
inlinestaticprotected

Transforms and returns the value at the specified data iterator.

Definition at line 151 of file AssociatedData.h.

152  { return data_iterator_t::operator*(); }
QuadExpr operator*(double v, const QuadExpr &e)
Definition: QuadExpr.h:39

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