Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataSequence2DPartialIterator_bool.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 
25 #include "cheetah/data/DataSequence2DPartialIterator.h"
26 #include <algorithm>
27 
28 namespace ska {
29 namespace cheetah {
30 namespace data {
31 
32 template <typename RawIterator>
34  : public std::iterator<std::forward_iterator_tag, bool>
35 {
37  using BaseType = RawIterator;
38 
39  public:
40  //typedef typename BaseType::iterator_category iterator_category;
41  typedef typename std::iterator_traits<RawIterator>::difference_type difference_type;
42 
43  public:
48  = default;
49 
55  = default;
56 
58  BaseType const &iterator)
59  : _it(iterator)
60  , _fast_index(0)
61  {}
62 
64  BaseType const &iterator,
65  std::size_t fast_length,
66  std::size_t slow_stride)
67  : _it(iterator)
68  , _fast_index(0)
69  , _slow_stride(slow_stride)
70  , _fast_length(fast_length)
71  {}
72 
77 
78  bool operator==(SelfType const& o) const
79  {
80  return _it == o._it;
81  }
82 
83  bool operator!=(SelfType const& o) const
84  {
85  return _it != o._it;
86  }
87 
88  typename BaseType::reference operator*()
89  {
90  return *_it;
91  }
92 
93  typename BaseType::reference const operator*() const
94  {
95  return *_it;
96  }
97 
98  SelfType& operator+=(typename BaseType::reference const v)
99  {
100  _it += v;
101  return *this;
102  }
103 
104  SelfType& operator++()
105  {
106  ++_it;
107 
108  if (++_fast_index < _fast_length) return *this;
109 
110  _it += _slow_stride;
111  _fast_index = 0;
112  return *this;
113  }
114 
115  difference_type operator-(SelfType const o)
116  {
117  std::size_t diff = _fast_index + (o._fast_length - o._fast_index);
118  return (_it - o._it)/(o._fast_length + o._slow_stride) + diff - 1;
119  }
120 
121  RawIterator& raw_it()
122  {
123  return _it;
124  }
125 
126  RawIterator const& raw_it() const
127  {
128  return _it;
129  }
130 
131  private:
132  RawIterator _it;
133  std::size_t _fast_index;
134  std::size_t _slow_stride;
135  std::size_t _fast_length;
136 };
137 
138 template <>
140  : public DataSequence2DPartialIteratorImpl<std::vector<bool>::iterator>
141 {
143 
144  public:
145  using BaseType::BaseType;
146 };
147 
148 template <>
149 class DataSequence2DPartialIterator<Cpu, const bool>:
150  public DataSequence2DPartialIteratorImpl<std::vector<bool>::const_iterator>
151 {
153 
154  public:
155  using BaseType::BaseType;
156 };
157 } // namespace data
158 } // namespace cheetah
159 } // namespace ska
160 
161 #include <algorithm>
162 
163 namespace std {
164  template<typename Arch>
165  struct iterator_traits<ska::cheetah::data::DataSequence2DPartialIterator<Arch, bool>>
166  {
168  };
169 
170  template<> inline
171  void fill<typename ska::cheetah::data::DataSequence2DPartialIterator<ska::cheetah::Cpu, bool>, bool>(typename ska::cheetah::data::DataSequence2DPartialIterator<ska::cheetah::Cpu, bool> begin, typename ska::cheetah::data::DataSequence2DPartialIterator<ska::cheetah::Cpu, bool> end, const bool& x)
172  {
173  std::fill(begin.raw_it(), end.raw_it(), x);
174  }
175 
176 
177  template< class Arch>
178  typename std::iterator_traits<ska::cheetah::data::DataSequence2DPartialIterator<Arch,bool>>::difference_type
180  {
181  return last - first;
182  }
183 
184 }
DataSequence2DPartialIteratorImpl()=default
default constructor. Required by random_access_iterator_tag
Some limits and constants for FLDO.
Definition: Brdz.h:35
Iterator over partial ranges of DataSequence2D types, "fast" axis. Generic type.