object_hex_dump.hpp
Go to the documentation of this file.
00001 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
00002 
00003 //Distributed under the Boost Software License, Version 1.0. (See accompanying
00004 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef UUID_6F463AC838DF11DDA3E6909F56D89593
00007 #define UUID_6F463AC838DF11DDA3E6909F56D89593
00008 
00009 #include <boost/exception/detail/type_info.hpp>
00010 #include <iomanip>
00011 #include <ios>
00012 #include <string>
00013 #include <sstream>
00014 
00015 namespace
00016 boost
00017     {
00018     namespace
00019     exception_detail
00020         {
00021         template <class T>
00022         inline
00023         std::string
00024         object_hex_dump( T const & x, size_t max_size=16 )
00025             {
00026             std::ostringstream s;
00027             s << "type: " << type_name<T>() << ", size: " << sizeof(T) << ", dump: ";
00028             size_t n=sizeof(T)>max_size?max_size:sizeof(T);
00029             s.fill('0');
00030             s.width(2);
00031             unsigned char const * b=reinterpret_cast<unsigned char const *>(&x);
00032             s << std::setw(2) << std::hex << (unsigned int)*b;
00033             for( unsigned char const * e=b+n; ++b!=e; )
00034                 s << " " << std::setw(2) << std::hex << (unsigned int)*b;
00035             return s.str();
00036             }
00037         }
00038     }
00039 
00040 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29