include/wipal/tool/filter.hxx

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_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   } // End of namespace internals.
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 } // End of namespace tool.
00108 
00109 #endif // ! TOOL_FILTER_HXX_

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