switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / 80221Bundle / MIHTypes.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief MIHTypes public header */
30
31 #ifndef HH_SENF_Packets_80221Bundle_MIHTypes_
32 #define HH_SENF_Packets_80221Bundle_MIHTypes_ 1
33
34 // Custom includes
35 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
36 #include <senf/Socket/Protocols/INet/INet4Address.hh>
37 #include <senf/Socket/Protocols/INet/INet6Address.hh>
38 #include <boost/function_output_iterator.hpp>
39 #include <boost/iterator/filter_iterator.hpp>
40 #include <boost/variant.hpp>
41
42 //#include "MIHTypes.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace senf {
46
47     class MIHFId
48         : public boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
49                 senf::INet6Address, std::string, senf::EUI64 >,
50           public boost::less_than_comparable<MIHFId>,
51           public boost::equality_comparable<MIHFId>
52     {
53     public:
54         static MIHFId const Multicast; ///< The multicast (empty) MIHF Id
55         enum Type { MulticastType, MACAddress, INet4Address, INet6Address, String, EUI64 };
56
57         MIHFId();                                   ///< Create multicast id.
58         MIHFId(senf::MACAddress const & addr);      ///< Construct id with given MACAddress
59         MIHFId(senf::INet4Address const & addr);    ///< Construct id with given INet4Address
60         MIHFId(senf::INet6Address const & addr);    ///< Construct id with given INet6Address
61         MIHFId(std::string const & addr);           ///< Construct id with given String
62         MIHFId(senf::EUI64 const & addr);           ///< Construct id with given EUI64
63
64         Type type() const;
65         bool operator==(MIHFId const & other) const;
66         bool operator<(MIHFId const & other) const;
67
68     private:
69         struct GetTypeVisitor : public boost::static_visitor<Type> {
70             Type operator()(boost::blank const &) const { return MulticastType; }
71             Type operator()(senf::MACAddress const &) const { return MACAddress; }
72             Type operator()(senf::INet4Address const &) const { return INet4Address; }
73             Type operator()(senf::INet6Address const &) const { return INet6Address; }
74             Type operator()(std::string const & ) const { return String; }
75             Type operator()(senf::EUI64 const &) const { return EUI64; }
76         };
77         struct EqualsVisitor : public boost::static_visitor<bool> {
78             template <typename T, typename U>
79             bool operator()(T const &, U const &) const {
80                 return false;
81             }
82             template <typename T>
83             bool operator()( const T & lhs, const T & rhs ) const {
84                 return lhs == rhs;
85             }
86         };
87         struct LessThanVisitor : public boost::static_visitor<bool> {
88             template <typename T, typename U>
89             bool operator()(T const &, U const &) const {
90                 return false;
91             }
92             template <typename T>
93             bool operator()( const T & lhs, const T & rhs ) const {
94                 return lhs < rhs;
95             }
96         };
97     };
98
99 }
100
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 #include "MIHTypes.cci"
103 //#include "MIHTypes.ct"
104 //#include "MIHTypes.cti"
105 #endif
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // fill-column: 100
111 // comment-column: 40
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // End: