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