Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataSequence2DPartialIterator.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>
32  : BaseT()
33  , _fbegin(0)
34  , _fend(0)
35  , _sbegin(0)
36  , _send(0)
37  , _flength(0)
38 {
39 }
40 
41 template<typename Type>
43 }
44 
45 
46 template<typename Type>
48  : BaseT(copy)
49  , _fbegin(copy._fbegin)
50  , _fend(copy._fend)
51  , _sbegin(copy._sbegin)
52  , _send(copy._send)
53 {
54  this->_flength = this->_fend - this->_fbegin;
55 }
56 
57 template<typename Type>
59  const DataSequence2D<Cpu,typename std::remove_cv<Type>::type> &data_ptr,
60  std::size_t fbegin, std::size_t fend, std::size_t sbegin, std::size_t send)
61  : BaseT(data_ptr)
62  , _fbegin(fbegin)
63  , _fend(fend)
64  , _sbegin(sbegin)
65  , _send(send)
66 {
67  this->_flength = this->_fend - this->_fbegin;
68 }
69 
70 
71 template<typename Type>
73  DataSequence2D<Cpu,typename std::remove_cv<Type>::type> &data_ptr,
74  std::size_t fbegin, std::size_t fend, std::size_t sbegin, std::size_t send)
75  : BaseT(data_ptr)
76  , _fbegin(fbegin)
77  , _fend(fend)
78  , _sbegin(sbegin)
79  , _send(send)
80 {
81  this->_flength = this->_fend - this->_fbegin;
82 }
83 
84 
85 template<typename Type>
87  BOOST_ASSERT_MSG(this->_raw != nullptr,"Cannot dereference iterator over null DataSequence2D");
88  BOOST_ASSERT_MSG(this->mangle_offset(this->_offset) < this->_data->fast_axis_length()*this->_data->slow_axis_length(),"Cannot dereference post-end iterator");
89  return this->_raw+this->mangle_offset(this->_offset);
90 }
91 
92 template<typename Type>
94  BOOST_ASSERT_MSG(this->_raw != nullptr,"Cannot dereference iterator over null DataSequence2D");
95  BOOST_ASSERT_MSG(this->mangle_offset(this->_offset) < this->_data->fast_axis_length()*this->_data->slow_axis_length(),"Cannot dereference post-end iterator");
96  return *(this->_raw+this->mangle_offset(this->_offset));
97 }
98 
99 template<typename Type>
100 std::size_t DataSequence2DPartialIterator<Cpu,Type>::mangle_offset(std::size_t off) const {
101  std::size_t s_idx = off / this->_flength;
102  std::size_t f_idx = off - s_idx * this->_flength;
103  return (this->_sbegin+s_idx) * this->_data->fast_axis_length() + this->_fbegin + f_idx;
104 }
105 
106 template<typename Type>
109  r._offset=0;
110  return r;
111 }
112 
113 template<typename Type>
116  r._offset=this->_flength*(this->_send - this->_sbegin);
117  return r;
118 }
119 
120 } // namespace data
121 } // namespace cheetah
122 } // namespace ska
123 
Iterator over partial ranges of DataSequence2D types, "fast" axis. CPU specialisation.
Some limits and constants for FLDO.
Definition: Brdz.h:35
A 2-dimensional sequencial data of type T.
Iterator over partial ranges of DataSequence2D types, "fast" axis. Generic type.