1 | /*
|
---|
2 | * UnobservedIterator.hpp
|
---|
3 | *
|
---|
4 | * Created on: Dec 13, 2015
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 |
|
---|
9 | #ifndef UNOBSERVEDITERATOR_HPP_
|
---|
10 | #define UNOBSERVEDITERATOR_HPP_
|
---|
11 |
|
---|
12 | // include config.h
|
---|
13 | #ifdef HAVE_CONFIG_H
|
---|
14 | #include <config.h>
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | #include <iterator>
|
---|
18 |
|
---|
19 | class Observable;
|
---|
20 |
|
---|
21 | /** This is a mock of UnobservedIterator that does not observe.
|
---|
22 | *
|
---|
23 | * The only thing we need to add here is another cstor to be signature compatible
|
---|
24 | * for use in ObservedContainer.
|
---|
25 | */
|
---|
26 | template<class _Set>
|
---|
27 | class UnobservedIterator
|
---|
28 | : public std::iterator<typename std::iterator_traits<typename _Set::iterator>::iterator_category,
|
---|
29 | typename std::iterator_traits<typename _Set::iterator>::value_type,
|
---|
30 | typename std::iterator_traits<typename _Set::iterator>::difference_type,
|
---|
31 | typename std::iterator_traits<typename _Set::iterator>::pointer,
|
---|
32 | typename std::iterator_traits<typename _Set::iterator>::reference>
|
---|
33 | {
|
---|
34 | public:
|
---|
35 | // Some typedefs to conform to STL-Iterator structure
|
---|
36 | typedef typename _Set::iterator _Iter;
|
---|
37 | typedef typename _Iter::value_type value_type;
|
---|
38 | typedef typename _Iter::difference_type difference_type;
|
---|
39 | typedef typename _Iter::pointer pointer;
|
---|
40 | typedef typename _Iter::reference reference;
|
---|
41 | typedef typename _Iter::iterator_category iterator_category;
|
---|
42 |
|
---|
43 | UnobservedIterator()
|
---|
44 | {}
|
---|
45 |
|
---|
46 | UnobservedIterator(_Iter iter,Observable *obs) :
|
---|
47 | iter(iter)
|
---|
48 | {}
|
---|
49 |
|
---|
50 | UnobservedIterator(const UnobservedIterator &dest) :
|
---|
51 | iter(dest.iter)
|
---|
52 | {}
|
---|
53 |
|
---|
54 | // standard Iterator methods
|
---|
55 | UnobservedIterator& operator=(const UnobservedIterator& dest){
|
---|
56 | if(&dest !=this)
|
---|
57 | iter = dest.iter;
|
---|
58 | return *this;
|
---|
59 | }
|
---|
60 |
|
---|
61 | virtual ~UnobservedIterator() {}
|
---|
62 |
|
---|
63 | UnobservedIterator& operator++() // prefix
|
---|
64 | {
|
---|
65 | ++iter;
|
---|
66 | return *this;
|
---|
67 | }
|
---|
68 |
|
---|
69 | UnobservedIterator operator++(int) // postfix with the dummy int parameter
|
---|
70 | {
|
---|
71 | UnobservedIterator ret(*this);
|
---|
72 | ++(*this);
|
---|
73 | return ret;
|
---|
74 | }
|
---|
75 |
|
---|
76 | UnobservedIterator& operator--() // prefix
|
---|
77 | {
|
---|
78 | --iter;
|
---|
79 | return *this;
|
---|
80 | }
|
---|
81 |
|
---|
82 | UnobservedIterator operator--(int) // postfix with the dummy int parameter
|
---|
83 | {
|
---|
84 | UnobservedIterator ret(*this);
|
---|
85 | --(*this);
|
---|
86 | return ret;
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool operator==(const UnobservedIterator &rhs) const
|
---|
90 | {
|
---|
91 | return iter==rhs.iter;
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool operator!=(const UnobservedIterator &rhs) const
|
---|
95 | {
|
---|
96 | return iter!=rhs.iter;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /** Returns the value_type this iterator represents.
|
---|
100 | *
|
---|
101 | * @return value_type of iterator
|
---|
102 | */
|
---|
103 | value_type operator*() const {
|
---|
104 | return (*iter);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** Returns pointer to value_type this iterator represents.
|
---|
108 | *
|
---|
109 | * @return pointer to value_type of iterator
|
---|
110 | */
|
---|
111 | value_type *operator->() const {
|
---|
112 | return &(*iter);
|
---|
113 | }
|
---|
114 |
|
---|
115 | operator typename _Set::const_iterator() {
|
---|
116 | return iter;
|
---|
117 | }
|
---|
118 |
|
---|
119 | // bool operator==(const UnobservedIterator &dest)
|
---|
120 | // { return static_cast<_Iter>(*this) == static_cast<_Iter>(dest); }
|
---|
121 | //
|
---|
122 | // bool operator!=(const UnobservedIterator &dest)
|
---|
123 | // { return !(*this == dest); }
|
---|
124 |
|
---|
125 | private:
|
---|
126 | _Iter iter;
|
---|
127 | };
|
---|
128 |
|
---|
129 | #endif /* UNOBSERVEDITERATOR_HPP_ */
|
---|