Alien-boost-mini
view release on metacpan or search on metacpan
include/boost/uuid/uuid_io.hpp view on Meta::CPAN
// Boost uuid_io.hpp header file ----------------------------------------------//
// Copyright 2009 Andy Tompkins.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Revision History
// 20 Mar 2009 - Initial Revision
// 28 Nov 2009 - disabled deprecated warnings for MSVC
#ifndef BOOST_UUID_IO_HPP
#define BOOST_UUID_IO_HPP
#include <boost/uuid/uuid.hpp>
#include <ios>
#include <ostream>
#include <istream>
#include <boost/io/ios_state.hpp>
#include <locale>
#include <algorithm>
#if defined(_MSC_VER)
#pragma warning(push) // Save warning settings.
#pragma warning(disable : 4996) // Disable deprecated std::ctype<char>::widen, std::copy
#endif
namespace boost {
namespace uuids {
template <typename ch, typename char_traits>
std::basic_ostream<ch, char_traits>& operator<<(std::basic_ostream<ch, char_traits> &os, uuid const& u)
{
io::ios_flags_saver flags_saver(os);
io::basic_ios_fill_saver<ch, char_traits> fill_saver(os);
const typename std::basic_ostream<ch, char_traits>::sentry ok(os);
if (ok) {
const std::streamsize width = os.width(0);
const std::streamsize uuid_width = 36;
const std::ios_base::fmtflags flags = os.flags();
const typename std::basic_ios<ch, char_traits>::char_type fill = os.fill();
if (flags & (std::ios_base::right | std::ios_base::internal)) {
for (std::streamsize i=uuid_width; i<width; i++) {
os << fill;
}
}
os << std::hex << std::right;
os.fill(os.widen('0'));
std::size_t i=0;
for (uuid::const_iterator i_data = u.begin(); i_data!=u.end(); ++i_data, ++i) {
os.width(2);
os << static_cast<unsigned int>(*i_data);
if (i == 3 || i == 5 || i == 7 || i == 9) {
os << os.widen('-');
}
}
if (flags & std::ios_base::left) {
for (std::streamsize s=uuid_width; s<width; s++) {
os << fill;
}
}
os.width(0); //used the width so reset it
}
return os;
}
template <typename ch, typename char_traits>
std::basic_istream<ch, char_traits>& operator>>(std::basic_istream<ch, char_traits> &is, uuid &u)
{
const typename std::basic_istream<ch, char_traits>::sentry ok(is);
if (ok) {
unsigned char data[16];
typedef std::ctype<ch> ctype_t;
ctype_t const& ctype = std::use_facet<ctype_t>(is.getloc());
( run in 0.630 second using v1.01-cache-2.11-cpan-ceb78f64989 )