include/wipal/tool/filter.hh

00001 /*
00002  * WiPal - A library and a set of tools to manipulate wireless traces.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
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   | Forward declarations |
00033   `---------------------*/
00034 
00035   namespace internals
00036   {
00037 
00038     template <class I, class P, class B1, class B2>
00039     struct filter_iterator;
00040 
00041   } // End of namespace tool::internals.
00042 
00043   template <class I, class P, class B>
00044   struct filter;
00045 
00046   /*--------------.
00047   | Virtual types |
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   | Declarations |
00065   `-------------*/
00066 
00067   namespace internals
00068   {
00069 
00070     template <class I, class P, class B, class Bottom = bottom>
00071     struct filter_iterator:
00072       tt_inherit(public tool::iterator, filter_iterator<I, P, B, Bottom>)
00073     {
00075 
00076       typedef tt_get_exact(Bottom, filter_iterator<I, P, B, Bottom>)
00077                                                         exact_type;
00078       typedef tool::iterator<exact_type>                super_type;
00079       typedef tt_type(value_type, exact_type)           value_type;
00080       typedef tt_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   } // End of namespace internals.
00106 
00107   template <class InputIterator,
00108             class Predicate,
00109             class Bottom = tool::bottom>
00110   struct filter:
00111     tt_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 } // End of namespace tool.
00131 
00132 # include "filter.hxx"
00133 
00134 #endif // ! TOOL_FILTER_HH_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4