Added the parts of boost which we need to access shared_ptr and weak_ptr. This will allow for improved memory management of large volumes.

This commit is contained in:
David Williams
2009-03-29 22:07:27 +00:00
parent 69751dc084
commit d574a18ce3
163 changed files with 18689 additions and 32 deletions

View File

@ -0,0 +1,61 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_CE6983AC753411DDA764247956D89593
#define UUID_CE6983AC753411DDA764247956D89593
#include <string>
namespace
boost
{
namespace
exception_detail
{
class
error_info_base
{
public:
virtual char const * tag_typeid_name() const = 0;
virtual std::string value_as_string() const = 0;
protected:
virtual
~error_info_base() throw()
{
}
};
}
template <class Tag,class T>
class
error_info:
public exception_detail::error_info_base
{
public:
typedef T value_type;
error_info( value_type const & value );
~error_info() throw();
value_type const &
value() const
{
return value_;
}
private:
char const * tag_typeid_name() const;
std::string value_as_string() const;
value_type const value_;
};
}
#endif

View File

@ -0,0 +1,38 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_898984B4076411DD973EDFA055D89593
#define UUID_898984B4076411DD973EDFA055D89593
#include <ostream>
namespace
boost
{
namespace
to_string_detail
{
template <class T,class CharT,class Traits>
char operator<<( std::basic_ostream<CharT,Traits> &, T const & );
template <class T,class CharT,class Traits>
struct
is_output_streamable_impl
{
static std::basic_ostream<CharT,Traits> & f();
static T const & g();
enum e { value=1!=(sizeof(f()<<g())) };
};
}
template <class T, class CharT=char, class Traits=std::char_traits<CharT> >
struct
is_output_streamable
{
enum e { value=to_string_detail::is_output_streamable_impl<T,CharT,Traits>::value };
};
}
#endif

View File

@ -0,0 +1,40 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_6F463AC838DF11DDA3E6909F56D89593
#define UUID_6F463AC838DF11DDA3E6909F56D89593
#include <boost/exception/detail/type_info.hpp>
#include <iomanip>
#include <ios>
#include <string>
#include <sstream>
namespace
boost
{
namespace
exception_detail
{
template <class T>
inline
std::string
object_hex_dump( T const & x, size_t max_size=16 )
{
std::ostringstream s;
s << "type: " << type_name<T>() << ", size: " << sizeof(T) << ", dump: ";
size_t n=sizeof(T)>max_size?max_size:sizeof(T);
s.fill('0');
s.width(2);
unsigned char const * b=reinterpret_cast<unsigned char const *>(&x);
s << std::setw(2) << std::hex << (unsigned int)*b;
for( unsigned char const * e=b+n; ++b!=e; )
s << " " << std::setw(2) << std::hex << (unsigned int)*b;
return s.str();
}
}
}
#endif

View File

@ -0,0 +1,130 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_C3E1741C754311DDB2834CCA55D89593
#define UUID_C3E1741C754311DDB2834CCA55D89593
#include <boost/detail/sp_typeinfo.hpp>
#include <boost/current_function.hpp>
namespace
boost
{
template <class T>
inline
char const *
tag_type_name()
{
#ifdef BOOST_NO_TYPEID
return BOOST_CURRENT_FUNCTION;
#else
return typeid(T*).name();
#endif
}
template <class T>
inline
char const *
type_name()
{
#ifdef BOOST_NO_TYPEID
return BOOST_CURRENT_FUNCTION;
#else
return typeid(T).name();
#endif
}
namespace
exception_detail
{
#ifdef BOOST_NO_TYPEID
struct
type_info_
{
detail::sp_typeinfo type_;
char const * name_;
explicit
type_info_( detail::sp_typeinfo type, char const * name ):
type_(type),
name_(name)
{
}
friend
bool
operator==( type_info_ const & a, type_info_ const & b )
{
return a.type_==b.type_;
}
friend
bool
operator<( type_info_ const & a, type_info_ const & b )
{
return a.type_<b.type_;
}
char const *
name() const
{
return name_;
}
};
#else
struct
type_info_
{
detail::sp_typeinfo const * type_;
explicit
type_info_( detail::sp_typeinfo const & type ):
type_(&type)
{
}
type_info_( detail::sp_typeinfo const & type, char const * ):
type_(&type)
{
}
friend
bool
operator==( type_info_ const & a, type_info_ const & b )
{
return (*a.type_)==(*b.type_);
}
friend
bool
operator<( type_info_ const & a, type_info_ const & b )
{
return 0!=(a.type_->before(*b.type_));
}
char const *
name() const
{
return type_->name();
}
};
#endif
inline
bool
operator!=( type_info_ const & a, type_info_ const & b )
{
return !(a==b);
}
}
}
#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_SP_TYPEID(T),::boost::tag_type_name<T>())
#ifndef BOOST_NO_RTTI
#define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x))
#endif
#endif

