00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_FILTER_FAST_INTERSECTOR_HXX_
00023 # define WIFI_FRAME_FILTER_FAST_INTERSECTOR_HXX_
00024
00025 # include <iostream>
00026
00027 # include "fast_intersector.hh"
00028
00029 # include <trace-tools/wifi/frame/filter/non_noisy_prism.hh>
00030 # include <trace-tools/wifi/frame/filter/uniquely_identifiable.hh>
00031
00032 namespace wifi
00033 {
00034 namespace frame
00035 {
00036 namespace filter
00037 {
00038
00039 namespace internals
00040 {
00041
00042 template <class I1, class I2, class B1, class B2>
00043 fast_intersector_iterator<I1, I2, B1, B2>::
00044 fast_intersector_iterator(const iterable_type& i, bool end):
00045 super_type (),
00046 iterable_ (&i),
00047 next_ (end ? i.last_ : i.first_)
00048 {
00049 if (not end)
00050 increment();
00051 }
00052
00053 template <class I1, class I2, class B1, class B2>
00054 bool
00055 fast_intersector_iterator<I1, I2, B1, B2>::
00056 equal(const fast_intersector_iterator& rhs) const
00057 {
00058 if (not rhs.value())
00059 return not this->value();
00060 return next_ == rhs.next_;
00061 }
00062
00063 template <class I1, class I2, class B1, class B2>
00064 void
00065 fast_intersector_iterator<I1, I2, B1, B2>::increment()
00066 {
00067 const I1& last = this->iterable_->last_;
00068 bool found (false);
00069
00070 while (next_ != last and not found)
00071 {
00072 found = check();
00073 ++next_;
00074 }
00075
00076 if (not found)
00077 this->value() = boost::none_t ();
00078 }
00079
00080 template <class I1, class I2, class B1, class B2>
00081 bool
00082 fast_intersector_iterator<I1, I2, B1, B2>::check()
00083 {
00084 typedef typename iterable_type::arrivals_type arrivals_type;
00085 typedef typename arrivals_type::const_iterator iterator;
00086
00087 const arrivals_type& arrivals = iterable_->arrivals_;
00088 const iterator i = arrivals.find(*next_);
00089
00090 if (i == arrivals.end())
00091 return false;
00092
00093 if (i->microseconds() < last_)
00094 {
00095 std::cerr << "WARNING: Unique frame " << i->frame_id()
00096 << " (" << i->microseconds() << " us) anterior to "
00097 "previous intersection (" << last_ << " us), "
00098 "ignoring.\n"
00099 "WARNING: Probably this is due to previously "
00100 "ignored frames." << std::endl;
00101 return false;
00102 }
00103
00104 last_ = i->microseconds();
00105 this->value() = value_type (*next_, *i);
00106 return true;
00107 }
00108
00109 }
00110
00111
00112 template <class I1, class I2, class B>
00113 fast_intersector<I1, I2, B>::
00114 fast_intersector(const I1& first1, const I1& last1,
00115 const I2& first2, const I2& last2):
00116 first_ (first1),
00117 last_ (last1)
00118 # ifndef DONT_USE_HASH
00119 , arrivals_ (hash_bucket_count)
00120 # endif
00121 {
00122 for (I2 i = first2; i != last2; ++i)
00123 {
00124 typedef typename arrivals_type::iterator iterator;
00125
00126 std::pair<iterator, bool> r = arrivals_.insert(*i);
00127
00128 if (not r.second)
00129 std::cerr << "WARNING: Unique frame " << r.first->frame_id()
00130 << " (" << r.first->microseconds() << " us) is not "
00131 "really unique. Frame " << i->frame_id() << " ("
00132 << i->microseconds() << " us) is a duplicate. "
00133 "Ignoring the last frame." << std::endl;
00134 }
00135 }
00136
00137 }
00138
00139 }
00140
00141 }
00142
00143 #endif // ! WIFI_FRAME_FILTER_FAST_INTERSECTOR_HXX_