EUI64.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "EUI64.hh"
18 //#include "EUI64.ih"
19 
20 // Custom includes
21 #include <boost/io/ios_state.hpp>
22 #include <iomanip>
23 #include "ParseString.hh"
24 
25 //#include "EUI64.mpp"
26 #define prefix_
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
30 
32 {
33  EUI64 eui (senf::noinit);
34  detail::parseHexString(s, ":-", eui.begin(), eui.end());
35  return eui;
36 }
37 
38 prefix_ std::ostream & senf::operator<<(std::ostream & os, EUI64 const & eui)
39 {
40  boost::io::ios_all_saver ias(os);
41  os << std::hex << std::setfill('0') << std::right
42  << std::setw(2) << unsigned(eui[0]) << ":"
43  << std::setw(2) << unsigned(eui[1]) << ":"
44  << std::setw(2) << unsigned(eui[2]) << ":"
45  << std::setw(2) << unsigned(eui[3]) << "-"
46  << std::setw(2) << unsigned(eui[4]) << ":"
47  << std::setw(2) << unsigned(eui[5]) << ":"
48  << std::setw(2) << unsigned(eui[6]) << ":"
49  << std::setw(2) << unsigned(eui[7]);
50  return os;
51 }
52 
53 prefix_ std::istream & senf::operator>>(std::istream & is, EUI64 & eui)
54 {
55  std::string s;
56  if (!(is >> s))
57  return is;
58  try {
59  eui = EUI64::from_string(s);
60  }
61  catch (AddressException &) {
62  is.setstate(std::ios::failbit);
63  }
64  return is;
65 }
66 
67 //-/////////////////////////////////////////////////////////////////////////////////////////////////
68 #undef prefix_
69 //#include "EUI64.mpp"
70 
71 
72 // Local Variables:
73 // mode: c++
74 // fill-column: 100
75 // comment-column: 40
76 // c-file-style: "senf"
77 // indent-tabs-mode: nil
78 // ispell-local-dictionary: "american"
79 // compile-command: "scons -u test"
80 // End:
static EUI64 from_string(std::string const &s)
Construct EUI-64 from string representation.
Definition: EUI64.cc:31
EUI-64 data type.
Definition: EUI64.hh:66
#define prefix_
Definition: EUI64.cc:26
ParseString public header.
static EUI64 const None
The empty (0) address.
Definition: EUI64.hh:73
std::ostream & operator<<(std::ostream &os, Packet const &packet)
noinit
std::istream & operator>>(std::istream &is, INet4SocketAddress &addr)
EUI64 public header.
void parseHexString(std::string const &value, char const *separator, ForwardIterator f, ForwardIterator l)
Base-class for Address exceptions.