ea901bf82c81c136665f36807c72c9175e0eca35
[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         static MIHFId const Multicast; ///< The multicast (empty) MIHF Id
50         enum Type { MulticastType, MACAddress, INet4Address, INet6Address, String, EUI64 };
51
52         MIHFId();                                   ///< Create multicast id.
53         MIHFId(senf::MACAddress const & addr);      ///< Construct id with given MACAddress
54         MIHFId(senf::INet4Address const & addr);    ///< Construct id with given INet4Address
55         MIHFId(senf::INet6Address const & addr);    ///< Construct id with given INet6Address
56         MIHFId(std::string const & addr);           ///< Construct id with given String
57         MIHFId(senf::EUI64 const & addr);           ///< Construct id with given EUI64
58
59         Type type() const;
60         bool operator==(MIHFId const & other) const;
61         bool operator<(MIHFId const & other) const;
62
63     private:
64         struct GetTypeVisitor : public boost::static_visitor<Type> {
65             Type operator()(boost::blank const &) const { return MulticastType; }
66             Type operator()(senf::MACAddress const &) const { return MACAddress; }
67             Type operator()(senf::INet4Address const &) const { return INet4Address; }
68             Type operator()(senf::INet6Address const &) const { return INet6Address; }
69             Type operator()(std::string const & ) const { return String; }
70             Type operator()(senf::EUI64 const &) const { return EUI64; }
71         };
72         struct EqualsVisitor : public boost::static_visitor<bool> {
73             template <typename T, typename U>
74             bool operator()(T const &, U const &) const {
75                 return false;
76             }
77             template <typename T>
78             bool operator()( const T & lhs, const T & rhs ) const {
79                 return lhs == rhs;
80             }
81         };
82         struct LessThanVisitor : public boost::static_visitor<bool> {
83             template <typename T, typename U>
84             bool operator()(T const &, U const &) const {
85                 return false;
86             }
87             template <typename T>
88             bool operator()( const T & lhs, const T & rhs ) const {
89                 return lhs < rhs;
90             }
91         };
92     };
93
94 }
95
96 ///////////////////////////////hh.e////////////////////////////////////////
97 #include "MIHTypes.cci"
98 //#include "MIHTypes.ct"
99 //#include "MIHTypes.cti"
100 #endif
101
102 \f
103 // Local Variables:
104 // mode: c++
105 // fill-column: 100
106 // comment-column: 40
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // End: