include/wipal/wifi/frame/filter/windowed_merge.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_WINDOWED_MERGE_HH_
00023 # define WIFI_FRAME_FILTER_WINDOWED_MERGE_HH_
00024 
00025 # include <wipal/tool/iterator.hh>
00026 # include <wipal/tool/iterable.hh>
00027 # include <wipal/wifi/addr_mapping.hh>
00028 
00029 /*---------------------.
00030 | Forward declarations |
00031 `---------------------*/
00032 namespace wifi
00033 {
00034   namespace frame
00035   {
00036     namespace filter
00037     {
00038 
00039       namespace internals
00040       {
00041         template <class, class, class, class, class>
00042         struct windowed_merge_iterator;
00043       }
00044 
00045       template <class, class, class, class>
00046       struct windowed_merge;
00047 
00048     }
00049   }
00050 }
00051 
00052 
00053 /*--------------.
00054 | Virtual types |
00055 `--------------*/
00056 
00057 namespace tool
00058 {
00059 
00060   template <class HT, class I1, class I2, class B1, class B2>
00061   struct types< wifi::frame::filter::internals::
00062                 windowed_merge_iterator<HT, I1, I2, B1, B2> >
00063   {
00064     typedef typename I1::value_type                             value_type;
00065     typedef wifi::frame::filter::windowed_merge<HT, I1, I2, B1> iterable_type;
00066   };
00067 
00068   template <class HT, class I1, class I2, class B>
00069   struct types< wifi::frame::filter::windowed_merge<HT, I1, I2, B> >
00070   {
00071     typedef wifi::frame::filter::internals::
00072       windowed_merge_iterator<HT, I1, I2, B, bottom>
00073       iterator;
00074   };
00075 
00076 } // End of namespace tool.
00077 
00078 
00079 /*-------------.
00080 | Declarations |
00081 `-------------*/
00082 
00083 namespace wifi
00084 {
00085   namespace frame
00086   {
00087     namespace filter
00088     {
00089 
00090       namespace internals
00091       {
00092         template <class HT,
00093                   class I1, class I2,
00094                   class B, class Bottom = tool::bottom>
00095         struct windowed_merge_iterator:
00096           tt_inherit(public tool::iterator,
00097                      windowed_merge_iterator<HT, I1, I2, B, Bottom>)
00098         {
00099 
00101 
00102           typedef tt_get_exact(Bottom, windowed_merge_iterator<HT, I1, I2,
00103                                                                B, Bottom>)
00104                                                         exact_type;
00105           typedef tool::iterator<exact_type>            super_type;
00106           typedef tt_type(value_type, exact_type)       value_type;
00107           typedef tt_type(iterable_type, exact_type)    iterable_type;
00109 
00111           windowed_merge_iterator(const iterable_type& i, bool end);
00112 
00114 
00115           bool                  equal(const windowed_merge_iterator& rhs) const;
00116           void                  increment();
00117 
00118           const value_type&     get() const;
00119           value_type&           get();
00120 
00121           const value_type*     get_ptr() const;
00122           value_type*           get_ptr();
00124 
00125         private:
00126           typedef std::deque<value_type>        window_type;
00127 
00129           int                   first_packet() const;
00130 
00136           template <class I>
00137           static
00138           unsigned
00139           fill(window_type&     w,
00140                I&               i,
00141                const I&         last,
00142                size_t           n);
00143 
00144           typedef typename window_type::iterator        win_iterator;
00145           typedef std::pair<win_iterator, win_iterator> match_type;
00146           typedef boost::optional<match_type>           optional_match;
00147 
00148           optional_match        match();
00149 
00150           enum
00151           {
00152             window_size =
00153 
00154 #ifdef WMERGE_WINDOW_SIZE
00155               WMERGE_WINDOW_SIZE
00156 #else // ! WMERGE_WINDOW_SIZE
00157               3
00158 #endif // WMERGE_WINDOW_SIZE
00159           };
00160 
00161           const iterable_type*  iterable_;
00162 
00163           I1                    next1_;
00164           I2                    next2_;
00165 
00166           window_type           win1_;
00167           window_type           win2_;
00168 
00169           int                   current_;
00170 # ifdef ENABLE_INFO
00171           unsigned              lhs_total_;
00172           unsigned              rhs_total_;
00173           unsigned              shared_;
00174           unsigned              total_;
00175           double                sync_error_;
00176 # endif // ENABLE_INFO
00177         };
00178 
00179       } // End of namespace internals.
00180 
00181 
00182       template <class HeaderType,
00183                 class InputIterator1,
00184                 class InputIterator2,
00185                 class Bottom = tool::bottom>
00186       struct windowed_merge:
00187         tt_inherit(public tool::iterable, windowed_merge<HeaderType,
00188                                                          InputIterator1,
00189                                                          InputIterator2,
00190                                                          Bottom>)
00191       {
00192         windowed_merge(const InputIterator1& first1,
00193                        const InputIterator1& last1,
00194                        const InputIterator2& first2,
00195                        const InputIterator2& last2,
00196                        tool::endian::endianness phy_end);
00197 
00198       private:
00199         tool::endian::endianness        phy_end_;
00200 
00201         InputIterator1                  first1_;
00202         InputIterator1                  last1_;
00203         InputIterator2                  first2_;
00204         InputIterator2                  last2_;
00205 
00206         friend
00207           class internals::windowed_merge_iterator<HeaderType,
00208                                                    InputIterator1,
00209                                                    InputIterator2,
00210                                                    Bottom,
00211                                                    tool::bottom>;
00212       };
00213 
00214     } // End of namespace wifi::frame::filter.
00215 
00216   } // End of namespace wifi::frame.
00217 
00218 } // End of namespace wifi.
00219 
00220 # include "windowed_merge.hxx"
00221 
00222 #endif // ! WIFI_FRAME_FILTER_WINDOWED_MERGE_HH_

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