STIR 6.4.0
NestedIterator.h
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2000 PARAPET partners
5 Copyright (C) 2000- 2011, Hammersmith Imanet Ltd
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
9
10 See STIR/LICENSE.txt for details
11*/
12#ifndef __stir_NestedIterator__H__
13#define __stir_NestedIterator__H__
14
26
28#include "boost/iterator/iterator_traits.hpp"
29
30START_NAMESPACE_STIR
31
92template <typename topleveliterT, class GetRestRangeFunctionT = BeginEndFunction<topleveliterT>>
93class NestedIterator
94{
95private:
96 typedef typename GetRestRangeFunctionT::rest_iter_type rest_iter_type;
97
98public:
99 typedef std::forward_iterator_tag iterator_category;
100 typedef typename boost::iterator_difference<rest_iter_type>::type difference_type;
101 typedef typename boost::iterator_value<rest_iter_type>::type value_type;
102 typedef typename boost::iterator_reference<rest_iter_type>::type reference;
103 typedef typename boost::iterator_pointer<rest_iter_type>::type pointer;
104
105public:
108
110 inline NestedIterator(const topleveliterT& top_level_iter, const topleveliterT& end_top_level_iter);
111
113
116 template <typename othertopleveliterT, typename otherGetRestRangeFunctionT>
118 NestedIterator<othertopleveliterT, otherGetRestRangeFunctionT> other,
119 typename boost::enable_if_convertible<othertopleveliterT, topleveliterT>::type* = 0,
120 typename boost::enable_if_convertible<typename otherGetRestRangeFunctionT::rest_iter_type, rest_iter_type>::type* = 0)
121 : _current_top_level_iter(other._current_top_level_iter),
122 _end_top_level_iter(other._end_top_level_iter),
123 _current_rest_iter(other._current_rest_iter),
124 _end_rest_iter(other._end_rest_iter)
125 {}
126
127 // inline NestedIterator& operator=(const NestedIterator&);
128
130 inline NestedIterator& operator++();
131
133 inline NestedIterator operator++(int);
134
136 inline bool operator==(const NestedIterator&) const;
138 inline bool operator!=(const NestedIterator&) const;
139
141 inline reference operator*() const;
142
144 inline pointer operator->() const;
145
146#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
147public:
148#else
149private:
150 // needed for conversion constructor
151 template <class, class>
152 friend class NestedIterator;
153#endif
154
156 topleveliterT _current_top_level_iter;
157
159 topleveliterT _end_top_level_iter;
160
162 rest_iter_type _current_rest_iter;
163
165 rest_iter_type _end_rest_iter;
166
167private:
169 void _set_rest_iters_for_current_top_level_iter();
170};
171
172END_NAMESPACE_STIR
173
175
176#endif
This file defines supporting function objects for stir::NestedIterator.
inline implementations for stir::NestedIterator.
NestedIterator & operator++()
prefix increment
Definition NestedIterator.inl:98
bool operator==(const NestedIterator &) const
test equality
Definition NestedIterator.inl:66
bool operator!=(const NestedIterator &) const
test equality
Definition NestedIterator.inl:90
NestedIterator operator++(int)
postfix increment
Definition NestedIterator.inl:114
NestedIterator(const topleveliterT &top_level_iter, const topleveliterT &end_top_level_iter)
constructor to initialise the members
Definition NestedIterator.inl:56
reference operator*() const
dereferencing operator
Definition NestedIterator.inl:123
NestedIterator(NestedIterator< othertopleveliterT, otherGetRestRangeFunctionT > other, typename boost::enable_if_convertible< othertopleveliterT, topleveliterT >::type *=0, typename boost::enable_if_convertible< typename otherGetRestRangeFunctionT::rest_iter_type, rest_iter_type >::type *=0)
constructor to convert between nested iterators using convertible top and next level iterators
Definition NestedIterator.h:117
pointer operator->() const
member-selection operator
Definition NestedIterator.inl:130
NestedIterator()
default constructor
Definition NestedIterator.inl:27