00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILTER_WINDOWED_MERGE_HH_
00023 # define 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 namespace wpl
00030 {
00031
00032
00033
00034
00035 namespace filter
00036 {
00037 namespace internals
00038 {
00039 template <class, class, class, class, class>
00040 struct windowed_merge_iterator;
00041 }
00042
00043 template <class, class, class, class>
00044 struct windowed_merge;
00045 }
00046
00047
00048
00049
00050
00051
00052 namespace tool
00053 {
00054
00055 template <class HT, class I1, class I2, class B1, class B2>
00056 struct types< wpl::filter::internals::
00057 windowed_merge_iterator<HT, I1, I2, B1, B2> >
00058 {
00059 typedef typename I1::value_type value_type;
00060 typedef wpl::filter::windowed_merge<HT, I1, I2, B1> iterable_type;
00061 };
00062
00063 template <class HT, class I1, class I2, class B>
00064 struct types< wpl::filter::windowed_merge<HT, I1, I2, B> >
00065 {
00066 typedef wpl::filter::internals::
00067 windowed_merge_iterator<HT, I1, I2, B, bottom>
00068 iterator;
00069 };
00070
00071 }
00072
00073
00074
00075
00076
00077
00078 namespace filter
00079 {
00080
00081 namespace internals
00082 {
00083 template <class HT,
00084 class I1, class I2,
00085 class B, class Bottom = tool::bottom>
00086 struct windowed_merge_iterator:
00087 WP_INHERIT(public tool::valued_iterator,
00088 windowed_merge_iterator<HT, I1, I2, B, Bottom>)
00089 {
00090
00092
00093 typedef WP_GET_EXACT(Bottom, windowed_merge_iterator<HT, I1, I2,
00094 B, Bottom>)
00095 exact_type;
00096 typedef tool::iterator<exact_type> super_type;
00097 typedef WP_TYPE(value_type, exact_type) value_type;
00098 typedef WP_TYPE(iterable_type, exact_type) iterable_type;
00100
00102 windowed_merge_iterator(const iterable_type& i, bool end);
00103
00105
00106 bool equal(const windowed_merge_iterator& rhs) const;
00107 void increment();
00109
00110 private:
00111 typedef std::deque<typename I1::value_type> window1_type;
00112 typedef std::deque<typename I2::value_type> window2_type;
00113
00115 int first_packet() const;
00116
00118 void update_current();
00119
00125 template <class WindowType, class I>
00126 static
00127 unsigned
00128 fill(WindowType& w,
00129 I& i,
00130 const I& last,
00131 size_t n);
00132
00133 typedef typename window1_type::iterator win1_iterator;
00134 typedef typename window2_type::iterator win2_iterator;
00135 typedef std::pair<win1_iterator, win2_iterator> match_type;
00136 typedef boost::optional<match_type> optional_match;
00137
00138 optional_match match();
00139
00140 enum
00141 {
00142 window_size =
00143
00144 #ifdef WP_WMERGE_WINDOW_SIZE
00145 WP_WMERGE_WINDOW_SIZE
00146 #else // ! WP_WMERGE_WINDOW_SIZE
00147 3
00148 #endif // WP_WMERGE_WINDOW_SIZE
00149 };
00150
00151 const iterable_type* iterable_;
00152
00153 I1 next1_;
00154 I2 next2_;
00155
00156 window1_type win1_;
00157 window2_type win2_;
00158
00159 int current_;
00160 # ifdef WP_ENABLE_INFO
00161 unsigned lhs_total_;
00162 unsigned rhs_total_;
00163 unsigned shared_;
00164 unsigned total_;
00165 double sync_error_;
00166 # endif // WP_ENABLE_INFO
00167 };
00168
00169 }
00170
00171
00172 template <class HeaderType,
00173 class InputIterator1,
00174 class InputIterator2,
00175 class Bottom = tool::bottom>
00176 struct windowed_merge:
00177 WP_INHERIT(public tool::iterable, windowed_merge<HeaderType,
00178 InputIterator1,
00179 InputIterator2,
00180 Bottom>)
00181 {
00182 windowed_merge(const InputIterator1& first1,
00183 const InputIterator1& last1,
00184 const InputIterator2& first2,
00185 const InputIterator2& last2,
00186 const unsigned precision,
00187 const tool::end::endianness phy_end,
00188 const bool pcap_tstamps);
00189
00190 private:
00191 unsigned precision_;
00192 tool::end::endianness phy_end_;
00193 bool pcap_tstamps_;
00194
00195 InputIterator1 first1_;
00196 InputIterator1 last1_;
00197 InputIterator2 first2_;
00198 InputIterator2 last2_;
00199
00200 friend
00201 class internals::windowed_merge_iterator<HeaderType,
00202 InputIterator1,
00203 InputIterator2,
00204 Bottom,
00205 tool::bottom>;
00206 };
00207
00208 }
00209
00210 }
00211
00212 # include "windowed_merge.hxx"
00213
00214 #endif // ! FILTER_WINDOWED_MERGE_HH_