View File

@ -0,0 +1,64 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_0552D49838DD11DD90146B8956D89593
#define UUID_0552D49838DD11DD90146B8956D89593
#include <boost/exception/get_error_info.hpp>
#include <exception>
#include <sstream>
#include <string>
namespace
boost
{
namespace
exception_detail
{
inline
char const *
get_diagnostic_information( exception const & x )
{
if( error_info_container * c=x.data_.get() )
try
{
return c->diagnostic_information();
}
catch(...)
{
}
return 0;
}
}
inline
std::string
diagnostic_information( exception const & x )
{
std::ostringstream tmp;
if( boost::shared_ptr<char const * const> f=get_error_info<throw_file>(x) )
{
tmp << *f;
if( boost::shared_ptr<int const> l=get_error_info<throw_line>(x) )
tmp << '(' << *l << "): ";
}
tmp << "Throw in function ";
if( boost::shared_ptr<char const * const> fn=get_error_info<throw_function>(x) )
tmp << *fn;
else
tmp << "(unknown)";
#ifndef BOOST_NO_RTTI
tmp << "\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
tmp << "\nstd::exception::what: " << e->what();
#endif
if( char const * s=exception_detail::get_diagnostic_information(x) )
if( *s )
tmp << '\n' << s;
return tmp.str();
}
}
#endif

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/exception.hpp>

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/exception.hpp>

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
namespace boost { template <class Tag,class T> class error_info; }

View File

