ADTF  3.18.2
iterator_intf.h
Go to the documentation of this file.
1 
8 #ifndef _ADTF_UCOM_ANT_ITERATOR_INTERFACE_INCLUDES_HEADER_
9 #define _ADTF_UCOM_ANT_ITERATOR_INTERFACE_INCLUDES_HEADER_
10 
11 namespace adtf
12 {
13 namespace ucom
14 {
15 namespace ant
16 {
17 
18 //forward declarations for usage in POD types
19 template<typename> class IForwardIterator;
20 template<typename> class IBidirectionalIterator;
21 template<typename> class IRandomAccessIterator;
22 
27 template<typename T>
28 struct pointer_iterator {};
29 
36 template<typename T>
38 {
39  //necessary types for iterators in general
40  typedef T value_type;
42  typedef T* pointer;
43  typedef const T* const_pointer;
44  typedef T& reference;
45  typedef const T& const_reference;
46  typedef std::forward_iterator_tag iterator_category;
47  typedef std::ptrdiff_t difference_type;
48 
53  self_type operator++() { m_pCur = m_pIt->Next(); return *this; }
54 
59  self_type operator++(int32_t) { self_type oTmp = *this; ++(*this); return oTmp; }
60 
65  pointer operator->() { return m_pCur; }
66 
71  const_pointer operator->() const { return m_pCur; }
72 
77  reference operator*() { return *m_pCur; }
78 
83  const_reference operator*() const { return *m_pCur; }
84 
85 private:
87  typedef typename std::conditional<
88  std::is_const<value_type>::value,
89  const IForwardIterator<T>*,
91 
92  //friend access
93  template<typename, template<typename> class> friend struct iterator_adapter;
94 
97 };//struct input_iterator_adapter<T>
98 
107 template<typename T>
108 inline bool operator< (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
109 {
110  return oLHS.operator->() < oRHS.operator->();
111 }
112 
121 template<typename T>
122 inline bool operator> (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
123 {
124  return oRHS < oLHS;
125 }
126 
135 template<typename T>
136 inline bool operator<= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
137 {
138  return !(oLHS > oRHS);
139 }
140 
149 template<typename T>
150 inline bool operator>= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
151 {
152  return !(oLHS < oRHS);
153 }
154 
163 template<typename T>
164 inline bool operator== (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
165 {
166  return !(oLHS < oRHS) && !(oLHS > oRHS);
167 }
168 
177 template<typename T>
178 inline bool operator!= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
179 {
180  return !(oLHS == oRHS);
181 }
182 
188 template<typename T, template<typename> class IteratorType = forward_iterator>
190 {
191  //needed types for adapter/containers
192  typedef T value_type;
194  typedef IteratorType<const value_type> const_iterator;
195  typedef typename std::conditional <
196  std::is_const<value_type>::value,
198  IteratorType < value_type >>::type iterator;
199 
204  iterator begin() const { return m_oBegin; }
205 
210  iterator end() const { return m_oEnd; }
211 
216  const_iterator cbegin() const { return begin(); }
217 
222  const_iterator cend() const { return end(); }
223 
224 private:
225  //friend class access for assignment
226  template<typename, template<typename> class> friend class cForwardIterator;
227 
235  template<typename IteratorInterfaceType>
236  static self_type create(IteratorInterfaceType& o_oIterator)
237  { //create both iterators which are members of iterator_adapter
238  iterator_adapter oTmpContainer;
239  oTmpContainer.m_oBegin.m_pIt = &o_oIterator;
240  oTmpContainer.m_oBegin.m_pCur = o_oIterator.Begin();
241  oTmpContainer.m_oEnd.m_pIt = &o_oIterator;
242  oTmpContainer.m_oEnd.m_pCur = o_oIterator.End();
243  return oTmpContainer;
244  }
245 
248 };//struct iterator_adapter
249 
254 template<typename T>
256 {
257  typedef T value_type;
259  typedef const value_type* const_iterator;
260  typedef typename std::conditional <
261  std::is_const<value_type>::value,
263  value_type*> ::type iterator;
264 
269  iterator begin() const { return m_oBegin; }
270 
275  iterator end() const { return m_oEnd; }
276 
281  const_iterator cbegin() const { return begin(); }
282 
287  const_iterator cend() const { return end(); }
288 
295  static self_type create(iterator i_oBegin, iterator i_oEnd)
296  { //create both iterators which are members of iterator_adapter
297  iterator_adapter oTmpContainer;
298  oTmpContainer.m_oBegin = i_oBegin;
299  oTmpContainer.m_oEnd = i_oEnd;
300  return oTmpContainer;
301  }
302 
303 private:
306 };//struct iterator_adapter
307 
312 template<typename T>
314 {
315 public:
320  virtual T* Next() const = 0; //mutable must be used
321 
322 protected:
324  ~IForwardIterator() = default;
325 };//class IForwardIterator
326 
332 template<typename T>
334 {
335 public:
340  virtual T* Previous() const = 0; //mutable must be used
341 
342 protected:
345 };//class IBidirectionalIterator
346 
353 template<typename T>
355 {
356 public:
362  virtual T* Forward(size_t i_nIncrement) const = 0; //mutable must be used
363 
369  virtual T* Backward(size_t i_nDecrement) const = 0; //mutable must be used
370 
371 protected:
374 };//class IRandomAccessIterator
375 
376 }//ns ant
377 
379 template<typename T>
381 
383 template<typename T>
385 
387 template<typename T>
389 
391 template<typename T, template<typename> class IteratorType = ant::forward_iterator>
393 
395 template<typename T>
397 
399 template<typename T>
401 
402 }//ns ucom
403 }//ns adtf
404 
405 #endif // _ADTF_UCOM_ANT_ITERATOR_INTERFACE_INCLUDES_HEADER_
Bidirectional iterator interface details Additionally providing method Previous() for POD bidirection...
~IBidirectionalIterator()=default
Default destructor.
virtual T * Previous() const =0
Decrement iterator by one - may be used with mutable member iterators.
Forward iterator interface providing method Next() usable by POD forward iterators.
virtual T * Next() const =0
Increment iterator by one - may be used with mutable member iterators.
~IForwardIterator()=default
Default destructor.
Random access iterator interface.
~IRandomAccessIterator()=default
Default destructor.
virtual T * Backward(size_t i_nDecrement) const =0
Decrement iterator by n - may be used with mutable member iterators.
virtual T * Forward(size_t i_nIncrement) const =0
Increment iterator by n - may be used with mutable member iterators.
bool operator>(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than operator for forward_iterator.
bool operator<(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than operator for forward_iterator.
bool operator>=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than-or-equal operator for forward_iterator.
bool operator<=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than-or-equal operator for forward_iterator.
bool operator!=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Inequality operator for forward_iterator.
bool operator==(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Equality operator for forward_iterator.
ant::IBidirectionalIterator< T > IBidirectionalIterator
Alias always bringing the latest version of ant::IBidirectionalIterator into scope.
ant::IForwardIterator< T > IForwardIterator
Alias always bringing the latest version of ant::IForwardIterator into scope.
ant::IRandomAccessIterator< T > IRandomAccessIterator
Alias always bringing the latest version of ant::IRandomAccessIterator into scope.
Namespace for entire ADTF SDK.
POD forward iterator type using a forward iterator interface to iterate over a sequence.
Definition: iterator_intf.h:38
const_pointer operator->() const
Pointer operator const version.
Definition: iterator_intf.h:71
pointer m_pCur
Pointer to the current value inside the sequence.
Definition: iterator_intf.h:96
pointer operator->()
Pointer operator.
Definition: iterator_intf.h:65
self_type operator++()
Pre-increment operator using iterator interface method Next()
Definition: iterator_intf.h:53
std::forward_iterator_tag iterator_category
category of the iterator
Definition: iterator_intf.h:46
reference operator*()
Dereference operator.
Definition: iterator_intf.h:77
std::conditional< std::is_const< value_type >::value, const IForwardIterator< T > *, IForwardIterator< T > * >::type iterator_interface_pointer
const correct pointer to the iterator interface used to increment this iterator
Definition: iterator_intf.h:90
iterator_interface_pointer m_pIt
Pointer to iterator interface providing Next()
Definition: iterator_intf.h:95
const T * const_pointer
const value pointer type
Definition: iterator_intf.h:43
T * pointer
value pointer type
Definition: iterator_intf.h:42
forward_iterator< T > self_type
self type
Definition: iterator_intf.h:41
self_type operator++(int32_t)
Post-increment operator.
Definition: iterator_intf.h:59
T & reference
value reference type
Definition: iterator_intf.h:44
const_reference operator*() const
Dereference operator const version.
Definition: iterator_intf.h:83
std::ptrdiff_t difference_type
pointer difference type
Definition: iterator_intf.h:47
const T & const_reference
const value reference type
Definition: iterator_intf.h:45
iterator begin() const
Get pointer to the beginning of the container sequence (STL compliant)
iterator m_oBegin
pointer to the beginning of the containers values
const_iterator cbegin() const
Get const pointer to the beginning of the container sequence (STL compliant)
static self_type create(iterator i_oBegin, iterator i_oEnd)
Create the adapter by assigning begin and end iterators (pointers)
iterator end() const
Get pointer to the end of the container sequence (STL compliant)
std::conditional< std::is_const< value_type >::value, const_iterator, value_type * >::type iterator
iterator type
const_iterator cend() const
Get const pointer to the end of the container sequence (STL compliant)
const value_type * const_iterator
const iterator type
iterator_adapter< value_type, pointer_iterator > self_type
self type
iterator m_oEnd
pointer past the last element of the container values
Adapter for begin and end iterators - usable as return and parameter value in interfaces.
iterator begin() const
Get iterator to the beginning of the container sequence (STL compliant)
iterator m_oBegin
iterator to the beginning of the containers sequence
const_iterator cbegin() const
Get const iterator to the beginning of the container sequence (STL compliant)
std::conditional< std::is_const< value_type >::value, const_iterator, IteratorType< value_type > >::type iterator
iterator type
iterator end() const
Get iterator to the end of the container sequence (STL compliant)
static self_type create(IteratorInterfaceType &o_oIterator)
Create the adapter by assigning iterator interface to begin and end iterators.
IteratorType< const value_type > const_iterator
const iterator type
const_iterator cend() const
Get const iterator to the end of the container sequence (STL compliant)
iterator_adapter< value_type, IteratorType > self_type
self type
iterator m_oEnd
iterator to past the last element of the container sequence
Empty struct template to specialize implementations of iterator interfaces.
Definition: iterator_intf.h:28