astrotypes  0.0
SliceIterator.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 namespace pss {
26 namespace astrotypes {
27 
28 template<typename DerivedType, typename SliceType, bool is_const, int rank>
30  : BaseT(slice)
31  , _slice(slice)
32  , _pos()
33 {
34 }
35 
36 template<typename DerivedType, typename SliceType, bool is_const, int rank>
38 {
39 }
40 
41 template<typename DerivedType, typename SliceType, bool is_const, int rank>
43 {
44  if(!_slice.increment_it(this->_current, _pos)) {
45  this->_current = this->_slice.end()._current;
46  }
47  return static_cast<DerivedType&>(*this);
48 }
49 
50 template<typename DerivedType, typename SliceType, bool is_const, int rank>
52 {
53  return _slice;
54 }
55 
56 template<typename DerivedType, typename SliceType, bool is_const, int rank>
58 {
59  return _slice.diff_it(this->_current - f._current);
60 }
61 
62 template<typename DerivedType, typename SliceType, bool is_const>
64 {
65  DerivedType it(slice);
66  it._current += static_cast<std::size_t>(slice.base_span());
67  return it;
68 }
69 
70 template<typename DerivedType, typename SliceType, bool is_const>
72  : _current(slice.base_ptr())
73 {
74 }
75 
76 template<typename DerivedType, typename SliceType, bool is_const>
78 {
79 }
80 
81 template<typename DerivedType, typename SliceType, bool is_const>
83 {
84  return _current - f._current;
85 }
86 
87 template<typename DerivedType, typename SliceType, bool is_const>
89 {
90  ++_current;
91  return static_cast<DerivedType&>(*this);
92 }
93 
94 template<typename DerivedType, typename SliceType, bool is_const>
96 {
97  DerivedType copy(static_cast<DerivedType&>(*this));
98  ++(*this);
99  return copy;
100 }
101 
102 template<typename DerivedType, typename SliceType, bool is_const>
104 {
105  return *_current;
106 }
107 
108 template<typename DerivedType, typename SliceType, bool is_const>
109 template<typename DataT>
111 {
112  return OverlaySliceIterator<DataT, DerivedType>(obj, static_cast<const DerivedType&>(*this));
113 }
114 
115 template<typename DerivedType, typename SliceType, bool is_const>
116 template<typename D, bool const_val>
118 {
119  return _current == o._current;
120 }
121 
122 template<typename DerivedType, typename SliceType, bool is_const>
123 template<typename D, bool const_val>
125 {
126  return _current != o._current;
127 }
128 
129 template<typename T, std::size_t B, typename SliceType, bool is_const>
131 {
132  static_assert(B == 1 , "not yet implemented");
133  ++static_cast<ActualBaseT&>(*this);
134  return *this;
135 }
136 
137 template<typename T, std::size_t B, typename SliceType, bool is_const>
138 SliceIterator<multiarray::ReducedRankSlice<SliceType, T, B>, is_const>& SliceIterator<multiarray::ReducedRankSlice<SliceType, T, B>, is_const>::operator++(int)
139 {
140  static_assert(B == 1 , "not yet implemented");
141  return static_cast<ActualBaseT&>(*this)++;
142 }
143 
144 template<template<typename, typename...> class Mixin, typename... Ts, typename SliceType, bool is_const>
145 SliceIterator<Mixin<SliceType, Ts...>, is_const>& SliceIterator<Mixin<SliceType, Ts...>, is_const>::operator++()
146 {
147  ++static_cast<ActualBaseT&>(*this);
148  return *this;
149 }
150 
151 template<template<typename, typename...> class Mixin, typename... Ts, typename SliceType, bool is_const>
152 SliceIterator<Mixin<SliceType, Ts...>, is_const>& SliceIterator<Mixin<SliceType, Ts...>, is_const>::operator++(int)
153 {
154  return static_cast<ActualBaseT&>(*this)++;
155 }
156 
157 } // namespace astrotypes
158 } // namespace pss
std::iterator_traits< parent_iterator >::reference reference
Definition: SliceIterator.h:73
difference_type operator-(SelfType const &) const
SliceT const & slice() const
std::conditional< is_const, SliceType const, SliceType >::type SliceT
std::iterator_traits< parent_iterator >::difference_type difference_type
Definition: SliceIterator.h:75
Overlays an iterator from one data structure onto that of another.
bool operator!=(PointerAllocator< FirstType > const &, PointerAllocator< SecondType > const &) noexcept
Allows to test for diversity of PointerAllocator objects.
bool operator==(PointerAllocator< FirstType > const &, PointerAllocator< SecondType > const &) noexcept
Allows to test for equivalence of PointerAllocator objects.
Class to Iterate over a Slice.
Definition: SliceIterator.h:57
std::conditional< is_const, SliceType const, SliceType >::type SliceT
Definition: SliceIterator.h:68