@ -0,0 +1,396 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
#define UUID_274DA366004E11DCB1DDFE2E56D89593
namespace
boost
{
namespace
exception_detail
{
template <class T>
class
refcount_ptr
{
public:
refcount_ptr():
px_(0)
{
}
~refcount_ptr()
{
release();
}
refcount_ptr( refcount_ptr const & x ):
px_(x.px_)
{
add_ref();
}
refcount_ptr &
operator=( refcount_ptr const & x )
{
adopt(x.px_);
return *this;
}
void
adopt( T * px )
{
release();
px_=px;
add_ref();
}
T *
get() const
{
return px_;
}
private:
T * px_;
void
add_ref()
{
if( px_ )
px_->add_ref();
}
void
release()
{
if( px_ )
px_->release();
}
};
}
////////////////////////////////////////////////////////////////////////
template <class Tag,class T>
class error_info;
typedef error_info<struct tag_throw_function,char const *> throw_function;
typedef error_info<struct tag_throw_file,char const *> throw_file;
typedef error_info<struct tag_throw_line,int> throw_line;
template <>
class
error_info<tag_throw_function,char const *>
{
public:
typedef char const * value_type;
value_type v_;
explicit
error_info( value_type v ):
v_(v)
{
}
};
template <>
class
error_info<tag_throw_file,char const *>
{
public:
typedef char const * value_type;
value_type v_;
explicit
error_info( value_type v ):
v_(v)
{
}
};
template <>
class
error_info<tag_throw_line,int>
{
public:
typedef int value_type;
value_type v_;
explicit
error_info( value_type v ):
v_(v)
{
}
};
template <class E,class Tag,class T>
E const & operator<<( E const &, error_info<Tag,T> const & );
class exception;
template <class>
class shared_ptr;
namespace
exception_detail
{
class error_info_base;
struct type_info_;
struct
error_info_container
{
virtual char const * diagnostic_information() const = 0;
virtual shared_ptr<error_info_base const> get( type_info_ const & ) const = 0;
virtual void set( shared_ptr<error_info_base const> const &, type_info_ const & ) = 0;
virtual void add_ref() const = 0;
virtual void release() const = 0;
protected:
virtual
~error_info_container() throw()
{
}
};
template <class>
struct get_info;
template <>
struct get_info<throw_function>;
template <>
struct get_info<throw_file>;
template <>
struct get_info<throw_line>;
char const * get_diagnostic_information( exception const & );
}
class
exception
{
protected:
exception():
throw_function_(0),
throw_file_(0),
throw_line_(-1)
{
}
#ifdef __HP_aCC
//On HP aCC, this protected copy constructor prevents throwing boost::exception.
//On all other platforms, the same effect is achieved by the pure virtual destructor.
exception( exception const & x ) throw():
data_(x.data_),
throw_function_(x.throw_function_),
throw_file_(x.throw_file_),
throw_line_(x.throw_line_)
{
}
#endif
virtual ~exception() throw()
#ifndef __HP_aCC
= 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
#endif
;
private:
template <class E>
friend
E const &
operator<<( E const & x, throw_function const & y )
{
x.throw_function_=y.v_;
return x;
}
template <class E>
friend
E const &
operator<<( E const & x, throw_file const & y )
{
x.throw_file_=y.v_;
return x;
}
template <class E>
friend
E const &
operator<<( E const & x, throw_line const & y )
{
x.throw_line_=y.v_;
return x;
}
friend char const * exception_detail::get_diagnostic_information( exception const & );
template <class E,class Tag,class T>
friend E const & operator<<( E const &, error_info<Tag,T> const & );
template <class>
friend struct exception_detail::get_info;
friend struct exception_detail::get_info<throw_function>;
friend struct exception_detail::get_info<throw_file>;
friend struct exception_detail::get_info<throw_line>;
mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
mutable char const * throw_function_;
mutable char const * throw_file_;
mutable int throw_line_;
};
inline
exception::
~exception() throw()
{
}
////////////////////////////////////////////////////////////////////////
namespace
exception_detail
{
template <class T>
struct
error_info_injector:
public T,
public exception
{
explicit
error_info_injector( T const & x ):
T(x)
{
}
~error_info_injector() throw()
{
}
};
struct large_size { char c[256]; };
large_size dispatch( exception * );
struct small_size { };
small_size dispatch( void * );
template <class,int>
struct enable_error_info_helper;
template <class T>
struct
enable_error_info_helper<T,sizeof(large_size)>
{
typedef T type;
};
template <class T>
struct
enable_error_info_helper<T,sizeof(small_size)>
{
typedef error_info_injector<T> type;
};
template <class T>
struct
enable_error_info_return_type
{
typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
};
}
template <class T>
inline
typename
exception_detail::enable_error_info_return_type<T>::type
enable_error_info( T const & x )
{
typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
return rt(x);
}
////////////////////////////////////////////////////////////////////////
namespace
exception_detail
{
class
clone_base
{
public:
virtual clone_base const * clone() const = 0;
virtual void rethrow() const = 0;
virtual
~clone_base() throw()
{
}
};
inline
void
copy_boost_exception( exception * a, exception const * b )
{
*a = *b;
}
inline
void
copy_boost_exception( void *, void const * )
{
}
template <class T>
class
clone_impl:
public T,
public clone_base
{
public:
explicit
clone_impl( T const & x ):
T(x)
{
copy_boost_exception(this,&x);
}
~clone_impl() throw()
{
}
private:
clone_base const *
clone() const
{
return new clone_impl(*this);
}
void
rethrow() const
{
throw*this;
}
};
}
template <class T>
inline
exception_detail::clone_impl<T>
enable_current_exception( T const & x )
{
return exception_detail::clone_impl<T>(x);
}
}
#endif

View File

