STIR 6.4.0
NestedIteratorHelpers.h
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2006- 2011, Hammersmith Imanet Ltd
5 This file is part of STIR.
6
7 SPDX-License-Identifier: Apache-2.0
8
9 See STIR/LICENSE.txt for details
10*/
11#ifndef __stir_NestedIteratorHelpers__H__
12#define __stir_NestedIteratorHelpers__H__
13
23
24#include "stir/common.h"
25#include "boost/iterator/iterator_traits.hpp"
26#include "boost/pointee.hpp"
27
28START_NAMESPACE_STIR
29
34#if 0
35// This is the original implementation, which works but contains a lot of code repetition.
36// It's superseded by the implementation below, but that might need a recent compiler, so
37// I've kept this old version in the file for now, but it is disabled.
38template <class TopLevelIterT>
39class BeginEndFunction
40{
41 typedef typename boost::iterator_value<TopLevelIterT>::type iter_value_type;
42 public:
43 typedef typename iter_value_type::iterator rest_iter_type;
44
45 rest_iter_type begin(const TopLevelIterT& iter) const
46 { return iter->begin(); }
47 rest_iter_type end(const TopLevelIterT& iter) const
48 { return iter->end(); }
49};
50
51template <class TopLevelIterT>
52class ConstBeginEndFunction
53{
54 typedef typename boost::iterator_value<TopLevelIterT>::type iter_value_type;
55 public:
56 typedef typename iter_value_type::const_iterator rest_iter_type;
57
58 rest_iter_type begin(const TopLevelIterT& iter) const
59 { return iter->begin(); }
60 rest_iter_type end(const TopLevelIterT& iter) const
61 { return iter->end(); }
62};
63
64template <class TopLevelIterT>
65class BeginEndAllFunction
66{
67 typedef typename boost::iterator_value<TopLevelIterT>::type iter_value_type;
68 public:
69 typedef typename iter_value_type::full_iterator rest_iter_type;
70
71 rest_iter_type begin(const TopLevelIterT& iter) const
72 { return iter->begin_all(); }
73 rest_iter_type end(const TopLevelIterT& iter) const
74 { return iter->end_all(); }
75};
76
77template <class TopLevelIterT>
78class ConstBeginEndAllFunction
79{
80 typedef typename boost::iterator_value<TopLevelIterT>::type iter_value_type;
81 public:
82 typedef typename iter_value_type::const_full_iterator rest_iter_type;
83
84 rest_iter_type begin(const TopLevelIterT& iter) const
85 { return iter->begin_all_const(); }
86 rest_iter_type end(const TopLevelIterT& iter) const
87 { return iter->end_all_const(); }
88};
89
90template <class TopLevelIterT>
91class PtrBeginEndFunction
92{
93 typedef typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type iter_value_type;
94 public:
95 typedef typename iter_value_type::iterator rest_iter_type;
96
97 rest_iter_type begin(const TopLevelIterT& iter) const
98 { return (**iter).begin(); }
99 rest_iter_type end(const TopLevelIterT& iter) const
100 { return (**iter).end(); }
101};
102
103template <class TopLevelIterT>
104class ConstPtrBeginEndFunction
105{
106 typedef typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type iter_value_type;
107 public:
108 typedef typename iter_value_type::const_iterator rest_iter_type;
109
110 rest_iter_type begin(const TopLevelIterT& iter) const
111 { return (**iter).begin(); }
112 rest_iter_type end(const TopLevelIterT& iter) const
113 { return (**iter).end(); }
114};
115
116template <class TopLevelIterT>
117class PtrBeginEndAllFunction
118{
119 typedef typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type iter_value_type;
120 public:
121 typedef typename iter_value_type::full_iterator rest_iter_type;
122
123 rest_iter_type begin(const TopLevelIterT& iter) const
124 { return (**iter).begin_all(); }
125 rest_iter_type end(const TopLevelIterT& iter) const
126 { return (**iter).end_all(); }
127};
128
129template <class TopLevelIterT>
130class ConstPtrBeginEndAllFunction
131{
132 typedef typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type iter_value_type;
133 public:
134 typedef typename iter_value_type::const_full_iterator rest_iter_type;
135
136 rest_iter_type begin(const TopLevelIterT& iter) const
137 { return (**iter).begin_all_const(); }
138 rest_iter_type end(const TopLevelIterT& iter) const
139 { return (**iter).end_all_const(); }
140};
141
142#else
143
144// new implementation
145
147
156template <class TopLevelIterT, class RestIterT = typename boost::iterator_value<TopLevelIterT>::type::iterator>
158{
159public:
161 typedef RestIterT rest_iter_type;
163
164 inline RestIterT begin(const TopLevelIterT& iter) const { return iter->begin(); }
166 inline RestIterT end(const TopLevelIterT& iter) const { return iter->end(); }
167};
168
171
182template <class TopLevelIterT,
183 class RestIterT = typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type::iterator>
185{
186public:
187 typedef RestIterT rest_iter_type;
189
190 inline RestIterT begin(const TopLevelIterT& iter) const { return (**iter).begin(); }
192 inline RestIterT end(const TopLevelIterT& iter) const { return (**iter).end(); }
193};
194
196
207template <class TopLevelIterT, class RestIterT = typename boost::iterator_value<TopLevelIterT>::type::full_iterator>
209{
210public:
211 typedef RestIterT rest_iter_type;
212 inline RestIterT begin(const TopLevelIterT& iter) const { return iter->begin_all(); }
213 inline RestIterT end(const TopLevelIterT& iter) const { return iter->end_all(); }
214};
215
218
229template <class TopLevelIterT,
230 class RestIterT = typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type::full_iterator>
232{
233public:
234 typedef RestIterT rest_iter_type;
235 inline RestIterT begin(const TopLevelIterT& iter) const { return (**iter).begin_all(); }
236 inline RestIterT end(const TopLevelIterT& iter) const { return (**iter).end_all(); }
237};
238
240
241template <class TopLevelIterT, class RestIterT = typename boost::iterator_value<TopLevelIterT>::type::const_iterator>
242class ConstBeginEndFunction : public BeginEndFunction<TopLevelIterT, RestIterT>
243{
244};
245
247
248template <class TopLevelIterT, class RestIterT = typename boost::iterator_value<TopLevelIterT>::type::const_full_iterator>
249class ConstBeginEndAllFunction : public BeginEndAllFunction<TopLevelIterT, RestIterT>
250{
251};
252
254
255template <class TopLevelIterT>
257 : public PtrBeginEndFunction<
258 TopLevelIterT,
259 typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type::const_iterator>
260{
261};
262
264template <class TopLevelIterT>
266 : public PtrBeginEndAllFunction<
267 TopLevelIterT,
268 typename boost::pointee<typename boost::iterator_value<TopLevelIterT>::type>::type::const_full_iterator>
269{
270};
271
272#endif // #if between old and new implementation
273
275
276END_NAMESPACE_STIR
277
278#endif
Helper class for NestedIterator when the 1st level iterator refers to a stir full iterator for the 2n...
Definition NestedIteratorHelpers.h:209
Helper class for NestedIterator when the 1st level iterator refers to an ordinary iterator for the 2n...
Definition NestedIteratorHelpers.h:158
RestIterT end(const TopLevelIterT &iter) const
function to get the "end" 2nd level iterator for a top-level iterator
Definition NestedIteratorHelpers.h:166
RestIterT begin(const TopLevelIterT &iter) const
function to get the first 2nd level iterator for a top-level iterator
Definition NestedIteratorHelpers.h:164
RestIterT rest_iter_type
typedef storing the type of the 2nd level iterator
Definition NestedIteratorHelpers.h:161
Convenience class where the 2nd level iterator is a const_full_iterator.
Definition NestedIteratorHelpers.h:250
Convenience class where the 2nd level iterator is a const_iterator.
Definition NestedIteratorHelpers.h:243
Convenience class where the 2nd level iterator is a const_full_iterator.
Definition NestedIteratorHelpers.h:269
Convenience class where the 2nd level iterator is a const_iterator.
Definition NestedIteratorHelpers.h:260
Helper class for NestedIterator when the 1st level iterator refers to a pointer to a stir full iterat...
Definition NestedIteratorHelpers.h:232
Helper class for NestedIterator when the 1st level iterator refers to pointers to an ordinary iterato...
Definition NestedIteratorHelpers.h:185
RestIterT end(const TopLevelIterT &iter) const
function to get the "end" 2nd level iterator for a top-level iterator
Definition NestedIteratorHelpers.h:192
RestIterT begin(const TopLevelIterT &iter) const
function to get the first 2nd level iterator for a top-level iterator
Definition NestedIteratorHelpers.h:190
basic configuration include file