EUI64.cc

Go to the documentation of this file.
00001 // $Id: EUI64.cc 1792 2011-06-09 15:49:59Z tho $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "EUI64.hh"
00027 //#include "EUI64.ih"
00028 
00029 // Custom includes
00030 #include <boost/io/ios_state.hpp>
00031 #include <iomanip>
00032 #include "ParseString.hh"
00033 
00034 //#include "EUI64.mpp"
00035 #define prefix_
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 senf::EUI64 const senf::EUI64::None;
00039 
00040 prefix_ senf::EUI64 senf::EUI64::from_string(std::string const & s)
00041 {
00042     EUI64 eui (senf::noinit);
00043     detail::parseHexString(s, ":-", eui.begin(), eui.end());
00044     return eui;
00045 }
00046 
00047 prefix_ std::ostream & senf::operator<<(std::ostream & os, EUI64 const & eui)
00048 {
00049     boost::io::ios_all_saver ias(os);
00050     os << std::hex << std::setfill('0') << std::right
00051        << std::setw(2) << unsigned(eui[0]) << ":"
00052        << std::setw(2) << unsigned(eui[1]) << ":"
00053        << std::setw(2) << unsigned(eui[2]) << ":"
00054        << std::setw(2) << unsigned(eui[3]) << "-"
00055        << std::setw(2) << unsigned(eui[4]) << ":"
00056        << std::setw(2) << unsigned(eui[5]) << ":"
00057        << std::setw(2) << unsigned(eui[6]) << ":"
00058        << std::setw(2) << unsigned(eui[7]);
00059     return os;
00060 }
00061 
00062 prefix_ std::istream & senf::operator>>(std::istream & is, EUI64 & eui)
00063 {
00064     std::string s;
00065     if (!(is >> s))
00066         return is;
00067     try {
00068         eui = EUI64::from_string(s);
00069     }
00070     catch (AddressException &) {
00071         is.setstate(std::ios::failbit);
00072     }
00073     return is;
00074 }
00075 
00076 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00077 #undef prefix_
00078 //#include "EUI64.mpp"
00079 
00080 
00081 // Local Variables:
00082 // mode: c++
00083 // fill-column: 100
00084 // comment-column: 40
00085 // c-file-style: "senf"
00086 // indent-tabs-mode: nil
00087 // ispell-local-dictionary: "american"
00088 // compile-command: "scons -u test"
00089 // End: