LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
NestedIterator.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef NDARRAY_DETAIL_NestedIterator_h_INCLUDED
24 #define NDARRAY_DETAIL_NestedIterator_h_INCLUDED
25 
32 #include <boost/iterator/iterator_facade.hpp>
33 #include "ndarray_fwd.h"
34 
35 namespace ndarray {
36 namespace detail {
37 
51 template <typename T, int N, int C>
52 class NestedIterator : public boost::iterator_facade<
53  NestedIterator<T,N,C>,
54  typename ArrayTraits<T,N,C>::Value,
55  boost::random_access_traversal_tag,
56  typename ArrayTraits<T,N,C>::Reference
57  >
58 {
59 public:
60  typedef typename ArrayTraits<T,N,C>::Value Value;
62 
63  Reference operator[](int n) const {
64  Reference r(_ref);
65  r._data += n * _stride;
66  return r;
67  }
68 
69  Reference const & operator*() const { return _ref; }
70 
71  Reference const * operator->() { return &_ref; }
72 
74 
75  NestedIterator(Reference const & ref, int stride) : _ref(ref), _stride(stride) {}
76 
77  NestedIterator(NestedIterator const & other) : _ref(other._ref), _stride(other._stride) {}
78 
79  template <typename T_, int C_>
80  NestedIterator(NestedIterator<T_,N,C_> const & other) : _ref(other._ref), _stride(other._stride) {}
81 
83  if (&other != this) {
84  _ref._data = other._ref._data;
85  _ref._core = other._ref._core;
86  _stride = other._stride;
87  }
88  return *this;
89  }
90 
91  template <typename T_, int C_>
93  _ref._data = other._ref._data;
94  _ref._core = other._ref._core;
95  _stride = other._stride;
96  return *this;
97  }
98 
99 private:
100 
102 
103  template <typename T_, int N_, int C_> friend class NestedIterator;
104 
105  Reference const & dereference() const { return _ref; }
106 
107  void increment() { _ref._data += _stride; }
108  void decrement() { _ref._data -= _stride; }
109  void advance(int n) { _ref._data += _stride * n; }
110 
111  template <typename T_, int C_>
112  int distance_to(NestedIterator<T_,N,C_> const & other) const {
113  return std::distance(_ref._data, other._ref._data) / _stride;
114  }
115 
116  template <typename T_, int C_>
117  bool equal(NestedIterator<T_,N,C_> const & other) const {
118  return _ref._data == other._ref._data;
119  }
120 
122  int _stride;
123 };
124 
125 } // namespace detail
126 } // namespace ndarray
127 
128 #endif // !NDARRAY_DETAIL_NestedIterator_h_INCLUDED
A proxy class for Array with deep assignment operators.
Definition: ArrayRef.h:46
bool equal(NestedIterator< T_, N, C_ > const &other) const
Reference operator[](int n) const
Element * _data
Definition: ArrayBase.h:227
int distance_to(NestedIterator< T_, N, C_ > const &other) const
Reference const & operator*() const
Forward declarations and default template parameters for ndarray.
NestedIterator & operator=(NestedIterator< T_, N, C_ > const &other)
ArrayTraits< T, N, C >::Reference Reference
NestedIterator & operator=(NestedIterator const &other)
ArrayTraits< T, N, C >::Value Value
NestedIterator(NestedIterator< T_, N, C_ > const &other)
A multidimensional strided array.
Definition: Array.h:47
friend class boost::iterator_core_access
NestedIterator(Reference const &ref, int stride)
Reference const * operator->()
Reference const & dereference() const
NestedIterator(NestedIterator const &other)