@ -0,0 +1,134 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_1A590226753311DD9E4CCF6156D89593
#define UUID_1A590226753311DD9E4CCF6156D89593
#include <boost/exception/exception.hpp>
#include <boost/exception/detail/error_info_impl.hpp>
#include <boost/exception/detail/type_info.hpp>
#include <boost/shared_ptr.hpp>
namespace
boost
{
namespace
exception_detail
{
struct
strwrap
{
std::string str;
char const * ptr;
explicit
strwrap( char const * s ):
str(s),
ptr(&str[0])
{
}
private:
strwrap( strwrap const & );
strwrap & operator=( strwrap const & );
};
template <>
struct
get_info<throw_function>
{
static
shared_ptr<char const * const>
get( exception const & x )
{
if( x.throw_function_ && *x.throw_function_ )
{
shared_ptr<strwrap> s(new strwrap(x.throw_function_));
return shared_ptr<char const *>(s,&s->ptr);
}
else
return shared_ptr<char const * const>();
}
};
template <>
struct
get_info<throw_file>
{
static
shared_ptr<char const * const>
get( exception const & x )
{
if( x.throw_file_ && *x.throw_file_ )
{
shared_ptr<strwrap> s(new strwrap(x.throw_file_));
return shared_ptr<char const *>(s,&s->ptr);
}
else
return shared_ptr<char const * const>();
}
};
template <>
struct
get_info<throw_line>
{
static
shared_ptr<int const>
get( exception const & x )
{
if( x.throw_line_!=-1 )
return boost::shared_ptr<int>(new int(x.throw_line_));
else
return shared_ptr<int const>();
}
};
template <class ErrorInfo>
struct
get_info
{
static
shared_ptr<typename ErrorInfo::value_type const>
get( exception const & x )
{
if( exception_detail::error_info_container * c=x.data_.get() )
if( shared_ptr<exception_detail::error_info_base const> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
{
#ifndef BOOST_NO_RTTI
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
#endif
ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());
return shared_ptr<typename ErrorInfo::value_type const>(eib,&w->value());
}
return shared_ptr<typename ErrorInfo::value_type const>();
}
};
}
#ifdef BOOST_NO_RTTI
template <class ErrorInfo>
inline
shared_ptr<typename ErrorInfo::value_type const>
get_error_info( boost::exception const & x )
{
return exception_detail::get_info<ErrorInfo>::get(x);
}
#else
template <class ErrorInfo,class E>
inline
shared_ptr<typename ErrorInfo::value_type const>
get_error_info( E const & some_exception )
{
if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
return exception_detail::get_info<ErrorInfo>::get(*x);
else
return shared_ptr<typename ErrorInfo::value_type const>();
}
#endif
}
#endif

View File

@ -0,0 +1,159 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_8D22C4CA9CC811DCAA9133D256D89593
#define UUID_8D22C4CA9CC811DCAA9133D256D89593
#include <boost/exception/exception.hpp>
#include <boost/exception/to_string_stub.hpp>
#include <boost/exception/detail/error_info_impl.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
namespace
boost
{
template <class Tag,class T>
inline
typename enable_if<has_to_string<T>,std::string>::type
to_string( error_info<Tag,T> const & x )
{
return to_string(x.value());
}
template <class Tag,class T>
inline
error_info<Tag,T>::
error_info( value_type const & value ):
value_(value)
{
}
template <class Tag,class T>
inline
error_info<Tag,T>::
~error_info() throw()
{
}
template <class Tag,class T>
inline
char const *
error_info<Tag,T>::
tag_typeid_name() const
{
return tag_type_name<Tag>();
}
template <class Tag,class T>
inline
std::string
error_info<Tag,T>::
value_as_string() const
{
return to_string_stub(*this);
}
namespace
exception_detail
{
class
error_info_container_impl:
public error_info_container
{
public:
error_info_container_impl():
count_(0)
{
}
~error_info_container_impl() throw()
{
}
void
set( shared_ptr<error_info_base const> const & x, type_info_ const & typeid_ )
{
BOOST_ASSERT(x);
info_[typeid_] = x;
diagnostic_info_str_.clear();
}
shared_ptr<error_info_base const>
get( type_info_ const & ti ) const
{
error_info_map::const_iterator i=info_.find(ti);
if( info_.end()!=i )
{
shared_ptr<error_info_base const> const & p = i->second;
#ifndef BOOST_NO_RTTI
BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p)==ti );
#endif
return p;
}
return shared_ptr<error_info_base const>();
}
char const *
diagnostic_information() const
{
if( diagnostic_info_str_.empty() )
{
std::string tmp;
for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
{
shared_ptr<error_info_base const> const & x = i->second;
tmp += '[';
tmp += x->tag_typeid_name();
tmp += "] = ";
tmp += x->value_as_string();
tmp += '\n';
}
diagnostic_info_str_.swap(tmp);
}
return diagnostic_info_str_.c_str();
}
private:
friend class boost::exception;
typedef std::map< type_info_, shared_ptr<error_info_base const> > error_info_map;
error_info_map info_;
mutable std::string diagnostic_info_str_;
mutable int count_;
void
add_ref() const
{
++count_;
}
void
release() const
{
if( !--count_ )
delete this;
}
};
}
template <class E,class Tag,class T>
inline
E const &
operator<<( E const & x, error_info<Tag,T> const & v )
{
typedef error_info<Tag,T> error_info_tag_t;
shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
exception_detail::error_info_container * c;
if( !(c=x.data_.get()) )
x.data_.adopt(c=new exception_detail::error_info_container_impl);
c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
return x;
}
}
#endif

