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