include/trace-tools/wifi/frame/unique_id.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_UNIQUE_ID_HXX_
00023 # define WIFI_FRAME_UNIQUE_ID_HXX_
00024 
00025 # include "unique_id.hh"
00026 
00027 # include <trace-tools/prism_header.hh>
00028 
00029 namespace wifi
00030 {
00031 
00032   namespace frame
00033   {
00034 
00035     namespace internals
00036     {
00037 
00038       template <class Tag>
00039       bool
00040       empty<Tag>::operator < (const empty&) const
00041       {
00042         return false;
00043       }
00044 
00045       template <class Tag>
00046       bool
00047       empty<Tag>::operator == (const empty&) const
00048       {
00049         return true;
00050       }
00051 
00052       template <class Tag>
00053       bool
00054       empty<Tag>::operator != (const empty&) const
00055       {
00056         return false;
00057       }
00058 
00059       template <class T, class Tag>
00060       adapter<T, Tag>::adapter(const T& v): v_ (v)
00061       {
00062       }
00063 
00064       template <class T, class Tag>
00065       bool
00066       adapter<T, Tag>::operator < (const adapter& rhs) const
00067       {
00068         return v_ < rhs.v_;
00069       }
00070 
00071       template <class T, class Tag>
00072       bool
00073       adapter<T, Tag>::operator == (const adapter& rhs) const
00074       {
00075         return v_ == rhs.v_;
00076       }
00077 
00078       template <class T, class Tag>
00079       bool
00080       adapter<T, Tag>::operator != (const adapter& rhs) const
00081       {
00082         return not (*this == rhs);
00083       }
00084 
00085     } // End of namespace wifi::frame::internals.
00086 
00087     /*----------------------.
00088     | uniquely_identifiable |
00089     `----------------------*/
00090 
00091     template <class Id1, class Id2, class Id3, class Id4>
00092     unique_id<Id1, Id2, Id3, Id4>::unique_id(unsigned   frame_id,
00093                                              const Id1& id1,
00094                                              const Id2& id2,
00095                                              const Id3& id3,
00096                                              const Id4& id4):
00097       Id1 (id1),
00098       Id2 (id2),
00099       Id3 (id3),
00100       Id4 (id4),
00101       frame_id_ (frame_id)
00102     {
00103     }
00104 
00105     template <class Id1, class Id2, class Id3, class Id4>
00106     bool
00107     unique_id<Id1, Id2, Id3, Id4>::operator < (const unique_id& rhs) const
00108     {
00109       const Id1&   l1 = id1(),   r1 = rhs.id1();
00110       const Id2&   l2 = id2(),   r2 = rhs.id2();
00111       const Id3&   l3 = id3(),   r3 = rhs.id3();
00112       const Id4&   l4 = id4(),   r4 = rhs.id4();
00113 
00114       if (l1 != r1)
00115         return l1 < r1;
00116       if (l2 != r2)
00117         return l2 < r2;
00118       if (l3 != r3)
00119         return l3 < r3;
00120       return l4 < r4;
00121     }
00122 
00123     template <class Id1, class Id2, class Id3, class Id4>
00124     bool
00125     unique_id<Id1, Id2, Id3, Id4>::operator == (const unique_id& rhs) const
00126     {
00127       return (id1() == rhs.id1() and id2() == rhs.id2() and
00128               id3() == rhs.id3() and id4() == rhs.id4());
00129     }
00130 
00131     template <class Id1, class Id2, class Id3, class Id4>
00132     bool
00133     unique_id<Id1, Id2, Id3, Id4>::operator != (const unique_id& rhs) const
00134     {
00135       return not (*this == rhs);
00136     }
00137 
00138     template <class Id1, class Id2, class Id3, class Id4>
00139     std::ostream&
00140     unique_id<Id1, Id2, Id3, Id4>::print(std::ostream& os) const
00141     {
00142       return os << frame_id_;
00143     }
00144 
00145     template <class Id1, class Id2, class Id3, class Id4>
00146     unsigned
00147     unique_id<Id1, Id2, Id3, Id4>::frame_id() const
00148     {
00149       return frame_id_;
00150     }
00151 
00152     template <class Id1, class Id2, class Id3, class Id4>
00153     const Id1&
00154     unique_id<Id1, Id2, Id3, Id4>::id1() const
00155     {
00156       return static_cast<const Id1&> (*this);
00157     }
00158 
00159     template <class Id1, class Id2, class Id3, class Id4>
00160     const Id2&
00161     unique_id<Id1, Id2, Id3, Id4>::id2() const
00162     {
00163       return static_cast<const Id2&> (*this);
00164     }
00165 
00166     template <class Id1, class Id2, class Id3, class Id4>
00167     const Id3&
00168     unique_id<Id1, Id2, Id3, Id4>::id3() const
00169     {
00170       return static_cast<const Id3&> (*this);
00171     }
00172 
00173     template <class Id1, class Id2, class Id3, class Id4>
00174     const Id4&
00175     unique_id<Id1, Id2, Id3, Id4>::id4() const
00176     {
00177       return static_cast<const Id4&> (*this);
00178     }
00179 
00180     template <class Id1, class Id2, class Id3, class Id4>
00181     std::ostream&
00182     operator << (std::ostream& os, const unique_id<Id1, Id2, Id3, Id4>& ui)
00183     {
00184       return ui.print(os);
00185     }
00186 
00187     namespace internals
00188     {
00189 
00190       inline
00191       bool
00192       make_unique_id_handle_prism(const void*&  frame,
00193                                   size_t&       caplen,
00194                                   const pcapxx::frame_descriptor& desc,
00195                                   bool          noise_means_error)
00196       {
00197         const pcapxx::pkthdr*           pcap = desc.pcap_header().get();
00198         const prism::header* const      prism =
00199           reinterpret_cast<const prism::header*> (desc.bytes().get());
00200 
00201         if (pcap->caplen <= sizeof (prism::header))
00202           return false;
00203 
00204         if (noise_means_error and prism->noise.data)
00205           return false;
00206 
00207         frame = prism + 1;
00208         caplen = pcap->caplen - sizeof (*prism);
00209         return true;
00210       }
00211 
00212     } // End of namespace wifi::frame::internals.
00213 
00214 
00215   } // End of namespace wifi::frame.
00216 
00217 } // End of namespace wifi.
00218 
00219 #endif // ! WIFI_FRAME_UNIQUE_ID_HXX_

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