View File

@ -0,0 +1,67 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_63EE924290FB11DC87BB856555D89593
#define UUID_63EE924290FB11DC87BB856555D89593
#include <boost/exception/info.hpp>
#include <boost/tuple/tuple.hpp>
namespace
boost
{
template <
class E,
class Tag1,class T1,
class Tag2,class T2 >
inline
E const &
operator<<(
E const & x,
tuple<
error_info<Tag1,T1>,
error_info<Tag2,T2> > const & v )
{
return x << v.template get<0>() << v.template get<1>();
}
template <
class E,
class Tag1,class T1,
class Tag2,class T2,
class Tag3,class T3 >
inline
E const &
operator<<(
E const & x,
tuple<
error_info<Tag1,T1>,
error_info<Tag2,T2>,
error_info<Tag3,T3> > const & v )
{
return x << v.template get<0>() << v.template get<1>() << v.template get<2>();
}
template <
class E,
class Tag1,class T1,
class Tag2,class T2,
class Tag3,class T3,
class Tag4,class T4 >
inline
E const &
operator<<(
E const & x,
tuple<
error_info<Tag1,T1>,
error_info<Tag2,T2>,
error_info<Tag3,T3>,
error_info<Tag4,T4> > const & v )
{
return x << v.template get<0>() << v.template get<1>() << v.template get<2>() << v.template get<3>();
}
}
#endif

View File

@ -0,0 +1,74 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_7E48761AD92811DC9011477D56D89593
#define UUID_7E48761AD92811DC9011477D56D89593
#include <boost/utility/enable_if.hpp>
#include <boost/exception/detail/is_output_streamable.hpp>
#include <sstream>
namespace
boost
{
namespace
to_string_detail
{
template <class T>
typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
template <class,bool IsOutputStreamable>
struct has_to_string_impl;
template <class T>
struct
has_to_string_impl<T,true>
{
enum e { value=1 };
};
template <class T>
struct
has_to_string_impl<T,false>
{
static T const & f();
enum e { value=1!=sizeof(to_string(f())) };
};
}
template <class T>
inline
typename enable_if<is_output_streamable<T>,std::string>::type
to_string( T const & x )
{
std::ostringstream out;
out << x;
return out.str();
}
template <class T>
struct
has_to_string
{
enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
};
template <class T,class U>
inline
std::string
to_string( std::pair<T,U> const & x )
{
return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
}
inline
std::string
to_string( std::exception const & x )
{
return x.what();
}
}
#endif

View File

@ -0,0 +1,100 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_E788439ED9F011DCB181F25B55D89593
#define UUID_E788439ED9F011DCB181F25B55D89593
#include <boost/exception/to_string.hpp>
#include <boost/exception/detail/object_hex_dump.hpp>
#include <boost/assert.hpp>
namespace
boost
{
namespace
exception_detail
{
template <bool ToStringAvailable>
struct
to_string_dispatcher
{
template <class T,class Stub>
static
std::string
convert( T const & x, Stub )
{
return to_string(x);
}
};
template <>
struct
to_string_dispatcher<false>
{
template <class T,class Stub>
static
std::string
convert( T const & x, Stub s )
{
return s(x);
}
template <class T>
static
std::string
convert( T const & x, std::string s )
{
return s;
}
template <class T>
static
std::string
convert( T const & x, char const * s )
{
BOOST_ASSERT(s!=0);
return s;
}
};
namespace
to_string_dispatch
{
template <class T,class Stub>
inline
std::string
dispatch( T const & x, Stub s )
{
return to_string_dispatcher<has_to_string<T>::value>::convert(x,s);
}
}
template <class T>
inline
std::string
string_stub_dump( T const & x )
{
return "[ " + exception_detail::object_hex_dump(x) + " ]";
}
}
template <class T>
inline
std::string
to_string_stub( T const & x )
{
return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump<T>);
}
template <class T,class Stub>
inline
std::string
to_string_stub( T const & x, Stub s )
{
return exception_detail::to_string_dispatch::dispatch(x,s);
}
}
#endif