forked from boostorg/exception
Boost Exception now works with BOOST_NO_RTTI and/or BOOST_NO_TYPEID.
[SVN r48429]
This commit is contained in:
38
include/boost/exception/detail/error_info_base.hpp
Normal file
38
include/boost/exception/detail/error_info_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_CE6983AC753411DDA764247956D89593
|
||||
#define UUID_CE6983AC753411DDA764247956D89593
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#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:
|
||||
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~error_info_base()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
47
include/boost/exception/detail/get_boost_exception.hpp
Normal file
47
include/boost/exception/detail/get_boost_exception.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
//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_B9A8291074CA11DD94BFC77156D89593
|
||||
#define UUID_B9A8291074CA11DD94BFC77156D89593
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
#ifdef BOOST_NO_RTTI
|
||||
template <class T>
|
||||
exception const *
|
||||
get_boost_exception( T const * )
|
||||
{
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
exception & x )
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
template <class T>
|
||||
exception const *
|
||||
get_boost_exception( T const * x )
|
||||
{
|
||||
return dynamic_cast<exception const *>(x);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -6,6 +6,7 @@
|
||||
#ifndef UUID_6F463AC838DF11DDA3E6909F56D89593
|
||||
#define UUID_6F463AC838DF11DDA3E6909F56D89593
|
||||
|
||||
#include <boost/exception/detail/type_info.hpp>
|
||||
#include <iomanip>
|
||||
#include <typeinfo>
|
||||
#include <ios>
|
||||
@ -24,7 +25,7 @@ boost
|
||||
object_hex_dump( T const & x, size_t max_size=16 )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: ";
|
||||
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);
|
||||
|
62
include/boost/exception/detail/type_info.hpp
Normal file
62
include/boost/exception/detail/type_info.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
//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 ErrorInfoTag>
|
||||
inline
|
||||
char const *
|
||||
error_info_value()
|
||||
{
|
||||
return BOOST_CURRENT_FUNCTION;
|
||||
}
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
typedef detail::sp_typeinfo type_info_;
|
||||
|
||||
#ifdef BOOST_NO_TYPEID
|
||||
typedef type_info_ type_info_wrapper;
|
||||
#else
|
||||
struct
|
||||
type_info_wrapper
|
||||
{
|
||||
type_info_ const * type;
|
||||
|
||||
explicit
|
||||
type_info_wrapper( type_info_ const & t ):
|
||||
type(&t)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
operator<( type_info_wrapper const & b ) const
|
||||
{
|
||||
return 0!=(type->before(*b.type));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <class ErrorInfoTag>
|
||||
inline
|
||||
char const *
|
||||
type_name()
|
||||
{
|
||||
return error_info_value<ErrorInfoTag>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define BOOST_EXCEPTION_STATIC_TYPEID(T) BOOST_SP_TYPEID(T)
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user