include/trace-tools/wifi/frame/filter/unique_synchronizer.hxx

00001 /*
00002  * trace-tools - 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_SYNCHRONIZER_HXX_
00023 # define WIFI_FRAME_FILTER_SYNCHRONIZER_HXX_
00024 
00025 # include <trace-tools/tool/linear_regression.hh>
00026 
00027 # include "unique_synchronizer.hh"
00028 
00029 namespace wifi
00030 {
00031   namespace frame
00032   {
00033     namespace filter
00034     {
00035 
00036       inline
00037       synchronized_unique_frame::
00038       synchronized_unique_frame(const tool::microseconds& timestamp1,
00039                                 const tool::microseconds& timestamp2,
00040                                 const coefs_type& c):
00041         t1 (timestamp1),
00042         t2 (timestamp2),
00043         coefs (c)
00044       {
00045       }
00046 
00047       inline
00048       bool
00049       synchronized_unique_frame::
00050       operator == (const synchronized_unique_frame& rhs) const
00051       {
00052         return t1 == rhs.t1 and t2 == rhs.t2 and coefs == rhs.coefs;
00053       }
00054 
00055       inline
00056       bool
00057       synchronized_unique_frame::
00058       operator != (const synchronized_unique_frame& rhs) const
00059       {
00060         return not (*this == rhs);
00061       }
00062 
00063       namespace internals
00064       {
00065 
00066         template <class I, class B1, class B2>
00067         u_sync_iterator<I, B1, B2>::
00068         u_sync_iterator(unique_synchronizer<I, B1>& i, bool end):
00069           i_ (&i),
00070           next_wpos_ (0),
00071           v_ ()
00072         {
00073           if (not end)
00074             increment();
00075         }
00076 
00077         template <class I, class B1, class B2>
00078         bool
00079         u_sync_iterator<I, B1, B2>::equal(const exact_type& rhs) const
00080         {
00081           return
00082             i_ == rhs.i_ and next_wpos_ == rhs.next_wpos_ and v_ == rhs.v_;
00083         }
00084 
00085         template <class I, class B1, class B2>
00086         void
00087         u_sync_iterator<I, B1, B2>::increment()
00088         {
00089           typedef typename value_type::impl_type        impl_type;
00090 
00091           const I&      last = i_->last_;
00092           I&            next = i_->next_;
00093           const size_t  window_size = next->size();
00094 
00095           if (next_wpos_ == window_size and next == last)
00096             {
00097               next_wpos_ = 0;
00098               v_ = boost::none_t ();
00099               return;
00100             }
00101 
00102           v_ = value_type (next[next_wpos_].first.microseconds(),
00103                            next[next_wpos_].second.microseconds(),
00104                            // FIXME: TODO: This works around the previous
00105                            // FIXME: changes in intersector.  One should
00106                            // FIXME: adapt the code so we do call the linear
00107                            // FIXME: regression algorithm.
00108                            std::make_pair(0, 0));
00109 
00110                            // FIXME: Original code follows.
00111 //                         tool::linear_regression<impl_type>(next->begin(),
00112 //                                                            next->end()));
00113 
00114           if (next_wpos_ < window_size / 2 or next == last)
00115             ++next_wpos_;
00116           else
00117             ++next;
00118         }
00119 
00120         template <class I, class B1, class B2>
00121         const typename u_sync_iterator<I, B1, B2>::value_type&
00122         u_sync_iterator<I, B1, B2>::get() const
00123         {
00124           return v_.get();
00125         }
00126 
00127         template <class I, class B1, class B2>
00128         const typename u_sync_iterator<I, B1, B2>::value_type*
00129         u_sync_iterator<I, B1, B2>::get_ptr() const
00130         {
00131           return v_.get_ptr();
00132         }
00133 
00134       } // End of namespace wifi::frame::filter::internals.
00135 
00136 
00137       template <class I, class B>
00138       unique_synchronizer<I, B>::
00139       unique_synchronizer(const I& first, const I& last):
00140         next_ (first),
00141         last_ (last)
00142       {
00143       }
00144 
00145     } // End of namespace wifi::frame::filter.
00146   } // End of namespace wifi::frame.
00147 } // End of namespace wifi.
00148 
00149 #endif // ! WIFI_FRAME_FILTER_SYNCHRONIZER_HXX_

Generated on Wed Sep 12 16:02:47 2007 for trace-tools by  doxygen 1.5.3