1 | /*
|
---|
2 | * SelectiveIterator_impl.hpp
|
---|
3 | *
|
---|
4 | * Created on: Mar 17, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef SELECTIVEITERATOR_IMPL_HPP_
|
---|
9 | #define SELECTIVEITERATOR_IMPL_HPP_
|
---|
10 |
|
---|
11 | #include "Helpers/helpers.hpp"
|
---|
12 |
|
---|
13 | template<class _Target,
|
---|
14 | class _Container,
|
---|
15 | class _Descriptor>
|
---|
16 | SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(_Descriptor _descr, _Container &_content) :
|
---|
17 | descr(_descr.get_impl()),
|
---|
18 | index(0),
|
---|
19 | content(_content)
|
---|
20 | {
|
---|
21 | state = content.begin();
|
---|
22 | advanceState();
|
---|
23 | }
|
---|
24 |
|
---|
25 | template<class _Target,
|
---|
26 | class _Container,
|
---|
27 | class _Descriptor>
|
---|
28 | SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(_Descriptor _descr, _Container &_content, SelectiveIterator<_Target,_Container,_Descriptor>::Iter _state) :
|
---|
29 | state(_state),
|
---|
30 | descr(_descr.get_impl()),
|
---|
31 | index(0),
|
---|
32 | content(_content)
|
---|
33 | {
|
---|
34 | advanceState();
|
---|
35 | }
|
---|
36 |
|
---|
37 | template<class _Target,
|
---|
38 | class _Container,
|
---|
39 | class _Descriptor>
|
---|
40 | SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs) :
|
---|
41 | state(rhs.state),
|
---|
42 | descr(rhs.descr),
|
---|
43 | index(rhs.index),
|
---|
44 | content(rhs.content)
|
---|
45 | {}
|
---|
46 |
|
---|
47 | template<class _Target,
|
---|
48 | class _Container,
|
---|
49 | class _Descriptor>
|
---|
50 | SelectiveIterator<_Target,_Container,_Descriptor>& SelectiveIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs)
|
---|
51 | {
|
---|
52 | if(&rhs!=this){
|
---|
53 | state=rhs.state;
|
---|
54 | descr=rhs.descr;
|
---|
55 | index=rhs.index;
|
---|
56 | }
|
---|
57 | return *this;
|
---|
58 | }
|
---|
59 |
|
---|
60 | template<class _Target,
|
---|
61 | class _Container,
|
---|
62 | class _Descriptor>
|
---|
63 | SelectiveIterator<_Target,_Container,_Descriptor>&
|
---|
64 | SelectiveIterator<_Target,_Container,_Descriptor>::operator++(){
|
---|
65 | ++state;
|
---|
66 | ++index;
|
---|
67 | advanceState();
|
---|
68 | return *this;
|
---|
69 | }
|
---|
70 |
|
---|
71 | template<class _Target,
|
---|
72 | class _Container,
|
---|
73 | class _Descriptor>
|
---|
74 | SelectiveIterator<_Target,_Container,_Descriptor> SelectiveIterator<_Target,_Container,_Descriptor>::operator++(int){
|
---|
75 | SelectiveIterator<_Target,_Container,_Descriptor> res = SelectiveIterator<_Target,_Container,_Descriptor>(*this);
|
---|
76 | ++(*this);
|
---|
77 | return res;
|
---|
78 | }
|
---|
79 |
|
---|
80 | template<class _Target,
|
---|
81 | class _Container,
|
---|
82 | class _Descriptor>
|
---|
83 | bool
|
---|
84 | SelectiveIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs){
|
---|
85 | return state==rhs.state;
|
---|
86 | }
|
---|
87 |
|
---|
88 | template<class _Target,
|
---|
89 | class _Container,
|
---|
90 | class _Descriptor>
|
---|
91 | bool
|
---|
92 | SelectiveIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs){
|
---|
93 | return state!=rhs.state;
|
---|
94 | }
|
---|
95 |
|
---|
96 | template<class _Target,
|
---|
97 | class _Container,
|
---|
98 | class _Descriptor>
|
---|
99 | typename SelectiveIterator<_Target,_Container,_Descriptor>::Target
|
---|
100 | SelectiveIterator<_Target,_Container,_Descriptor>::operator*(){
|
---|
101 | return _take<_Target,value_type>::get(*state);
|
---|
102 | }
|
---|
103 |
|
---|
104 | template<class _Target,
|
---|
105 | class _Container,
|
---|
106 | class _Descriptor>
|
---|
107 | void
|
---|
108 | SelectiveIterator<_Target,_Container,_Descriptor>::advanceState(){
|
---|
109 | // go forward until we have a matching atom or the end is reached
|
---|
110 | while((state!=content.end()) && (!descr->predicate(*state))){
|
---|
111 | ++state;
|
---|
112 | ++index;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | template<class _Target,
|
---|
117 | class _Container,
|
---|
118 | class _Descriptor>
|
---|
119 | int
|
---|
120 | SelectiveIterator<_Target,_Container,_Descriptor>::getCount(){
|
---|
121 | return index;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | #define CONSTRUCT_SELECTIVE_ITERATOR(_Target,_Container,_Descriptor) \
|
---|
126 | template SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(_Descriptor, _Container&); \
|
---|
127 | template SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(_Descriptor, _Container&, SelectiveIterator<_Target,_Container,_Descriptor>::Iter); \
|
---|
128 | template SelectiveIterator<_Target,_Container,_Descriptor>::SelectiveIterator(const SelectiveIterator<_Target,_Container,_Descriptor>&); \
|
---|
129 | template SelectiveIterator<_Target,_Container,_Descriptor>& SelectiveIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveIterator<_Target,_Container,_Descriptor>&); \
|
---|
130 | template SelectiveIterator<_Target,_Container,_Descriptor>& SelectiveIterator<_Target,_Container,_Descriptor>::operator++(); \
|
---|
131 | template SelectiveIterator<_Target,_Container,_Descriptor> SelectiveIterator<_Target,_Container,_Descriptor>::operator++(int); \
|
---|
132 | template bool SelectiveIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveIterator<_Target,_Container,_Descriptor>&); \
|
---|
133 | template bool SelectiveIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveIterator<_Target,_Container,_Descriptor>&); \
|
---|
134 | template SelectiveIterator<_Target,_Container,_Descriptor>::Target SelectiveIterator<_Target,_Container,_Descriptor>::operator*(); \
|
---|
135 | template int SelectiveIterator<_Target,_Container,_Descriptor>::getCount();
|
---|
136 |
|
---|
137 | #endif /* SELECTIVEITERATOR_IMPL_HPP_ */
|
---|