mirror of
https://github.com/boostorg/exception.git
synced 2025-07-14 04:56:34 +02:00
Boost Exception
In other libraries, watch for compile error referring to throw_exception_assert_compatibility in boost::throw_exception. Resolve by throwing an exception that derives from std::exception. This is not a new requirement but it is being enforced now. [SVN r46818]
This commit is contained in:
38
include/boost/exception/detail/cloning_base.hpp
Normal file
38
include/boost/exception/detail/cloning_base.hpp
Normal 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_F7D5662CCB0F11DCA353CAC656D89593
|
||||
#define UUID_F7D5662CCB0F11DCA353CAC656D89593
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class clone_base;
|
||||
|
||||
class
|
||||
cloning_base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual clone_base const * clone() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~cloning_base() throw()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
49
include/boost/exception/detail/counted_base.hpp
Normal file
49
include/boost/exception/detail/counted_base.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
//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_DBA0D90C930911DCBA7B675A56D89593
|
||||
#define UUID_DBA0D90C930911DCBA7B675A56D89593
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
counted_base
|
||||
{
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_add_ref( counted_base const * c )
|
||||
{
|
||||
c->add_ref();
|
||||
}
|
||||
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_release( counted_base const * c )
|
||||
{
|
||||
c->release();
|
||||
}
|
||||
|
||||
virtual void add_ref() const=0;
|
||||
virtual void release() const=0;
|
||||
|
||||
protected:
|
||||
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~counted_base() throw()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
38
include/boost/exception/detail/is_output_streamable.hpp
Normal file
38
include/boost/exception/detail/is_output_streamable.hpp
Normal 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
|
39
include/boost/exception/detail/object_hex_dump.hpp
Normal file
39
include/boost/exception/detail/object_hex_dump.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
//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 <iomanip>
|
||||
#include <typeinfo>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
std::string
|
||||
object_hex_dump( T const & x, size_t max_size=16 )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "type: " << typeid(x).name() << ", 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
|
27
include/boost/exception/diagnostic_information.hpp
Normal file
27
include/boost/exception/diagnostic_information.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
//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/exception.hpp>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
inline
|
||||
std::string
|
||||
diagnostic_information( std::exception const & x )
|
||||
{
|
||||
if( exception const * be = dynamic_cast<exception const *>(&x) )
|
||||
return be->diagnostic_information();
|
||||
else
|
||||
return std::string("[ what: ") + x.what() + ", type: " + typeid(x).name() + " ]";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
154
include/boost/exception/enable_current_exception.hpp
Normal file
154
include/boost/exception/enable_current_exception.hpp
Normal file
@ -0,0 +1,154 @@
|
||||
//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_78CC85B2914F11DC8F47B48E55D89593
|
||||
#define UUID_78CC85B2914F11DC8F47B48E55D89593
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/exception/detail/cloning_base.hpp>
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <new>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
clone_base:
|
||||
public counted_base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void rethrow() const=0;
|
||||
};
|
||||
|
||||
struct
|
||||
bad_alloc_impl:
|
||||
public clone_base,
|
||||
public std::bad_alloc
|
||||
{
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
clone_base * make_clone( T const & );
|
||||
|
||||
template <class T>
|
||||
class
|
||||
clone_impl:
|
||||
public T,
|
||||
public cloning_base
|
||||
{
|
||||
public:
|
||||
|
||||
explicit
|
||||
clone_impl( T const & x ):
|
||||
T(x)
|
||||
{
|
||||
if( boost::exception * be1=dynamic_cast<boost::exception *>(this) )
|
||||
if( boost::exception const * be2=dynamic_cast<boost::exception const *>(&x) )
|
||||
*be1 = *be2;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
clone_base const *
|
||||
clone() const
|
||||
{
|
||||
return make_clone<T>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class
|
||||
exception_clone:
|
||||
public T,
|
||||
public clone_base
|
||||
{
|
||||
public:
|
||||
|
||||
explicit
|
||||
exception_clone( T const & x ):
|
||||
T(x),
|
||||
count_(0)
|
||||
{
|
||||
if( boost::exception * be1=dynamic_cast<boost::exception *>(this) )
|
||||
if( boost::exception const * be2=dynamic_cast<boost::exception const *>(&x) )
|
||||
*be1 = *be2;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
detail::atomic_count mutable count_;
|
||||
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
++count_;
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
throw clone_impl<T>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
clone_base *
|
||||
make_clone( T const & x )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new exception_clone<T>(x);
|
||||
}
|
||||
catch(
|
||||
std::bad_alloc & )
|
||||
{
|
||||
static bad_alloc_impl bad_alloc;
|
||||
return &bad_alloc;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
exception_detail::clone_impl<T>
|
||||
enable_current_exception( T const & x )
|
||||
{
|
||||
return exception_detail::clone_impl<T>(x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
111
include/boost/exception/enable_error_info.hpp
Normal file
111
include/boost/exception/enable_error_info.hpp
Normal file
@ -0,0 +1,111 @@
|
||||
//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_0C5D492E909711DCB658AD4556D89593
|
||||
#define UUID_0C5D492E909711DCB658AD4556D89593
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return T::what();
|
||||
}
|
||||
|
||||
char const *
|
||||
diagnostic_information() const throw()
|
||||
{
|
||||
return boost::exception::_diagnostic_information(T::what());
|
||||
}
|
||||
};
|
||||
|
||||
struct large_size { char c[256]; };
|
||||
large_size dispatch( exception * );
|
||||
|
||||
struct small_size { };
|
||||
small_size dispatch( void * );
|
||||
|
||||
template <class,size_t>
|
||||
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;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
template <class T>
|
||||
struct
|
||||
sizeof_dispatch
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(int, value = sizeof(dispatch((T*)0)) );
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof_dispatch<T>::value>::type type;
|
||||
};
|
||||
#else
|
||||
template <class T>
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
typename
|
||||
#endif
|
||||
exception_detail::enable_error_info_return_type<T>::type
|
||||
enable_error_info( T const & x )
|
||||
{
|
||||
return
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
typename
|
||||
#endif
|
||||
exception_detail::enable_error_info_return_type<T>::type(x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
16
include/boost/exception/error_info.hpp
Normal file
16
include/boost/exception/error_info.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//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_0E57632CCA3011DCB876FD9955D89593
|
||||
#define UUID_0E57632CCA3011DCB876FD9955D89593
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <class Tag,class T>
|
||||
class error_info;
|
||||
}
|
||||
|
||||
#endif
|
127
include/boost/exception/exception.hpp
Normal file
127
include/boost/exception/exception.hpp
Normal file
@ -0,0 +1,127 @@
|
||||
//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
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/exception/detail/counted_base.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <class T>
|
||||
class shared_ptr;
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class error_info_base;
|
||||
|
||||
struct
|
||||
error_info_container:
|
||||
public exception_detail::counted_base
|
||||
{
|
||||
virtual char const * diagnostic_information( char const *, std::type_info const & ) const = 0;
|
||||
virtual shared_ptr<error_info_base const> get( std::type_info const & ) const = 0;
|
||||
virtual void set( shared_ptr<error_info_base const> const & ) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
template <class Tag,class T>
|
||||
class error_info;
|
||||
|
||||
template <class E,class Tag,class T>
|
||||
E const & operator<<( E const &, error_info<Tag,T> const & );
|
||||
|
||||
template <class ErrorInfo,class E>
|
||||
shared_ptr<typename ErrorInfo::value_type const> get_error_info( E const & );
|
||||
|
||||
class
|
||||
exception
|
||||
{
|
||||
public:
|
||||
|
||||
virtual
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return diagnostic_information();
|
||||
}
|
||||
|
||||
virtual
|
||||
char const *
|
||||
diagnostic_information() const throw()
|
||||
{
|
||||
return _diagnostic_information(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
exception()
|
||||
{
|
||||
}
|
||||
|
||||
exception( exception const & e ):
|
||||
data_(e.data_)
|
||||
{
|
||||
}
|
||||
|
||||
char const *
|
||||
_diagnostic_information( char const * std_what ) const throw()
|
||||
{
|
||||
if( data_ )
|
||||
try
|
||||
{
|
||||
char const * w = data_->diagnostic_information(std_what,typeid(*this));
|
||||
BOOST_ASSERT(0!=w);
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
return std_what ? std_what : typeid(*this).name();
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
||||
//Force class exception to be abstract.
|
||||
//Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
|
||||
virtual ~exception() throw()=0;
|
||||
#else
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
shared_ptr<exception_detail::error_info_base const> get( std::type_info const & ) const;
|
||||
void set( shared_ptr<exception_detail::error_info_base const> const & ) const;
|
||||
|
||||
template <class E,class Tag,class T>
|
||||
friend E const & operator<<( E const &, error_info<Tag,T> const & );
|
||||
|
||||
template <class ErrorInfo,class E>
|
||||
friend shared_ptr<typename ErrorInfo::value_type const> get_error_info( E const & );
|
||||
|
||||
intrusive_ptr<exception_detail::error_info_container> mutable data_;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above.
|
||||
inline
|
||||
exception::
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
242
include/boost/exception/info.hpp
Normal file
242
include/boost/exception/info.hpp
Normal file
@ -0,0 +1,242 @@
|
||||
//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/type.hpp>
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/exception/error_info.hpp>
|
||||
#include <boost/exception/to_string_stub.hpp>
|
||||
#include <boost/current_function.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <map>
|
||||
|
||||
#define BOOST_ERROR_INFO\
|
||||
::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\
|
||||
::boost::throw_file(__FILE__) <<\
|
||||
::boost::throw_line((int)__LINE__)
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
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;
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
error_info_base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual std::type_info const & tag_typeid() const = 0;
|
||||
virtual std::string value_as_string() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~error_info_base()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 ):
|
||||
value_(value)
|
||||
{
|
||||
}
|
||||
|
||||
value_type const &
|
||||
value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::type_info const &
|
||||
tag_typeid() const
|
||||
{
|
||||
return typeid(type<Tag>);
|
||||
}
|
||||
|
||||
std::string
|
||||
value_as_string() const
|
||||
{
|
||||
return to_string_stub(value_);
|
||||
}
|
||||
|
||||
value_type const value_;
|
||||
};
|
||||
|
||||
template <class E,class Tag,class T>
|
||||
E const &
|
||||
operator<<( E const & x, error_info<Tag,T> const & v )
|
||||
{
|
||||
shared_ptr< error_info<Tag,T> > p( new error_info<Tag,T>(v) );
|
||||
x.set(p);
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class ErrorInfo,class E>
|
||||
shared_ptr<typename ErrorInfo::value_type const>
|
||||
get_error_info( E const & some_exception )
|
||||
{
|
||||
if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
|
||||
if( shared_ptr<exception_detail::error_info_base const> eib = x->get(typeid(ErrorInfo)) )
|
||||
{
|
||||
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
|
||||
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>();
|
||||
}
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
error_info_container_impl:
|
||||
public error_info_container
|
||||
{
|
||||
public:
|
||||
|
||||
error_info_container_impl():
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
~error_info_container_impl() throw()
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr<error_info_base const>
|
||||
get( std::type_info const & ti ) const
|
||||
{
|
||||
error_info_map::const_iterator i=info_.find(typeinfo(ti));
|
||||
if( info_.end()!=i )
|
||||
{
|
||||
shared_ptr<error_info_base const> const & p = i->second;
|
||||
BOOST_ASSERT( typeid(*p)==ti );
|
||||
return p;
|
||||
}
|
||||
return shared_ptr<error_info_base const>();
|
||||
}
|
||||
|
||||
void
|
||||
set( shared_ptr<error_info_base const> const & x )
|
||||
{
|
||||
BOOST_ASSERT(x);
|
||||
info_[typeinfo(typeid(*x))] = x;
|
||||
what_.clear();
|
||||
}
|
||||
|
||||
char const *
|
||||
diagnostic_information( char const * std_what, std::type_info const & exception_type ) const
|
||||
{
|
||||
if( what_.empty() )
|
||||
{
|
||||
std::string tmp;
|
||||
if( std_what )
|
||||
{
|
||||
tmp += std_what;
|
||||
tmp += '\n';
|
||||
}
|
||||
tmp += "Dynamic exception type: ";
|
||||
tmp += exception_type.name();
|
||||
tmp += '\n';
|
||||
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';
|
||||
}
|
||||
what_.swap(tmp);
|
||||
}
|
||||
return what_.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class exception;
|
||||
|
||||
struct
|
||||
typeinfo
|
||||
{
|
||||
std::type_info const * type;
|
||||
|
||||
explicit
|
||||
typeinfo( std::type_info const & t ):
|
||||
type(&t)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
operator<( typeinfo const & b ) const
|
||||
{
|
||||
return 0!=(type->before(*b.type));
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map< typeinfo, shared_ptr<error_info_base const> > error_info_map;
|
||||
error_info_map info_;
|
||||
std::string mutable what_;
|
||||
int mutable count_;
|
||||
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
++count_;
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
exception::
|
||||
set( shared_ptr<exception_detail::error_info_base const> const & x ) const
|
||||
{
|
||||
if( !data_ )
|
||||
data_ = intrusive_ptr<exception_detail::error_info_container>(new exception_detail::error_info_container_impl);
|
||||
data_->set(x);
|
||||
}
|
||||
|
||||
inline
|
||||
shared_ptr<exception_detail::error_info_base const>
|
||||
exception::
|
||||
get( std::type_info const & ti ) const
|
||||
{
|
||||
if( data_ )
|
||||
return data_->get(ti);
|
||||
else
|
||||
return shared_ptr<exception_detail::error_info_base const>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
64
include/boost/exception/info_tuple.hpp
Normal file
64
include/boost/exception/info_tuple.hpp
Normal 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_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 >
|
||||
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 >
|
||||
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 >
|
||||
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
|
72
include/boost/exception/to_string.hpp
Normal file
72
include/boost/exception/to_string.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
//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>
|
||||
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>
|
||||
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
|
96
include/boost/exception/to_string_stub.hpp
Normal file
96
include/boost/exception/to_string_stub.hpp
Normal file
@ -0,0 +1,96 @@
|
||||
//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>
|
||||
std::string
|
||||
dispatch( T const & x, Stub s )
|
||||
{
|
||||
return to_string_dispatcher<has_to_string<T>::value>::convert(x,s);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::string
|
||||
string_stub_dump( T const & x )
|
||||
{
|
||||
return "[ " + exception_detail::object_hex_dump(x) + " ]";
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
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>
|
||||
std::string
|
||||
to_string_stub( T const & x, Stub s )
|
||||
{
|
||||
return exception_detail::to_string_dispatch::dispatch(x,s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user