[feb5d0] | 1 | /*
|
---|
| 2 | * SelectiveConstIterator_impl.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Mar 19, 2013
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef SELECTIVECONSTITERATOR_IMPL_HPP_
|
---|
| 9 | #define SELECTIVECONSTITERATOR_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 | SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _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 | SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _Container &_content, SelectiveConstIterator<_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 | SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_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 | SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_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 | SelectiveConstIterator<_Target,_Container,_Descriptor>&
|
---|
| 70 | SelectiveConstIterator<_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 | SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int){
|
---|
| 81 | SelectiveConstIterator<_Target,_Container,_Descriptor> res = SelectiveConstIterator<_Target,_Container,_Descriptor>(*this);
|
---|
| 82 | ++(*this);
|
---|
| 83 | return res;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | template<class _Target,
|
---|
| 87 | class _Container,
|
---|
| 88 | class _Descriptor>
|
---|
| 89 | bool
|
---|
| 90 | SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){
|
---|
| 91 | return state==rhs.state;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | template<class _Target,
|
---|
| 95 | class _Container,
|
---|
| 96 | class _Descriptor>
|
---|
| 97 | bool
|
---|
| 98 | SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){
|
---|
| 99 | return state!=rhs.state;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | template<class _Target,
|
---|
| 103 | class _Container,
|
---|
| 104 | class _Descriptor>
|
---|
| 105 | typename SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const
|
---|
| 106 | SelectiveConstIterator<_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 | SelectiveConstIterator<_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 | SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount(){
|
---|
| 127 | return index;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | #define CONSTRUCT_SELECTIVE_CONST_ITERATOR(_Target,_Container,_Descriptor) \
|
---|
| 132 | template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&); \
|
---|
| 133 | template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&, SelectiveConstIterator<_Target,_Container,_Descriptor>::Iter); \
|
---|
| 134 | template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
|
---|
| 135 | template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
|
---|
| 136 | template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(); \
|
---|
| 137 | template SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int); \
|
---|
| 138 | template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
|
---|
| 139 | template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
|
---|
| 140 | template SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const SelectiveConstIterator<_Target,_Container,_Descriptor>::operator*(); \
|
---|
| 141 | template int SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount();
|
---|
| 142 |
|
---|
| 143 | #endif /* SELECTIVECONSTITERATOR_IMPL_HPP_ */
|
---|