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_HH_
00023 # define TOOL_FILTER_HH_
00024
00025 # include <wipal/tool/iterator.hh>
00026 # include <wipal/tool/iterable.hh>
00027
00028 namespace tool
00029 {
00030
00031
00032
00033
00034
00035 namespace internals
00036 {
00037
00038 template <class I, class P, class B1, class B2>
00039 struct filter_iterator;
00040
00041 }
00042
00043 template <class I, class P, class B>
00044 struct filter;
00045
00046
00047
00048
00049
00050 template <class I, class P, class B1, class B2>
00051 struct types< internals::filter_iterator<I, P, B1, B2> >
00052 {
00053 typedef typename I::value_type value_type;
00054 typedef filter<I, P, B1> iterable_type;
00055 };
00056
00057 template <class I, class P, class B>
00058 struct types< filter<I, P, B> >
00059 {
00060 typedef internals::filter_iterator<I, P, B, bottom> iterator;
00061 };
00062
00063
00064
00065
00066
00067 namespace internals
00068 {
00069
00070 template <class I, class P, class B, class Bottom = bottom>
00071 struct filter_iterator:
00072 wp_inherit(public tool::iterator, filter_iterator<I, P, B, Bottom>)
00073 {
00075
00076 typedef wp_get_exact(Bottom, filter_iterator<I, P, B, Bottom>)
00077 exact_type;
00078 typedef tool::iterator<exact_type> super_type;
00079 typedef wp_type(value_type, exact_type) value_type;
00080 typedef wp_type(iterable_type, exact_type) iterable_type;
00082
00084 filter_iterator(const iterable_type& i, bool end);
00085
00087
00088 bool equal(const filter_iterator& rhs) const;
00089 void increment();
00090
00091 const value_type& get() const;
00092 value_type& get();
00093
00094 const value_type* get_ptr() const;
00095 value_type* get_ptr();
00097
00098 private:
00099 void skip_non_matching_items();
00100
00101 I current_;
00102 const iterable_type* iterable_;
00103 };
00104
00105 }
00106
00107 template <class InputIterator,
00108 class Predicate,
00109 class Bottom = tool::bottom>
00110 struct filter:
00111 wp_inherit(public tool::iterable, filter<InputIterator,
00112 Predicate,
00113 Bottom>),
00114 public Predicate
00115 {
00116 filter(const InputIterator& first, const InputIterator& last,
00117 const Predicate& p = Predicate ());
00118
00119 private:
00120 InputIterator first_;
00121 InputIterator last_;
00122
00123 friend
00124 class internals::filter_iterator<InputIterator,
00125 Predicate,
00126 Bottom,
00127 tool::bottom>;
00128 };
00129
00130 }
00131
00132 # include "filter.hxx"
00133
00134 #endif