ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
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,
91
92 //friend access
93 template<typename, template<typename> class> friend struct iterator_adapter;
94
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
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:
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...
virtual T * Previous() const =0
Decrement iterator by one - may be used with mutable member iterators.
~IBidirectionalIterator()=default
Default destructor.
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.
virtual T * Forward(size_t i_nIncrement) const =0
Increment iterator by n - may be used with mutable member iterators.
~IRandomAccessIterator()=default
Default destructor.
virtual T * Backward(size_t i_nDecrement) const =0
Decrement iterator by n - may be used with mutable member iterators.
Namespace for all functionality provided since v3.0.
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
Greater-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.
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 operator for forward_iterator.
Namespace for the ADTF uCOM3 SDK.
ant::IBidirectionalIterator< T > IBidirectionalIterator
Alias always bringing the latest version of IBidirectionalIterator into scope.
ant::iterator_adapter< T, IteratorType > iterator_adapter
Alias always bringing the latest version of ant::iterator_adapter into scope.
ant::pointer_iterator< T > pointer_iterator
Alias always bringing the latest version of ant::pointer_iterator into scope.
ant::IForwardIterator< T > IForwardIterator
Alias always bringing the latest version of IForwardIterator into scope.
ant::IRandomAccessIterator< T > IRandomAccessIterator
Alias always bringing the latest version of IRandomAccessIterator into scope.
ant::forward_iterator< T > forward_iterator
Alias always bringing the latest version of ant::forward_iterator into scope.
Namespace for entire ADTF SDK.
POD forward iterator type using a forward iterator interface to iterate over a sequence.
const_pointer operator->() const
Pointer operator const version.
pointer m_pCur
Pointer to the current value inside the sequence.
pointer operator->()
Pointer operator.
friend struct iterator_adapter
Alias always bringing the latest version of ant::iterator_adapter into scope.
self_type operator++()
Pre-increment operator using iterator interface method Next()
std::forward_iterator_tag iterator_category
category of the iterator
reference operator*()
Dereference operator.
iterator_interface_pointer m_pIt
Pointer to iterator interface providing Next()
const T * const_pointer
const value pointer type
T * pointer
value pointer type
forward_iterator< T > self_type
self type
self_type operator++(int32_t)
Post-increment operator.
T & reference
value reference type
std::conditional< std::is_const< value_type >::value, constIForwardIterator< T > *, IForwardIterator< T > * >::type iterator_interface_pointer
const correct pointer to the iterator interface used to increment this iterator
const_reference operator*() const
Dereference operator const version.
std::ptrdiff_t difference_type
pointer difference type
const T & const_reference
const value reference type
std::conditional< std::is_const< value_type >::value, const_iterator, value_type * >::type iterator
iterator type
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)
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)
const_iterator cbegin() const
Get const iterator to the beginning of the container sequence (STL compliant)
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.
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
std::conditional< std::is_const< value_type >::value, const_iterator, IteratorType< value_type > >::type iterator
Empty struct template to specialize implementations of iterator interfaces.