Socket/Protocols/Raw: EUI64 documentation
[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></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         Additionally, a senf::MACAddress can be converted into an EUI64 and vice versa.
64
65         \ingroup addr_group
66      */
67     class EUI64
68         : public boost::array<boost::uint8_t,8>,
69           public senf::comparable_safe_bool<EUI64>
70     {
71     public:
72         ///////////////////////////////////////////////////////////////////////////
73         ///\name Structors and default members
74         ///@{
75
76         // default copy constructor
77         // default copy assignment
78         // default destructor
79         // no conversion constructors
80
81         explicit EUI64(boost::uint64_t v=0u); ///< Construct EUI-64
82         explicit EUI64(senf::NoInit_t);       ///< Construct <em>uninitialized</em> EUI-64
83
84         static EUI64 from_mac(MACAddress const & mac);
85                                         ///< Construct EUI-64 from senf::MACAddress
86         static EUI64 from_string(std::string const & s);
87                                         ///< Construct EUI-64 from string representation
88                                         /**< The string representation consists of 8 octets in
89                                              hexadecimal notation spearated by ':' or '-' */
90         template <class InputIterator>
91         static EUI64 from_data(InputIterator i);
92                                         ///< Construct EUI-64 from 8 data octets
93                                         /**< The iterator \a i must point to a sequence of 8
94                                              octets in network byte order. */
95
96         ///@}
97         ///////////////////////////////////////////////////////////////////////////
98
99         bool isMACCompatible() const;   ///< \c true, if EUI64 is MAC compatible, \c false otherwise
100                                         /**< An EUI64 is MAC compatible if bytes 4th and 5th byte
101                                              (in network byte order) are 0xfffe. */
102         bool boolean_test() const;      ///< \c true, if EUI64 is != 0, \c false otherwise
103         boost::uint64_t uint64() const; ///< Return EUI64 as integer number
104     };
105
106     /** \brief Write out EUI64 in it's string representation to stream
107         \related senf::EUI64
108      */
109     std::ostream & operator<<(std::ostream & os, EUI64 const & v);
110
111     /** \brief Read EUI64 string representation from stream
112         \related senf::EUI64
113      */
114     std::istream & operator>>(std::istream & is, EUI64 & v);
115
116 }
117
118 ///////////////////////////////hh.e////////////////////////////////////////
119 #include "EUI64.cci"
120 //#include "EUI64.ct"
121 #include "EUI64.cti"
122 #endif
123
124 \f
125 // Local Variables:
126 // mode: c++
127 // fill-column: 100
128 // comment-column: 40
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"
133 // End: