Embedded Template Library  1.0
fixed_iterator.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2015 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_FIXED_ITERATOR_INCLUDED
32 #define ETL_FIXED_ITERATOR_INCLUDED
33 
34 #include "platform.h"
35 #include "iterator.h"
36 
37 #include "iterator.h"
38 
40 
41 namespace etl
42 {
47  template <typename TIterator>
48  class fixed_iterator : etl::iterator<typename etl::iterator_traits<TIterator>::iterator_category, typename etl::iterator_traits<TIterator>::value_type>
49  {
50  public:
51 
52  //***************************************************************************
54  //***************************************************************************
56  : it(TIterator())
57  {
58  }
59 
60  //***************************************************************************
62  //***************************************************************************
63  fixed_iterator(TIterator it_)
64  : it(it_)
65  {
66  }
67 
68  //***************************************************************************
70  //***************************************************************************
72  {
73  return *this;
74  }
75 
76  //***************************************************************************
78  //***************************************************************************
80  {
81  return *this;
82  }
83 
84  //***************************************************************************
86  //***************************************************************************
88  {
89  return *this;
90  }
91 
92  //***************************************************************************
94  //***************************************************************************
96  {
97  return *this;
98  }
99 
100  //***************************************************************************
102  //***************************************************************************
103  typename etl::iterator_traits<TIterator>::value_type operator *()
104  {
105  return *it;
106  }
107 
108  //***************************************************************************
110  //***************************************************************************
111  const typename etl::iterator_traits<TIterator>::value_type operator *() const
112  {
113  return *it;
114  }
115 
116  //***************************************************************************
118  //***************************************************************************
119  TIterator operator ->()
120  {
121  return it;
122  }
123 
124  //***************************************************************************
126  //***************************************************************************
127  const TIterator operator ->() const
128  {
129  return it;
130  }
131 
132  //***************************************************************************
134  //***************************************************************************
135  operator TIterator() const
136  {
137  return it;
138  }
139 
140  //***************************************************************************
142  //***************************************************************************
143  fixed_iterator& operator +=(typename etl::iterator_traits<TIterator>::difference_type /*offset*/)
144  {
145  return *this;
146  }
147 
148  //***************************************************************************
150  //***************************************************************************
151  fixed_iterator& operator -=(typename etl::iterator_traits<TIterator>::difference_type /*offset*/)
152  {
153  return *this;
154  }
155 
156  //***************************************************************************
158  //***************************************************************************
159  fixed_iterator& operator =(TIterator new_it)
160  {
161  it = new_it;
162  return *this;
163  }
164 
165  //***************************************************************************
167  //***************************************************************************
169  {
170  it = other.it;
171  return *this;
172  }
173 
174  private:
175 
176  TIterator it;
177  };
178 
179  //*****************************************************************************
181  //*****************************************************************************
182  template <typename TIterator>
184  typename etl::iterator_traits<TIterator>::difference_type /*rhs*/)
185  {
186  return lhs;
187  }
188 
189  //*****************************************************************************
191  //*****************************************************************************
192  template <typename TIterator>
194  typename etl::iterator_traits<TIterator>::difference_type /*rhs*/)
195  {
196  return lhs;
197  }
198 
199  //*****************************************************************************
201  //*****************************************************************************
202  template <typename TIterator>
203  typename etl::iterator_traits<TIterator>::difference_type operator -(etl::fixed_iterator<TIterator>& lhs,
205  {
206  return TIterator(lhs) - TIterator(rhs);
207  }
208 
209  //*****************************************************************************
211  //*****************************************************************************
212  template <typename TIterator>
215  {
216  return TIterator(lhs) == TIterator(rhs);
217  }
218 
219  //*****************************************************************************
221  //*****************************************************************************
222  template <typename TIterator>
224  TIterator rhs)
225  {
226  return TIterator(lhs) == rhs;
227  }
228 
229  //*****************************************************************************
231  //*****************************************************************************
232  template <typename TIterator>
233  bool operator ==(TIterator lhs,
235  {
236  return lhs == TIterator(rhs);
237  }
238 
239 
240  //*****************************************************************************
242  //*****************************************************************************
243  template <typename TIterator>
246  {
247  return !(lhs == rhs);
248  }
249 
250  //*****************************************************************************
252  //*****************************************************************************
253  template <typename TIterator>
255  TIterator rhs)
256  {
257  return !(lhs == rhs);
258  }
259 
260  //*****************************************************************************
262  //*****************************************************************************
263  template <typename TIterator>
264  bool operator !=(TIterator& lhs,
266  {
267  return !(lhs == rhs);
268  }
269 }
270 
271 #endif
fixed_iterator()
Default constructor.
Definition: fixed_iterator.h:55
fixed_iterator & operator-=(typename etl::iterator_traits< TIterator >::difference_type)
-= operator.
Definition: fixed_iterator.h:151
fixed_iterator & operator=(TIterator new_it)
Assignment from iterator.
Definition: fixed_iterator.h:159
TIterator operator->()
-> operator.
Definition: fixed_iterator.h:119
fixed_iterator & operator++()
Increment (Does nothing).
Definition: fixed_iterator.h:71
fixed_iterator & operator--()
Decrement (Does nothing).
Definition: fixed_iterator.h:87
fixed_iterator(TIterator it_)
Construct from iterator.
Definition: fixed_iterator.h:63
fixed_iterator & operator+=(typename etl::iterator_traits< TIterator >::difference_type)
+= operator.
Definition: fixed_iterator.h:143
etl::iterator_traits< TIterator >::value_type operator*()
Dereference operator.
Definition: fixed_iterator.h:103
Definition: fixed_iterator.h:49
Definition: absolute.h:37
etl::fixed_iterator< TIterator > & operator-(etl::fixed_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type)
Definition: fixed_iterator.h:193
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:594
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:582
etl::fixed_iterator< TIterator > & operator+(etl::fixed_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type)
Definition: fixed_iterator.h:183
iterator
Definition: iterator.h:422