00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TOOL_FILTER_HXX_
00023 # define TOOL_FILTER_HXX_
00024
00025 # include "filter.hh"
00026
00027 namespace tool
00028 {
00029
00030 namespace internals
00031 {
00032
00033 template <class I, class P, class B1, class B2>
00034 filter_iterator<I, P, B1, B2>::filter_iterator(const iterable_type& i,
00035 bool end):
00036 current_ (end ? i.last_ : i.first_),
00037 iterable_ (&i)
00038 {
00039 if (not end)
00040 skip_non_matching_items();
00041 }
00042
00043 template <class I, class P, class B1, class B2>
00044 bool
00045 filter_iterator<I, P, B1, B2>::equal(const filter_iterator& rhs) const
00046 {
00047 return current_ == rhs.current_;
00048 }
00049
00050 template <class I, class P, class B1, class B2>
00051 void
00052 filter_iterator<I, P, B1, B2>::increment()
00053 {
00054 ++current_;
00055 skip_non_matching_items();
00056 }
00057
00058 template <class I, class P, class B1, class B2>
00059 const typename filter_iterator<I, P, B1, B2>::value_type&
00060 filter_iterator<I, P, B1, B2>::get() const
00061 {
00062 return current_.get();
00063 }
00064
00065 template <class I, class P, class B1, class B2>
00066 typename filter_iterator<I, P, B1, B2>::value_type&
00067 filter_iterator<I, P, B1, B2>::get()
00068 {
00069 return current_.get();
00070 }
00071
00072 template <class I, class P, class B1, class B2>
00073 const typename filter_iterator<I, P, B1, B2>::value_type*
00074 filter_iterator<I, P, B1, B2>::get_ptr() const
00075 {
00076 return current_.get_ptr();
00077 }
00078
00079 template <class I, class P, class B1, class B2>
00080 typename filter_iterator<I, P, B1, B2>::value_type*
00081 filter_iterator<I, P, B1, B2>::get_ptr()
00082 {
00083 return current_.get_ptr();
00084 }
00085
00086 template <class I, class P, class B1, class B2>
00087 void
00088 filter_iterator<I, P, B1, B2>::skip_non_matching_items()
00089 {
00090 while (current_ != iterable_->last_ and
00091 not static_cast<const P&> (*iterable_)(*current_))
00092 ++current_;
00093 }
00094
00095 }
00096
00097 template <class I, class P, class B>
00098 filter<I, P, B>::filter(const I& first,
00099 const I& last,
00100 const P& p):
00101 P (p),
00102 first_ (first),
00103 last_ (last)
00104 {
00105 }
00106
00107 }
00108
00109 #endif // ! TOOL_FILTER_HXX_