Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataSequence2DFastIterator.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
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 #include <boost/assert.hpp>
25 
26 namespace ska {
27 namespace cheetah {
28 namespace data {
29 
30 template<typename Type, typename DerivedType>
32 {
33 }
34 
35 template<typename Type, typename DerivedType>
37  :_data(nullptr)
38 {
39 }
40 
41 template<typename Type, typename DerivedType>
43  :_data(copy._data)
44  ,_offset(copy._offset)
45  ,_raw(copy._raw)
46 {
47 }
48 
49 template<typename Type, typename DerivedType>
51  DataSequence2D<Cpu,typename std::remove_cv<Type>::type> &data_ptr,
52  std::size_t slow_offset
53  )
54 {
55  this->_data = &data_ptr;
56  this->_raw = data_ptr.data();
57  this->_offset = slow_offset*data_ptr.fast_axis_length();
58 }
59 
60 template<typename Type, typename DerivedType>
62  const DataSequence2D<Cpu,typename std::remove_cv<Type>::type> &data_ptr,
63  std::size_t slow_offset
64  )
65 {
66  this->_data = &data_ptr;
67  this->_raw = data_ptr.data();
68  this->_offset = slow_offset*data_ptr.fast_axis_length();
69 }
70 
71 
72 
73 template<typename Type, typename DerivedType>
74 typename DataSequence2DFastIteratorBase<Type, DerivedType>::PtrType DataSequence2DFastIteratorBase<Type, DerivedType>::operator->() const{
75  BOOST_ASSERT_MSG(this->_raw != nullptr,"Cannot dereference iterator over null DataSequence2D");
76  BOOST_ASSERT_MSG(this->_offset < this->_data->fast_axis_length()*this->_data->slow_axis_length(),"Cannot dereference post-end iterator");
77  return this->_raw+this->_offset;
78 }
79 
80 template<typename Type, typename DerivedType>
81 typename DataSequence2DFastIteratorBase<Type, DerivedType>::RefType DataSequence2DFastIteratorBase<Type, DerivedType>::operator*() const{
82  BOOST_ASSERT_MSG(this->_raw != nullptr,"Cannot dereference iterator over null DataSequence2D");
83  BOOST_ASSERT_MSG(this->_offset < this->_data->fast_axis_length()*this->_data->slow_axis_length(),"Cannot dereference post-end iterator");
84  return *(this->_raw+this->_offset);
85 }
86 
87 template<typename Type, typename DerivedType>
89  ++(this->_offset);
90  return static_cast<DerivedType&>(*this);
91 }
92 
93 
94 template<typename Type, typename DerivedType>
96  DerivedType r(static_cast<DerivedType const&>(*this));
97  ++(this->_offset);
98  return r;
99 }
100 
101 template<typename Type, typename DerivedType>
103  --(this->_offset);
104  return *this;
105 }
106 
107 template<typename Type, typename DerivedType>
109  DerivedType r(static_cast<DerivedType const&>(*this));
110  --(this->_offset);
111  return r;
112 }
113 
114 template<typename Type, typename DerivedType>
115 DerivedType& DataSequence2DFastIteratorBase<Type, DerivedType>::operator+=(typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType off){
116  this->_offset += off;
117  return static_cast<DerivedType&>(*this);
118 }
119 
120 template<typename Type, typename DerivedType>
121 DerivedType& DataSequence2DFastIteratorBase<Type, DerivedType>::operator-=(typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType off){
122  this->_offset -= off;
123  return static_cast<DerivedType&>(*this);
124 }
125 
126 template<typename Type, typename DerivedType>
127 DerivedType DataSequence2DFastIteratorBase<Type, DerivedType>::operator+(typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType off) const
128 {
129  DerivedType r(static_cast<DerivedType const&>(*this));
130  r._offset += off;
131  return r;
132 }
133 
134 template<typename Type, typename DerivedType>
135 DerivedType DataSequence2DFastIteratorBase<Type, DerivedType>::operator-(typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType off) const
136 {
137  DerivedType r(static_cast<DerivedType const&>(*this));
138  r._offset -= off;
139  return r;
140 }
141 
142 template<typename Type, typename DerivedType>
143 typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType DataSequence2DFastIteratorBase<Type, DerivedType>::operator-(const DataSequence2DFastIteratorBase<Type, DerivedType> &right) const
144 {
145  return this->_offset - right._offset;
146 }
147 
148 template<typename Type, typename DerivedType>
150 {
151  return this->_offset < right._offset;
152 }
153 
154 template<typename Type, typename DerivedType>
156 {
157  return this->_offset > right._offset;
158 }
159 
160 template<typename Type, typename DerivedType>
162 {
163  return this->_offset <= right._offset;
164 }
165 
166 template<typename Type, typename DerivedType>
168  return (this->_data==right._data) && (this->_offset >= right._offset);
169 }
170 
171 template<typename Type, typename DerivedType>
172 typename DataSequence2DFastIteratorBase<Type, DerivedType>::RefType DataSequence2DFastIteratorBase<Type, DerivedType>::operator[](typename DataSequence2DFastIteratorBase<Type, DerivedType>::DiffType off) const {
173  return *((*this)+off);
174 }
175 
176 template<typename Type, typename DerivedType>
178 {
179  return (it._data == _data) && (it._offset == _offset);
180 }
181 
182 template<typename Type, typename DerivedType>
184 {
185  return (it._data == _data) && (it._offset != _offset);
186 }
187 
188 template<typename Type, typename DerivedType>
190  return it1.operator==(it2);
191 }
192 
193 template<typename Type, typename DerivedType>
195  return it1.operator!=(it2);
196 }
197 
198 
199 } // namespace data
200 } // namespace cheetah
201 } // namespace ska
202 
Iterator over DataSequence2D types, over "fast" axis. CPU specific type.
Some limits and constants for FLDO.
Definition: Brdz.h:35
A 2-dimensional sequencial data of type T.
DataSequence2DFastIteratorBase()
default constructor. Required by random_access_iterator_tag