/* * SelectiveConstIterator_impl.hpp * * Created on: Mar 19, 2013 * Author: heber */ #ifndef SELECTIVECONSTITERATOR_IMPL_HPP_ #define SELECTIVECONSTITERATOR_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Helpers/helpers.hpp" template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _Container &_content) : descr(_descr.get_impl()), index(0), content(_content) { state = content.begin(); advanceState(); } template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _Container &_content, SelectiveConstIterator<_Target,_Container,_Descriptor>::Iter _state) : state(_state), descr(_descr.get_impl()), index(0), content(_content) { advanceState(); } template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs) : state(rhs.state), descr(rhs.descr), index(rhs.index), content(rhs.content) {} template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs) { if(&rhs!=this){ state=rhs.state; descr=rhs.descr; index=rhs.index; } return *this; } template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(){ ++state; ++index; advanceState(); return *this; } template SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int){ SelectiveConstIterator<_Target,_Container,_Descriptor> res = SelectiveConstIterator<_Target,_Container,_Descriptor>(*this); ++(*this); return res; } template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){ return state==rhs.state; } template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){ return state!=rhs.state; } template typename SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const SelectiveConstIterator<_Target,_Container,_Descriptor>::operator*(){ return _take<_Target,value_type>::get(*state); } template void SelectiveConstIterator<_Target,_Container,_Descriptor>::advanceState(){ // go forward until we have a matching atom or the end is reached while((state!=content.end()) && (!descr->predicate(*state))){ ++state; ++index; } } template int SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount(){ return index; } #define CONSTRUCT_SELECTIVE_CONST_ITERATOR(_Target,_Container,_Descriptor) \ template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&); \ template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&, SelectiveConstIterator<_Target,_Container,_Descriptor>::Iter); \ template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \ template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \ template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(); \ template SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int); \ template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \ template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \ template SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const SelectiveConstIterator<_Target,_Container,_Descriptor>::operator*(); \ template int SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount(); #endif /* SELECTIVECONSTITERATOR_IMPL_HPP_ */