include/wipal/wifi/frame/filter/intersector.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 WIFI_FRAME_FILTER_INTERSECTOR_HH_
00023 # define WIFI_FRAME_FILTER_INTERSECTOR_HH_
00024 
00025 # include <utility>
00026 
00027 # include <wipal/tool/hash.hh>
00028 # include <wipal/tool/valued_iterator.hh>
00029 # include <wipal/tool/microseconds.hh>
00030 # include <wipal/tool/iterable.hh>
00031 # include <wipal/wifi/addr_mapping.hh>
00032 
00033 # include "intersector_fwd.hh"
00034 
00035 namespace tool
00036 {
00037 
00038   template <class I1, class I2, class B1, class B2>
00039   struct types< wifi::frame::filter::internals::intersector_iterator<I1, I2,
00040                                                                      B1, B2> >
00041   {
00042     typedef
00043       std::pair<typename I1::value_type, typename I2::value_type>
00044       value_type;
00045 
00046     typedef
00047       wifi::frame::filter::intersector<I1, I2, B1>
00048       iterable_type;
00049   };
00050 
00051   template <class I1, class I2, class B>
00052   struct types< wifi::frame::filter::intersector<I1, I2, B> >
00053   {
00054     typedef
00055       wifi::frame::filter::internals::intersector_iterator<I1, I2, B, bottom>
00056       iterator;
00057   };
00058 
00059 } // End of namespace tool.
00060 
00061 namespace wifi
00062 {
00063   namespace frame
00064   {
00065     namespace filter
00066     {
00067 
00068       namespace internals
00069       {
00070         template <class I1, class I2, class B, class Bottom = tool::bottom>
00071         struct intersector_iterator:
00072           tt_inherit(public tool::valued_iterator,
00073                      intersector_iterator<I1, I2, B, Bottom>)
00074         {
00075 
00077 
00078           typedef tt_get_exact(Bottom, intersector_iterator<I1, I2, B, Bottom>)
00079                                                         exact_type;
00080           typedef tool::valued_iterator<exact_type>     super_type;
00081           typedef tt_type(value_type, exact_type)       value_type;
00082           typedef tt_type(iterable_type, exact_type)    iterable_type;
00084 
00086           intersector_iterator(const iterable_type& i, bool end);
00087 
00089 
00090           bool  equal(const intersector_iterator& rhs) const;
00091           void  increment();
00093 
00094         private:
00095 
00096 # ifdef DONT_USE_HASH
00097           enum
00098           {
00109             arrivals_max_size = 1 << 20
00110           };
00111 
00112           typedef std::set<typename I1::value_type> arrivals1_type;
00113           typedef std::set<typename I2::value_type> arrivals2_type;
00114 # else
00115           enum
00116           {
00126             arrivals_max_size = 1 << 20,
00127 
00136             hash_bucket_count = arrivals_max_size * 4
00137           };
00138 
00139           typedef tool::hash_set<typename I1::value_type> arrivals1_type;
00140           typedef tool::hash_set<typename I2::value_type> arrivals2_type;
00141 # endif
00142 
00143           template <bool SwapResult, class ArrType, class RHSArrType>
00144           bool
00145           check(I1&             frm,
00146                 ArrType&        frm_arrivals,
00147                 RHSArrType&     rhs_arrivals);
00148 
00149           template <class ArrType>
00150           void
00151           cleanup_arrivals(const typename ArrType::iterator&    frame,
00152                            ArrType&                             arrivals);
00153 
00154 
00155           const iterable_type*  iterable_;
00156 
00157           I1                    next1_;
00158           I2                    next2_;
00159 
00160           arrivals1_type        arrivals1_;
00161           arrivals2_type        arrivals2_;
00162           tool::microseconds    last_arrival_[2];
00163         };
00164 
00165       } // End of namespace internals.
00166 
00167 
00168       template <class InputIterator1,
00169                 class InputIterator2,
00170                 class Bottom = tool::bottom>
00171       struct intersector:
00172         tt_inherit(public tool::iterable, intersector<InputIterator1,
00173                                                       InputIterator2,
00174                                                       Bottom>)
00175       {
00176         intersector(const InputIterator1& first1, const InputIterator1& last1,
00177                     const InputIterator2& first2, const InputIterator2& last2);
00178 
00179       private:
00180         InputIterator1  first1_;
00181         InputIterator1  last1_;
00182         InputIterator2  first2_;
00183         InputIterator2  last2_;
00184 
00185         friend
00186           class internals::intersector_iterator<InputIterator1,
00187                                                 InputIterator2,
00188                                                 Bottom,
00189                                                 tool::bottom>;
00190       };
00191 
00202       template <class UniqueId,
00203                 class HeaderType,
00204                 template <class, class, class> class Intersector,
00205                 class I1, class I2, class F>
00206       void
00207       provide_intersector(const I1& first1, const I1& last1,
00208                           const I2& first2, const I2& last2,
00209                           addr_mapping& mapping,
00210                           F&                            func,
00211                           bool                          filter_prism,
00212                           tool::endian::endianness      phy_end);
00213 
00214     } // End of namespace wifi::frame::filter.
00215 
00216   } // End of namespace wifi::frame.
00217 
00218 } // End of namespace wifi.
00219 
00220 # include "intersector.hxx"
00221 
00222 #endif // ! WIFI_FRAME_FILTER_INTERSECTOR_HH_

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