Fix SCons 1.2.0 build failure
[senf.git] / Socket / Protocols / Raw / EUI64.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 //     Stefan Bund <g0dil@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 EUI64 public header */
25
26 #ifndef HH_SENF_Socket_Protocols_Raw_EUI64_
27 #define HH_SENF_Socket_Protocols_Raw_EUI64_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <boost/cstdint.hpp>
32 #include <boost/array.hpp>
33 #include "../../../Utils/Tags.hh"
34 #include "../../../Utils/safe_bool.hh"
35
36 //#include "EUI64.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     class MACAddress;
42
43     /** \brief EUI-64 data type
44         
45         An EUI-64 is a 64 bit (8 octet) id. The id is represented as an 8 byte sequence in network
46         byte order. An EUI64 can be converted from/to several other representations
47
48         <table class="senf">
49         <tr><td><tt>boost::uint64_t</tt></td>
50                 <td><tt>senf::EUI64(0x1a2b3c4d5f607182ull)</tt><br/>
51                     <i>eui64</i><tt>.uint64()</tt></td></tr>
52         <tr><td><tt>std::string</tt></td>
53                 <td><tt>senf::EUI64::from_string("1a:2b:3c:4d-5f:60:71:82")</tt><br/>
54                     <tt>senf::str(</tt><i>eui64</i><tt>)</tt></td></tr>
55         <tr><td><i>raw data</i><br/>&nbsp;&nbsp;&nbsp;&nbsp;(8 bytes)</td>
56                 <td><tt>senf::EUI64::from_data(</tt><i>iterator</i><tt>)</tt><br/>
57                     <i>eui64</i><tt>.begin()</tt></td></tr>
58         <tr><td>senf::MACAddress<br/>&nbsp;&nbsp;&nbsp;&nbsp;(aka EUI-48)</td>
59                 <td><tt>senf::EUI64::from_mac(</tt><i>mac-address</i><tt>)</tt><br/>
60                     <tt>senf::MACAddress::from_eui64(</tt><i>eui64</i><tt>)</tt></td></tr>
61         </table>
62
63         Since senf::EUI64 is based on \c boost::array, you can access the raw data bytes of the
64         address using \c begin(), \c end() or \c operator[]:
65         \code
66         senf::EUI64 eui64 (...);
67         std::vector<char> data;
68         data.resize(8);
69         std::copy(eui64.begin(), eui64.end(), data.begin()); // Copy 8 bytes
70         \endcode
71
72         \see <a href="http://tools.ietf.org/html/rfc4291">RFC 4291</a>
73
74         \ingroup addr_group
75      */
76     class EUI64
77         : public boost::array<boost::uint8_t,8>,
78           public senf::comparable_safe_bool<EUI64>
79     {
80     public:
81         ///////////////////////////////////////////////////////////////////////////
82         ///\name Structors and default members
83         ///@{
84
85         // default copy constructor
86         // default copy assignment
87         // default destructor
88         // no conversion constructors
89
90         explicit EUI64(boost::uint64_t v=0u); ///< Construct EUI-64
91         explicit EUI64(senf::NoInit_t);       ///< Construct <em>uninitialized</em> EUI-64
92
93         static EUI64 from_mac(MACAddress const & mac);
94                                         ///< Construct EUI-64 from senf::MACAddress
95         static EUI64 from_string(std::string const & s);
96                                         ///< Construct EUI-64 from string representation
97                                         /**< The string representation consists of 8 octets in
98                                              hexadecimal notation spearated by ':' or '-'
99                                              \throws senf::AddressSyntaxException */
100         template <class InputIterator>
101         static EUI64 from_data(InputIterator i);
102                                         ///< Construct EUI-64 from 8 data octets
103                                         /**< The iterator \a i must point to a sequence of 8
104                                              octets in network byte order. */
105
106         ///@}
107         ///////////////////////////////////////////////////////////////////////////
108
109         bool isMACCompatible() const;   ///< \c true, if EUI64 is MAC compatible, \c false otherwise
110                                         /**< An EUI64 is MAC compatible if bytes 4th and 5th byte
111                                              (in network byte order) are 0xfffe. */
112         bool local() const;             ///< \c true if the \e local bit is set, \c false otherwise
113                                         /**< The \e local bit is the second least significant bit of
114                                              the first octet (bit 6 in standard RFC bit numbering).
115                                           */
116         bool group() const;             ///< \c true if the \e group bit is set, \c false otherwise
117                                         /**< The \e group bit is the least significant bit of the
118                                              first octed (bit 7 in standard RFC bit numbering). */
119         bool boolean_test() const;      ///< \c true, if EUI64 is != 0, \c false otherwise
120         boost::uint64_t uint64() const; ///< Return EUI64 as integer number
121     };
122
123     /** \brief Write out EUI64 in it's string representation to stream
124         \related senf::EUI64
125      */
126     std::ostream & operator<<(std::ostream & os, EUI64 const & v);
127
128     /** \brief Read EUI64 string representation from stream
129         \related senf::EUI64
130      */
131     std::istream & operator>>(std::istream & is, EUI64 & v);
132
133 }
134
135 ///////////////////////////////hh.e////////////////////////////////////////
136 #include "EUI64.cci"
137 //#include "EUI64.ct"
138 #include "EUI64.cti"
139 #endif
140
141 \f
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // End: