source: src/Descriptors/SelectiveIterator_impl.hpp

Candidate_v1.6.1
Last change on this file was 56f73b, checked in by Frederik Heber <heber@…>, 14 years ago

Added config.h also to all header files, code check test ascertain this in the future.

  • as we want to use config.h to pass stuff such as MEMDEBUG, NDEBUG, LOG_OBSERVER, we have to make sure that it is present in each and every file.
  • split up CodeChecks/testsuite.at: each test has its own .at file.
  • Property mode set to 100644
File size: 4.8 KB
Line 
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
19template<class _Target,
20 class _Container,
21 class _Descriptor>
22SelectiveIterator<_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
31template<class _Target,
32 class _Container,
33 class _Descriptor>
34SelectiveIterator<_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
43template<class _Target,
44 class _Container,
45 class _Descriptor>
46SelectiveIterator<_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
53template<class _Target,
54 class _Container,
55 class _Descriptor>
56SelectiveIterator<_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
66template<class _Target,
67 class _Container,
68 class _Descriptor>
69SelectiveIterator<_Target,_Container,_Descriptor>&
70 SelectiveIterator<_Target,_Container,_Descriptor>::operator++(){
71 ++state;
72 ++index;
73 advanceState();
74 return *this;
75 }
76
77template<class _Target,
78 class _Container,
79 class _Descriptor>
80SelectiveIterator<_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
86template<class _Target,
87 class _Container,
88 class _Descriptor>
89bool
90 SelectiveIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs){
91 return state==rhs.state;
92 }
93
94template<class _Target,
95 class _Container,
96 class _Descriptor>
97bool
98 SelectiveIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveIterator<_Target,_Container,_Descriptor>& rhs){
99 return state!=rhs.state;
100 }
101
102template<class _Target,
103 class _Container,
104 class _Descriptor>
105typename SelectiveIterator<_Target,_Container,_Descriptor>::Target
106 SelectiveIterator<_Target,_Container,_Descriptor>::operator*(){
107 return _take<_Target,value_type>::get(*state);
108 }
109
110template<class _Target,
111 class _Container,
112 class _Descriptor>
113void
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
122template<class _Target,
123 class _Container,
124 class _Descriptor>
125int
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_ */
Note: See TracBrowser for help on using the repository browser.