ADTF
Loading...
Searching...
No Matches
iterator_intf.h
Go to the documentation of this file.
1
7
8#ifndef _ADTF_UCOM_ANT_ITERATOR_INTERFACE_INCLUDES_HEADER_
9#define _ADTF_UCOM_ANT_ITERATOR_INTERFACE_INCLUDES_HEADER_
10
11namespace adtf
12{
13namespace ucom
14{
15namespace ant
16{
17
18//forward declarations for usage in POD types
19template<typename> class IForwardIterator;
20template<typename> class IBidirectionalIterator;
21template<typename> class IRandomAccessIterator;
22
27template<typename T>
29
36template<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
85private:
87 typedef typename std::conditional<
88 std::is_const<value_type>::value,
90 IForwardIterator<T>*>::type iterator_interface_pointer;
91
92 //friend access
93 template<typename, template<typename> class> friend struct iterator_adapter;
94
95 iterator_interface_pointer m_pIt;
96 pointer m_pCur;
97};//struct input_iterator_adapter<T>
98
107template<typename T>
108inline bool operator< (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
109{
110 return oLHS.operator->() < oRHS.operator->();
111}
112
121template<typename T>
122inline bool operator> (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
123{
124 return oRHS < oLHS;
125}
126
135template<typename T>
136inline bool operator<= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
137{
138 return !(oLHS > oRHS);
139}
140
149template<typename T>
150inline bool operator>= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
151{
152 return !(oLHS < oRHS);
153}
154
163template<typename T>
164inline bool operator== (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
165{
166 return !(oLHS < oRHS) && !(oLHS > oRHS);
167}
168
177template<typename T>
178inline bool operator!= (const forward_iterator<T>& oLHS, const forward_iterator<T>& oRHS) noexcept
179{
180 return !(oLHS == oRHS);
181}
182
188template<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
224private:
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
246 iterator m_oBegin;
247 iterator m_oEnd;
248};//struct iterator_adapter
249
254template<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,
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
303private:
304 iterator m_oBegin;
305 iterator m_oEnd;
306};//struct iterator_adapter
307
312template<typename T>
314{
315public:
320 virtual T* Next() const = 0; //mutable must be used
321
322protected:
324 ~IForwardIterator() = default;
325};//class IForwardIterator
326
332template<typename T>
334{
335public:
340 virtual T* Previous() const = 0; //mutable must be used
341
342protected:
345};//class IBidirectionalIterator
346
353template<typename T>
355{
356public:
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
371protected:
374};//class IRandomAccessIterator
375
376}//ns ant
377
379template<typename T>
381
383template<typename T>
385
387template<typename T>
389
391template<typename T, template<typename> class IteratorType = ant::forward_iterator>
393
395template<typename T>
397
399template<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...
Definition iterator_intf.h:334
~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.
Definition iterator_intf.h:314
virtual T * Next() const =0
Increment iterator by one - may be used with mutable member iterators.
~IForwardIterator()=default
Default destructor.
Random access iterator interface.
Definition iterator_intf.h:355
~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.
Namespace for all functionality of the ADTF UCOM SDK provided since v3.0.
Definition test_runtime.h:14
bool operator>(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than operator for forward_iterator.
Definition iterator_intf.h:122
bool operator<(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than operator for forward_iterator.
Definition iterator_intf.h:108
bool operator>=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than-or-equal operator for forward_iterator.
Definition iterator_intf.h:150
bool operator<=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than-or-equal operator for forward_iterator.
Definition iterator_intf.h:136
bool operator!=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Inequality operator for forward_iterator.
Definition iterator_intf.h:178
bool operator==(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Equality operator for forward_iterator.
Definition iterator_intf.h:164
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::pointer_iterator< T > pointer_iterator
Alias always bringing the latest version of ant::pointer_iterator into scope.
Definition iterator_intf.h:396
ant::IRandomAccessIterator< T > IRandomAccessIterator
Alias always bringing the latest version of ant::IRandomAccessIterator into scope.
Definition iterator_intf.h:388
ant::IForwardIterator< T > IForwardIterator
Alias always bringing the latest version of ant::IForwardIterator into scope.
Definition iterator_intf.h:380
ant::iterator_adapter< T, IteratorType > iterator_adapter
Alias always bringing the latest version of ant::iterator_adapter into scope.
Definition iterator_intf.h:392
ant::IBidirectionalIterator< T > IBidirectionalIterator
Alias always bringing the latest version of ant::IBidirectionalIterator into scope.
Definition iterator_intf.h:384
ant::forward_iterator< T > forward_iterator
Alias always bringing the latest version of ant::forward_iterator into scope.
Definition iterator_intf.h:400
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
POD forward iterator type using a forward iterator interface to iterate over a sequence.
Definition iterator_intf.h:38
friend struct iterator_adapter
Alias always bringing the latest version of ant::iterator_adapter into scope.
Definition iterator_intf.h:93
const T & const_reference
const value reference type
Definition iterator_intf.h:45
const_pointer operator->() const
Pointer operator const version.
Definition iterator_intf.h:71
pointer operator->()
Pointer operator.
Definition iterator_intf.h:65
T value_type
value type
Definition iterator_intf.h:40
std::ptrdiff_t difference_type
pointer difference type
Definition iterator_intf.h:47
std::forward_iterator_tag iterator_category
category of the iterator
Definition iterator_intf.h:46
forward_iterator< T > self_type
self type
Definition iterator_intf.h:41
self_type operator++()
Pre-increment operator using iterator interface method Next()
Definition iterator_intf.h:53
reference operator*()
Dereference operator.
Definition iterator_intf.h:77
self_type operator++(int32_t)
Post-increment operator.
Definition iterator_intf.h:59
const T * const_pointer
const value pointer type
Definition iterator_intf.h:43
T & reference
value reference type
Definition iterator_intf.h:44
const_reference operator*() const
Dereference operator const version.
Definition iterator_intf.h:83
T * pointer
value pointer type
Definition iterator_intf.h:42
std::conditional< std::is_const< value_type >::value, const_iterator, value_type * >::type iterator
iterator type
Definition iterator_intf.h:263
iterator_adapter< value_type, pointer_iterator > self_type
self type
Definition iterator_intf.h:258
iterator end() const
Get pointer to the end of the container sequence (STL compliant)
Definition iterator_intf.h:275
const_iterator cend() const
Get const pointer to the end of the container sequence (STL compliant)
Definition iterator_intf.h:287
static self_type create(iterator i_oBegin, iterator i_oEnd)
Create the adapter by assigning begin and end iterators (pointers)
Definition iterator_intf.h:295
T value_type
value type
Definition iterator_intf.h:257
const_iterator cbegin() const
Get const pointer to the beginning of the container sequence (STL compliant)
Definition iterator_intf.h:281
const value_type * const_iterator
const iterator type
Definition iterator_intf.h:259
iterator begin() const
Get pointer to the beginning of the container sequence (STL compliant)
Definition iterator_intf.h:269
Adapter for begin and end iterators - usable as return and parameter value in interfaces.
Definition iterator_intf.h:190
IteratorType< const value_type > const_iterator
Definition iterator_intf.h:194
iterator_adapter< value_type, IteratorType > self_type
self type
Definition iterator_intf.h:193
const_iterator cend() const
Get const iterator to the end of the container sequence (STL compliant)
Definition iterator_intf.h:222
iterator end() const
Get iterator to the end of the container sequence (STL compliant)
Definition iterator_intf.h:210
const_iterator cbegin() const
Get const iterator to the beginning of the container sequence (STL compliant)
Definition iterator_intf.h:216
T value_type
value type
Definition iterator_intf.h:192
std::conditional< std::is_const< value_type >::value, const_iterator, IteratorType< value_type > >::type iterator
Definition iterator_intf.h:198
iterator begin() const
Get iterator to the beginning of the container sequence (STL compliant)
Definition iterator_intf.h:204
Empty struct template to specialize implementations of iterator interfaces.
Definition iterator_intf.h:28