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 wpl
00028 {
00029 
00030   namespace tool
00031   {
00032 
00033     namespace internals
00034     {
00035 
00036       template <class I, class P, class B1, class B2>
00037       filter_iterator<I, P, B1, B2>::
00038       filter_iterator(const iterable_type&      i,
00039                       bool                      end):
00040         current_ (end ? i.last_ : i.first_),
00041         iterable_ (&i)
00042       {
00043         if (not end)
00044           skip_non_matching_items();
00045       }
00046 
00047       template <class I, class P, class B1, class B2>
00048       bool
00049       filter_iterator<I, P, B1, B2>::equal(const filter_iterator& rhs) const
00050       {
00051         return current_ == rhs.current_;
00052       }
00053 
00054       template <class I, class P, class B1, class B2>
00055       void
00056       filter_iterator<I, P, B1, B2>::increment()
00057       {
00058         ++current_;
00059         skip_non_matching_items();
00060       }
00061 
00062       template <class I, class P, class B1, class B2>
00063       const typename filter_iterator<I, P, B1, B2>::value_type&
00064       filter_iterator<I, P, B1, B2>::get() const
00065       {
00066         return current_.get();
00067       }
00068 
00069       template <class I, class P, class B1, class B2>
00070       typename filter_iterator<I, P, B1, B2>::value_type&
00071       filter_iterator<I, P, B1, B2>::get()
00072       {
00073         return current_.get();
00074       }
00075 
00076       template <class I, class P, class B1, class B2>
00077       const typename filter_iterator<I, P, B1, B2>::value_type*
00078       filter_iterator<I, P, B1, B2>::get_ptr() const
00079       {
00080         return current_.get_ptr();
00081       }
00082 
00083       template <class I, class P, class B1, class B2>
00084       typename filter_iterator<I, P, B1, B2>::value_type*
00085       filter_iterator<I, P, B1, B2>::get_ptr()
00086       {
00087         return current_.get_ptr();
00088       }
00089 
00090       template <class I, class P, class B1, class B2>
00091       void
00092       filter_iterator<I, P, B1, B2>::skip_non_matching_items()
00093       {
00094         while (current_ != iterable_->last_ and
00095                not static_cast<const P&> (*iterable_)(*current_))
00096           ++current_;
00097       }
00098 
00099     } 
00100 
00101     template <class I, class P, class B>
00102     filter<I, P, B>::filter(const I& first,
00103                             const I& last,
00104                             const P& p):
00105       P (p),
00106       first_ (first),
00107       last_ (last)
00108     {
00109     }
00110 
00111   } 
00112 
00113 } 
00114 
00115 #endif // ! TOOL_FILTER_HXX_