include/wipal/wifi/frame/unique_id/unique_id.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_UNIQUE_ID_HH_
00023 # define WIFI_FRAME_UNIQUE_ID_HH_
00024 
00025 # include <ostream>
00026 # include <boost/optional.hpp>
00027 
00028 # include <wipal/pcap/frame_descriptor.hh>
00029 # include <wipal/wifi/addr_mapping.hh>
00030 # include <wipal/tool/hash.hh>
00031 
00032 namespace wifi
00033 {
00034 
00035   namespace frame
00036   {
00037 
00039     namespace internals
00040     {
00041       struct tag1 {};
00042       struct tag2 {};
00043       struct tag3 {};
00044       struct tag4 {};
00045 
00046       template <class Tag>
00047       struct empty
00048       {
00049         bool operator  < (const empty& rhs) const;
00050         bool operator == (const empty& rhs) const;
00051         bool operator != (const empty& rhs) const;
00052       };
00053 
00054       template <class T, class Tag = tag1>
00055       struct adapter
00056       {
00057         adapter(const T& v = T());
00058 
00059         bool operator  < (const adapter& rhs) const;
00060         bool operator == (const adapter& rhs) const;
00061         bool operator != (const adapter& rhs) const;
00062 
00063         const T&        value() const;
00064         T&              value();
00065 
00066       private:
00067         T       v_;
00068       };
00069 
00070     } // End of namespace wifi::frame::internals.
00071 
00080     template < class Id1 = internals::empty<internals::tag1>,
00081                class Id2 = internals::empty<internals::tag2>,
00082                class Id3 = internals::empty<internals::tag3>,
00083                class Id4 = internals::empty<internals::tag4> >
00084     struct unique_id: private Id1, private Id2, private Id3, private Id4
00085     {
00096       unique_id(unsigned        frame_id,
00097                 const Id1&      id1 = Id1 (),
00098                 const Id2&      id2 = Id2 (),
00099                 const Id3&      id3 = Id3 (),
00100                 const Id4&      id4 = Id4 ());
00101 
00103 
00104       bool              operator < (const unique_id& rhs) const;
00105       bool              operator == (const unique_id& rhs) const;
00106       bool              operator != (const unique_id& rhs) const;
00108 
00110       std::ostream&     print(std::ostream&) const;
00111 
00113       unsigned          frame_id() const;
00114 
00116 
00117       const Id1&        id1() const;
00118       const Id2&        id2() const;
00119       const Id3&        id3() const;
00120       const Id4&        id4() const;
00122 
00123     private:
00124       unsigned          frame_id_;
00125     };
00126 
00129     template <class Id1, class Id2, class Id3, class Id4>
00130     std::ostream&
00131     operator << (std::ostream&, const unique_id<Id1, Id2, Id3, Id4>&);
00132 
00140     template <class UniqueId, class HeaderType>
00141     boost::optional<UniqueId>
00142     make_unique_id(const pcapxx::frame_descriptor&      desc,
00143                    addr_mapping&                        mapping);
00144 
00145     namespace internals
00146     {
00147 
00148       bool
00149       make_unique_id_handle_prism(const void*&                    frame,
00150                                   size_t&                         caplen,
00151                                   const pcapxx::frame_descriptor& desc);
00152 
00153 # define tt_make_unique_id_prism_dissect(F, D, HType, H)                \
00154       dissector<HType>  D;                                              \
00155       {                                                                 \
00156         const void*     frame;                                          \
00157         size_t          caplen;                                         \
00158                                                                         \
00159         if (not internals::make_unique_id_handle_prism(frame, caplen, F)) \
00160           return boost::none_t ();                                      \
00161         D(frame, caplen);                                               \
00162       }                                                                 \
00163       const HType&      H = D.hooks()
00164 
00165     } // End of namespace wifi::frame::internals.
00166 
00167   } // End of namespace wifi::frame.
00168 
00169 } // End of namespace wifi.
00170 
00171 /*---------------.
00172 | Hash functions |
00173 `---------------*/
00174 
00175 HASH_NAMESPACE_BEGIN
00176 
00177   template <class Tag>
00178   struct hash< wifi::frame::internals::empty<Tag> >
00179   {
00180     size_t
00181     operator () (const wifi::frame::internals::empty<Tag>&) const;
00182   };
00183 
00184   template <class T, class Tag>
00185   struct hash< wifi::frame::internals::adapter<T, Tag> >: public hash<T>
00186   {
00187     size_t
00188     operator () (const wifi::frame::internals::adapter<T, Tag>&) const;
00189   };
00190 
00191   template <class Id1, class Id2, class Id3, class Id4>
00192   struct hash< wifi::frame::unique_id<Id1, Id2, Id3, Id4> >:
00193       public hash<Id1>,
00194       public hash<Id2>,
00195       public hash<Id3>,
00196       public hash<Id4>
00197   {
00198     size_t
00199     operator () (const wifi::frame::unique_id<Id1, Id2, Id3, Id4>&) const;
00200   };
00201 
00202 HASH_NAMESPACE_END
00203 
00204 
00205 # include "unique_id.hxx"
00206 
00207 #endif // ! WIFI_FRAME_UNIQUE_ID_HH_

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