mirror of
https://github.com/boostorg/exception.git
synced 2025-07-17 14:32:05 +02:00
fixed compile errors, removed tabs as required.
[SVN r44114]
This commit is contained in:
@ -13,47 +13,47 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
class
|
||||
unknown_exception:
|
||||
public exception,
|
||||
public std::exception
|
||||
{
|
||||
public:
|
||||
{
|
||||
class
|
||||
unknown_exception:
|
||||
public exception,
|
||||
public std::exception
|
||||
{
|
||||
public:
|
||||
|
||||
explicit
|
||||
unknown_exception()
|
||||
{
|
||||
}
|
||||
explicit
|
||||
unknown_exception()
|
||||
{
|
||||
}
|
||||
|
||||
explicit
|
||||
unknown_exception( boost::exception const & x ):
|
||||
boost::exception(x)
|
||||
{
|
||||
}
|
||||
};
|
||||
explicit
|
||||
unknown_exception( boost::exception const & x ):
|
||||
boost::exception(x)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef intrusive_ptr<exception_detail::clone_base const> exception_ptr;
|
||||
typedef intrusive_ptr<exception_detail::clone_base const> exception_ptr;
|
||||
|
||||
template <class T>
|
||||
exception_ptr
|
||||
clone_exception( T const & e )
|
||||
{
|
||||
if( boost::exception_detail::cloning_base const * cb = dynamic_cast<boost::exception_detail::cloning_base const *>(&e) )
|
||||
if( exception_detail::clone_base const * c = cb->clone() )
|
||||
return exception_ptr(c);
|
||||
if( boost::exception const * be = dynamic_cast<boost::exception const *>(&e) )
|
||||
return exception_ptr(exception_detail::make_clone(unknown_exception(*be)));
|
||||
else
|
||||
return exception_ptr(exception_detail::make_clone(unknown_exception()));
|
||||
}
|
||||
template <class T>
|
||||
exception_ptr
|
||||
clone_exception( T const & e )
|
||||
{
|
||||
if( boost::exception_detail::cloning_base const * cb = dynamic_cast<boost::exception_detail::cloning_base const *>(&e) )
|
||||
if( exception_detail::clone_base const * c = cb->clone() )
|
||||
return exception_ptr(c);
|
||||
if( boost::exception const * be = dynamic_cast<boost::exception const *>(&e) )
|
||||
return exception_ptr(exception_detail::make_clone(unknown_exception(*be)));
|
||||
else
|
||||
return exception_ptr(exception_detail::make_clone(unknown_exception()));
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
rethrow_exception( exception_ptr const & p )
|
||||
{
|
||||
p->rethrow();
|
||||
}
|
||||
}
|
||||
inline
|
||||
void
|
||||
rethrow_exception( exception_ptr const & p )
|
||||
{
|
||||
p->rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,20 +8,20 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class clone_base;
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class clone_base;
|
||||
|
||||
class
|
||||
cloning_base
|
||||
{
|
||||
public:
|
||||
class
|
||||
cloning_base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual clone_base const * clone() const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
virtual clone_base const * clone() const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,31 +8,31 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
counted_base
|
||||
{
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_add_ref( counted_base const * c )
|
||||
{
|
||||
c->add_ref();
|
||||
}
|
||||
{
|
||||
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();
|
||||
}
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_release( counted_base const * c )
|
||||
{
|
||||
c->release();
|
||||
}
|
||||
|
||||
virtual void add_ref() const=0;
|
||||
virtual void release() const=0;
|
||||
};
|
||||
}
|
||||
}
|
||||
virtual void add_ref() const=0;
|
||||
virtual void release() const=0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,60 +10,60 @@
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
};
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
struct
|
||||
error_info_injector:
|
||||
public T,
|
||||
public exception
|
||||
{
|
||||
explicit
|
||||
error_info_injector( T const & x ):
|
||||
T(x)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct large_size { char c[256]; };
|
||||
large_size dispatch( exception * );
|
||||
struct large_size { char c[256]; };
|
||||
large_size dispatch( exception * );
|
||||
|
||||
struct small_size { };
|
||||
small_size dispatch( void * );
|
||||
struct small_size { };
|
||||
small_size dispatch( void * );
|
||||
|
||||
template <class,size_t>
|
||||
struct enable_error_info_helper;
|
||||
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(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_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>
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
typename exception_detail::enable_error_info_return_type<T>::type
|
||||
enable_error_info( T const & x )
|
||||
{
|
||||
return typename exception_detail::enable_error_info_return_type<T>::type(x);
|
||||
}
|
||||
}
|
||||
template <class T>
|
||||
typename exception_detail::enable_error_info_return_type<T>::type
|
||||
enable_error_info( T const & x )
|
||||
{
|
||||
return typename exception_detail::enable_error_info_return_type<T>::type(x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -14,135 +14,135 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
clone_base:
|
||||
public counted_base
|
||||
{
|
||||
public:
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
clone_base:
|
||||
public counted_base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void rethrow() const=0;
|
||||
};
|
||||
virtual void rethrow() const=0;
|
||||
};
|
||||
|
||||
struct
|
||||
bad_alloc_impl:
|
||||
public clone_base,
|
||||
public std::bad_alloc
|
||||
{
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
}
|
||||
struct
|
||||
bad_alloc_impl:
|
||||
public clone_base,
|
||||
public std::bad_alloc
|
||||
{
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
}
|
||||
void
|
||||
release() const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
};
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
clone_base * make_clone( T const & );
|
||||
template <class T>
|
||||
clone_base * make_clone( T const & );
|
||||
|
||||
template <class T>
|
||||
class
|
||||
clone_impl:
|
||||
public T,
|
||||
public cloning_base
|
||||
{
|
||||
public:
|
||||
template <class T>
|
||||
class
|
||||
clone_impl:
|
||||
public T,
|
||||
public cloning_base
|
||||
{
|
||||
public:
|
||||
|
||||
explicit
|
||||
clone_impl( T const & x ):
|
||||
T(x)
|
||||
{
|
||||
}
|
||||
explicit
|
||||
clone_impl( T const & x ):
|
||||
T(x)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
clone_base const *
|
||||
clone() const
|
||||
{
|
||||
return make_clone<T>(*this);
|
||||
}
|
||||
};
|
||||
clone_base const *
|
||||
clone() const
|
||||
{
|
||||
return make_clone<T>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class
|
||||
exception_clone:
|
||||
public T,
|
||||
public clone_base
|
||||
{
|
||||
public:
|
||||
template <class T>
|
||||
class
|
||||
exception_clone:
|
||||
public T,
|
||||
public clone_base
|
||||
{
|
||||
public:
|
||||
|
||||
explicit
|
||||
exception_clone( T const & x ):
|
||||
T(x),
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
explicit
|
||||
exception_clone( T const & x ):
|
||||
T(x),
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
detail::atomic_count mutable count_;
|
||||
detail::atomic_count mutable count_;
|
||||
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
++count_;
|
||||
}
|
||||
void
|
||||
add_ref() const
|
||||
{
|
||||
++count_;
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
void
|
||||
release() const
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
|
||||
void
|
||||
rethrow() const
|
||||
{
|
||||
throw clone_impl<T>(*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>
|
||||
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_exception_cloning( T const & x )
|
||||
{
|
||||
return exception_detail::clone_impl<T>(x);
|
||||
}
|
||||
}
|
||||
template <class T>
|
||||
exception_detail::clone_impl<T>
|
||||
enable_exception_cloning( T const & x )
|
||||
{
|
||||
return exception_detail::clone_impl<T>(x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <class Tag,class T>
|
||||
class error_info;
|
||||
}
|
||||
{
|
||||
template <class Tag,class T>
|
||||
class error_info;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -12,79 +12,79 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
template <class T>
|
||||
class shared_ptr;
|
||||
{
|
||||
template <class T>
|
||||
class shared_ptr;
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class error_info_base;
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class error_info_base;
|
||||
|
||||
struct
|
||||
error_info_container:
|
||||
public exception_detail::counted_base
|
||||
{
|
||||
virtual char const * what( 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;
|
||||
};
|
||||
}
|
||||
struct
|
||||
error_info_container:
|
||||
public exception_detail::counted_base
|
||||
{
|
||||
virtual char const * what( 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 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 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 & );
|
||||
template <class ErrorInfo,class E>
|
||||
shared_ptr<typename ErrorInfo::value_type const> get_error_info( E const & );
|
||||
|
||||
class
|
||||
exception
|
||||
{
|
||||
public:
|
||||
class
|
||||
exception
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~exception() throw()=0;
|
||||
virtual char const * what() const throw();
|
||||
virtual ~exception() throw()=0;
|
||||
virtual char const * what() const throw();
|
||||
|
||||
private:
|
||||
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;
|
||||
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 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 & );
|
||||
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_;
|
||||
};
|
||||
intrusive_ptr<exception_detail::error_info_container> mutable data_;
|
||||
};
|
||||
|
||||
inline
|
||||
exception::
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
inline
|
||||
exception::
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
char const *
|
||||
exception::
|
||||
what() const throw()
|
||||
{
|
||||
if( data_ )
|
||||
try
|
||||
{
|
||||
char const * w = data_->what(typeid(*this));
|
||||
BOOST_ASSERT(0!=w);
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
return typeid(*this).name();
|
||||
}
|
||||
}
|
||||
inline
|
||||
char const *
|
||||
exception::
|
||||
what() const throw()
|
||||
{
|
||||
if( data_ )
|
||||
try
|
||||
{
|
||||
char const * w = data_->what(typeid(*this));
|
||||
BOOST_ASSERT(0!=w);
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
return typeid(*this).name();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -15,219 +15,219 @@
|
||||
#include <map>
|
||||
|
||||
#define BOOST_ERROR_INFO\
|
||||
::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\
|
||||
::boost::throw_file(__FILE__) <<\
|
||||
::boost::throw_line((int)__LINE__)
|
||||
::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;
|
||||
{
|
||||
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:
|
||||
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;
|
||||
};
|
||||
}
|
||||
virtual std::type_info const & tag_typeid() const = 0;
|
||||
virtual std::string value_as_string() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
template <class Tag,class T>
|
||||
class
|
||||
error_info:
|
||||
public exception_detail::error_info_base
|
||||
{
|
||||
public:
|
||||
template <class Tag,class T>
|
||||
class
|
||||
error_info:
|
||||
public exception_detail::error_info_base
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef T value_type;
|
||||
|
||||
error_info( value_type const & value ):
|
||||
value_(value)
|
||||
{
|
||||
}
|
||||
error_info( value_type const & value ):
|
||||
value_(value)
|
||||
{
|
||||
}
|
||||
|
||||
value_type const &
|
||||
value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
value_type const &
|
||||
value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
std::type_info const &
|
||||
tag_typeid() const
|
||||
{
|
||||
return typeid(type<Tag>);
|
||||
}
|
||||
std::type_info const &
|
||||
tag_typeid() const
|
||||
{
|
||||
return typeid(type<Tag>);
|
||||
}
|
||||
|
||||
std::string
|
||||
value_as_string() const
|
||||
{
|
||||
return to_string_stub(value_);
|
||||
}
|
||||
std::string
|
||||
value_as_string() const
|
||||
{
|
||||
return to_string_stub(value_);
|
||||
}
|
||||
|
||||
value_type const value_;
|
||||
};
|
||||
value_type const value_;
|
||||
};
|
||||
|
||||
template <class ErrorInfo>
|
||||
struct
|
||||
error_info_type
|
||||
{
|
||||
typedef typename ErrorInfo::value_type value_type;
|
||||
};
|
||||
template <class ErrorInfo>
|
||||
struct
|
||||
error_info_type
|
||||
{
|
||||
typedef typename ErrorInfo::value_type value_type;
|
||||
};
|
||||
|
||||
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 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>();
|
||||
}
|
||||
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:
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
class
|
||||
error_info_container_impl:
|
||||
public error_info_container
|
||||
{
|
||||
public:
|
||||
|
||||
error_info_container_impl():
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
error_info_container_impl():
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
~error_info_container_impl() throw()
|
||||
{
|
||||
}
|
||||
~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>();
|
||||
}
|
||||
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();
|
||||
}
|
||||
void
|
||||
set( shared_ptr<error_info_base const> const & x )
|
||||
{
|
||||
BOOST_ASSERT(x);
|
||||
info_[typeinfo(typeid(*x))] = x;
|
||||
what_.clear();
|
||||
}
|
||||
|
||||
char const *
|
||||
what( std::type_info const & exception_type ) const
|
||||
{
|
||||
if( what_.empty() )
|
||||
{
|
||||
std::string 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();
|
||||
}
|
||||
char const *
|
||||
what( std::type_info const & exception_type ) const
|
||||
{
|
||||
if( what_.empty() )
|
||||
{
|
||||
std::string 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:
|
||||
private:
|
||||
|
||||
friend class exception;
|
||||
friend class exception;
|
||||
|
||||
struct
|
||||
typeinfo
|
||||
{
|
||||
std::type_info const * type;
|
||||
struct
|
||||
typeinfo
|
||||
{
|
||||
std::type_info const * type;
|
||||
|
||||
explicit
|
||||
typeinfo( std::type_info const & t ):
|
||||
type(&t)
|
||||
{
|
||||
}
|
||||
explicit
|
||||
typeinfo( std::type_info const & t ):
|
||||
type(&t)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
operator<( typeinfo const & b ) const
|
||||
{
|
||||
return 0!=(type->before(*b.type));
|
||||
}
|
||||
};
|
||||
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_;
|
||||
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
|
||||
add_ref() const
|
||||
{
|
||||
++count_;
|
||||
}
|
||||
|
||||
void
|
||||
release() const
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
}
|
||||
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
|
||||
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>();
|
||||
}
|
||||
}
|
||||
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
|
||||
|
@ -11,54 +11,54 @@
|
||||
|
||||
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 >
|
||||
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 >
|
||||
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>();
|
||||
}
|
||||
}
|
||||
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
|
||||
|
@ -10,18 +10,18 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template <class T>
|
||||
std::string
|
||||
to_string( T const & x )
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << x;
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template <class T>
|
||||
std::string
|
||||
to_string( T const & x )
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << x;
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -12,138 +12,135 @@
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <bool ShiftLeftAvailable>
|
||||
struct shift_left_dispatcher;
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <bool ShiftLeftAvailable>
|
||||
struct shift_left_dispatcher;
|
||||
|
||||
template <>
|
||||
struct
|
||||
shift_left_dispatcher<true>
|
||||
{
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
static
|
||||
void
|
||||
convert( std::basic_ostream<CharT,Traits> & out, T const & x, Stub )
|
||||
{
|
||||
out << x;
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct
|
||||
shift_left_dispatcher<true>
|
||||
{
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
static
|
||||
void
|
||||
convert( std::basic_ostream<CharT,Traits> & out, T const & x, Stub )
|
||||
{
|
||||
out << x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
shift_left_dispatcher<false>
|
||||
{
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
static
|
||||
void
|
||||
convert( std::basic_ostream<CharT,Traits> & out, T const & x, Stub s )
|
||||
{
|
||||
out << s(x);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct
|
||||
shift_left_dispatcher<false>
|
||||
{
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
static
|
||||
void
|
||||
convert( std::basic_ostream<CharT,Traits> & out, T const & x, Stub s )
|
||||
{
|
||||
out << s(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
shift_left_dispatch
|
||||
{
|
||||
template <class T,class CharT,class Traits>
|
||||
char operator<<( std::basic_ostream<CharT,Traits> &, T );
|
||||
namespace
|
||||
shift_left_dispatch
|
||||
{
|
||||
template <class T,class CharT,class Traits>
|
||||
char operator<<( std::basic_ostream<CharT,Traits> &, T );
|
||||
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
void
|
||||
dispatch( std::basic_ostream<CharT,Traits> & out, T const & x, Stub s )
|
||||
{
|
||||
shift_left_dispatcher<1!=sizeof(out<<x)>::convert(out,x,s);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <class T,class CharT,class Traits,class Stub>
|
||||
void
|
||||
dispatch( std::basic_ostream<CharT,Traits> & out, T const & x, Stub s )
|
||||
{
|
||||
shift_left_dispatcher<1!=sizeof(out<<x)>::convert(out,x,s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <bool ToStringAvailable>
|
||||
struct to_string_dispatcher;
|
||||
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<true>
|
||||
{
|
||||
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 )
|
||||
{
|
||||
std::ostringstream out;
|
||||
shift_left_dispatch::dispatch(out,x,s);
|
||||
return out.str();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct
|
||||
to_string_dispatcher<false>
|
||||
{
|
||||
template <class T,class Stub>
|
||||
static
|
||||
std::string
|
||||
convert( T const & x, Stub s )
|
||||
{
|
||||
std::ostringstream out;
|
||||
shift_left_dispatch::dispatch(out,x,s);
|
||||
return out.str();
|
||||
}
|
||||
};
|
||||
namespace
|
||||
to_string_dispatch
|
||||
{
|
||||
template <class T>
|
||||
char to_string( T );
|
||||
|
||||
namespace
|
||||
to_string_dispatch
|
||||
{
|
||||
template <class T>
|
||||
char to_string( T );
|
||||
template <class T,class Stub>
|
||||
std::string
|
||||
dispatch( T const & x, Stub s )
|
||||
{
|
||||
return to_string_dispatcher<1!=sizeof(to_string(x))>::convert(x,s);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T,class Stub>
|
||||
std::string
|
||||
dispatch( T const & x, Stub s )
|
||||
{
|
||||
return to_string_dispatcher<1!=sizeof(to_string(x))>::convert(x,s);
|
||||
}
|
||||
}
|
||||
template <class T>
|
||||
std::string
|
||||
string_stub_dump( T const & x )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: ";
|
||||
size_t n=sizeof(T)>16?16:sizeof(T);
|
||||
s.fill('0');
|
||||
s.width(2);
|
||||
for( unsigned char const * b=reinterpret_cast<unsigned char const *>(&x),* e=b+n; b!=e; ++b )
|
||||
s << std::setw(2) << std::hex << (unsigned int)*b << " ";
|
||||
s << "]";
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::string
|
||||
string_stub_dump( T const & x )
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: ";
|
||||
size_t n=sizeof(T)>16?16:sizeof(T);
|
||||
s.fill('0');
|
||||
s.width(2);
|
||||
for( unsigned char const * b=reinterpret_cast<unsigned char const *>(&x),* e=b+n; b!=e; ++b )
|
||||
s << std::setw(2) << std::hex << (unsigned int)*b << " ";
|
||||
s << "]";
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
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>
|
||||
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);
|
||||
}
|
||||
|
||||
template <class T,class Stub>
|
||||
std::string
|
||||
to_string_stub( T const & x, Stub s )
|
||||
{
|
||||
return exception_detail::to_string_dispatch::dispatch(x,s);
|
||||
}
|
||||
|
||||
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) + ')';
|
||||
}
|
||||
}
|
||||
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) + ')';
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user