Packets/80221Bundle: more GenericTLVBase integration; removed GenericTLVPacket; some...
[senf.git] / senf / Packets / 80221Bundle / MIHTypes.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief MIHTypes public header */
25
26 #ifndef HH_SENF_Packets_80221Bundle_MIHTypes_
27 #define HH_SENF_Packets_80221Bundle_MIHTypes_ 1
28
29 // Custom includes
30 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
31 #include <senf/Socket/Protocols/INet/INet4Address.hh>
32 #include <senf/Socket/Protocols/INet/INet6Address.hh>
33 #include <boost/function_output_iterator.hpp>
34 #include <boost/iterator/filter_iterator.hpp>
35 #include <boost/variant.hpp>
36
37 //#include "MIHTypes.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41
42     class MIHFId 
43         : public boost::variant< boost::blank, senf::MACAddress, senf::INet4Address, 
44                 senf::INet6Address, std::string, senf::EUI64 >,
45           public boost::less_than_comparable<MIHFId>,
46           public boost::equality_comparable<MIHFId>
47     {
48     public:
49         enum Type { Empty, MACAddress, INet4Address, INet6Address, String, EUI64 };
50       
51         MIHFId();                                   ///< Create empty instance.
52         MIHFId(senf::MACAddress const & addr);      ///< Construct id with given MACAddress 
53         MIHFId(senf::INet4Address const & addr);    ///< Construct id with given INet4Address
54         MIHFId(senf::INet6Address const & addr);    ///< Construct id with given INet6Address
55         MIHFId(std::string const & addr);           ///< Construct id with given String
56         MIHFId(senf::EUI64 const & addr);           ///< Construct id with given EUI64
57         
58         Type type() const;
59         bool operator==(MIHFId const & other) const;
60         bool operator<(MIHFId const & other) const; 
61         
62     private:
63         struct GetTypeVisitor : public boost::static_visitor<Type> {
64             Type operator()(boost::blank const &) const { return Empty; }
65             Type operator()(senf::MACAddress const &) const { return MACAddress; }
66             Type operator()(senf::INet4Address const &) const { return INet4Address; }
67             Type operator()(senf::INet6Address const &) const { return INet6Address; }
68             Type operator()(std::string const & ) const { return String; }
69             Type operator()(senf::EUI64 const &) const { return EUI64; }
70         };
71         struct EqualsVisitor : public boost::static_visitor<bool> {
72             template <typename T, typename U>
73             bool operator()(T const &, U const &) const {
74                 return false;
75             }
76             template <typename T>
77             bool operator()( const T & lhs, const T & rhs ) const {
78                 return lhs == rhs;
79             }
80         };
81         struct LessThanVisitor : public boost::static_visitor<bool> {
82             template <typename T, typename U>
83             bool operator()(T const &, U const &) const {
84                 return false;
85             }
86             template <typename T>
87             bool operator()( const T & lhs, const T & rhs ) const {
88                 return lhs < rhs;
89             }
90         };
91     };
92
93 }
94
95 ///////////////////////////////hh.e////////////////////////////////////////
96 #include "MIHTypes.cci"
97 //#include "MIHTypes.ct"
98 //#include "MIHTypes.cti"
99 #endif
100
101 \f
102 // Local Variables:
103 // mode: c++
104 // fill-column: 100
105 // comment-column: 40
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // End: