Public Types | Public Member Functions | Private Attributes | List of all members
WireCell::IteratorAdapter< adapted_iterator, base_iterator > Class Template Reference

#include <IteratorBase.h>

Inheritance diagram for WireCell::IteratorAdapter< adapted_iterator, base_iterator >:
base_iterator< Value >

Public Types

typedef base_iterator::value_type value_type
 
- Public Types inherited from base_iterator< Value >
using difference_type = typename traits_t::difference_type
 
using value_type = typename traits_t::value_type
 
using pointer = typename traits_t::pointer
 
using reference = typename traits_t::reference
 
using iterator_category = typename traits_t::iterator_category
 

Public Member Functions

 IteratorAdapter (adapted_iterator it)
 
virtual ~IteratorAdapter ()
 
const IteratorAdapterdc (const base_iterator &other) const
 
bool operator== (const base_iterator &rhs) const
 
bool operator!= (const base_iterator &rhs) const
 
base_iteratoroperator= (const base_iterator &rhs)
 
base_iteratoroperator++ ()
 
value_type operator* () const
 
base_iteratorclone () const
 
- Public Member Functions inherited from base_iterator< Value >
 base_iterator (pointer ptr=nullptr)
 
reference operator* () const
 
pointer operator-> () const
 
base_iteratoroperator++ ()
 
base_iteratoroperator-- ()
 
reference operator[] (difference_type offset) const
 
difference_type operator- (base_iterator const &other) const
 

Private Attributes

adapted_iterator m_it
 

Additional Inherited Members

- Public Attributes inherited from base_iterator< Value >
pointer ptr = nullptr
 

Detailed Description

template<typename adapted_iterator, typename base_iterator>
class WireCell::IteratorAdapter< adapted_iterator, base_iterator >

Handy adapter from an iterator to an abstract base iterator.

Eg:

class MyData : virtual public IData {...}; typedef IteratorBase< const IData* > my_base_iterator; typedef std::vector<MyData*> MyStore; typedef IteratorAdapter< MyStore::iterator, my_base_iterator > my_iterator;

typedef std::Iterator<const IMyData*> data_iterator; typedef std::pair<data_iterator, data_iterator> data_range;

In interface class:

data_range get_data() const = 0;

In implementation with

MyStore m_store;

data_range MyImp::get_data() { return data_range(my_iterator(m_store.begin(), my_iterator(m_store.end())); }

Reasons not to use this adapter and go to the trouble to write your own iterator class:

Definition at line 72 of file IteratorBase.h.

Member Typedef Documentation

template<typename adapted_iterator , typename base_iterator >
typedef base_iterator::value_type WireCell::IteratorAdapter< adapted_iterator, base_iterator >::value_type

Definition at line 76 of file IteratorBase.h.

Constructor & Destructor Documentation

template<typename adapted_iterator , typename base_iterator >
WireCell::IteratorAdapter< adapted_iterator, base_iterator >::IteratorAdapter ( adapted_iterator  it)
inline

Definition at line 78 of file IteratorBase.h.

78 : m_it(it) {}
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
virtual WireCell::IteratorAdapter< adapted_iterator, base_iterator >::~IteratorAdapter ( )
inlinevirtual

Definition at line 79 of file IteratorBase.h.

79 {}

Member Function Documentation

template<typename adapted_iterator , typename base_iterator >
base_iterator* WireCell::IteratorAdapter< adapted_iterator, base_iterator >::clone ( ) const
inline

Definition at line 102 of file IteratorBase.h.

102  {
103  return new IteratorAdapter(m_it);
104  }
IteratorAdapter(adapted_iterator it)
Definition: IteratorBase.h:78
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
const IteratorAdapter& WireCell::IteratorAdapter< adapted_iterator, base_iterator >::dc ( const base_iterator other) const
inline

Definition at line 81 of file IteratorBase.h.

81  {
82  return *dynamic_cast<const IteratorAdapter*>(&other); // segfault on type mismatch
83  }
IteratorAdapter(adapted_iterator it)
Definition: IteratorBase.h:78
template<typename adapted_iterator , typename base_iterator >
bool WireCell::IteratorAdapter< adapted_iterator, base_iterator >::operator!= ( const base_iterator rhs) const
inline

Definition at line 87 of file IteratorBase.h.

87  {
88  return m_it != dc(rhs).m_it;
89  }
const IteratorAdapter & dc(const base_iterator &other) const
Definition: IteratorBase.h:81
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
value_type WireCell::IteratorAdapter< adapted_iterator, base_iterator >::operator* ( ) const
inline

Definition at line 98 of file IteratorBase.h.

98  {
99  return *m_it;
100  }
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
base_iterator& WireCell::IteratorAdapter< adapted_iterator, base_iterator >::operator++ ( )
inline

Definition at line 94 of file IteratorBase.h.

94  {
95  ++m_it;
96  return *this;
97  }
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
base_iterator& WireCell::IteratorAdapter< adapted_iterator, base_iterator >::operator= ( const base_iterator rhs)
inline

Definition at line 90 of file IteratorBase.h.

90  {
91  m_it = dc(rhs).m_it;
92  return *this;
93  }
const IteratorAdapter & dc(const base_iterator &other) const
Definition: IteratorBase.h:81
adapted_iterator m_it
Definition: IteratorBase.h:106
template<typename adapted_iterator , typename base_iterator >
bool WireCell::IteratorAdapter< adapted_iterator, base_iterator >::operator== ( const base_iterator rhs) const
inline

Definition at line 84 of file IteratorBase.h.

84  {
85  return m_it == dc(rhs).m_it;
86  }
const IteratorAdapter & dc(const base_iterator &other) const
Definition: IteratorBase.h:81
adapted_iterator m_it
Definition: IteratorBase.h:106

Member Data Documentation

template<typename adapted_iterator , typename base_iterator >
adapted_iterator WireCell::IteratorAdapter< adapted_iterator, base_iterator >::m_it
private

Definition at line 106 of file IteratorBase.h.


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