Merging from trunk: new function diagnostic_information_what, and mutable error info access.

[SVN r56477]
This commit is contained in:
Emil Dotchevski
2009-09-29 20:38:11 +00:00
parent d32fff4fb2
commit 6434a2031c
32 changed files with 9991 additions and 9480 deletions

View File

@ -49,12 +49,18 @@ boost
return value_;
}
value_type &
value()
{
return value_;
}
private:
char const * tag_typeid_name() const;
std::string value_as_string() const;
value_type const value_;
value_type value_;
};
}

View File

@ -44,14 +44,14 @@ boost
inline
char const *
get_diagnostic_information( exception const & x )
get_diagnostic_information( exception const & x, char const * header )
{
if( error_info_container * c=x.data_.get() )
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
return c->diagnostic_information();
return c->diagnostic_information(header);
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
@ -63,7 +63,7 @@ boost
inline
std::string
diagnostic_information_impl( boost::exception const * be, std::exception const * se )
diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
{
BOOST_ASSERT(be||se);
#ifndef BOOST_NO_RTTI
@ -72,6 +72,13 @@ boost
if( !be )
be = dynamic_cast<boost::exception const *>(se);
#endif
char const * wh=0;
if( with_what && se )
{
wh=se->what();
if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
return wh;
}
std::ostringstream tmp;
if( be )
{
@ -92,12 +99,12 @@ boost
tmp << std::string("Dynamic exception type: ") <<
(be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
#endif
if( se )
tmp << "std::exception::what: " << se->what() << '\n';
if( with_what && se )
tmp << "std::exception::what: " << wh << '\n';
if( be )
if( char const * s=exception_detail::get_diagnostic_information(*be) )
if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
if( *s )
tmp << s;
return s;
return tmp.str();
}
}
@ -107,7 +114,7 @@ boost
typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
diagnostic_information( T const & e )
{
return exception_detail::diagnostic_information_impl(&e,0);
return exception_detail::diagnostic_information_impl(&e,0,true);
}
template <class T>
@ -115,7 +122,28 @@ boost
typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
diagnostic_information( T const & e )
{
return exception_detail::diagnostic_information_impl(0,&e);
return exception_detail::diagnostic_information_impl(0,&e,true);
}
inline
char const *
diagnostic_information_what( exception const & e ) throw()
{
char const * w=0;
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
(void) exception_detail::diagnostic_information_impl(&e,0,false);
return exception_detail::get_diagnostic_information(e,0);
#ifndef BOOST_NO_EXCEPTIONS
}
catch(
... )
{
}
#endif
return w;
}
}
@ -131,7 +159,7 @@ boost
boost::exception const * be=current_exception_cast<boost::exception const>();
std::exception const * se=current_exception_cast<std::exception const>();
if( be || se )
return exception_detail::diagnostic_information_impl(be,se);
return exception_detail::diagnostic_information_impl(be,se,true);
else
return "No diagnostic information available.";
}

View File

@ -143,9 +143,9 @@ boost
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 char const * diagnostic_information( char const * ) const = 0;
virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
virtual void add_ref() const = 0;
virtual void release() const = 0;
@ -169,7 +169,7 @@ boost
template <>
struct get_info<throw_line>;
char const * get_diagnostic_information( exception const & );
char const * get_diagnostic_information( exception const &, char const * );
}
class
@ -231,7 +231,7 @@ boost
return x;
}
friend char const * exception_detail::get_diagnostic_information( exception const & );
friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
template <class E,class Tag,class T>
friend E const & operator<<( E const &, error_info<Tag,T> const & );

View File

@ -22,16 +22,16 @@ boost
get_info
{
static
typename ErrorInfo::value_type const *
typename ErrorInfo::value_type *
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)) )
if( shared_ptr<exception_detail::error_info_base> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
{
#ifndef BOOST_NO_RTTI
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
#endif
ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());
ErrorInfo * w = static_cast<ErrorInfo *>(eib.get());
return &w->value();
}
return 0;
@ -43,7 +43,7 @@ boost
get_info<throw_function>
{
static
char const * const *
char const * *
get( exception const & x )
{
return x.throw_function_ ? &x.throw_function_ : 0;
@ -55,7 +55,7 @@ boost
get_info<throw_file>
{
static
char const * const *
char const * *
get( exception const & x )
{
return x.throw_file_ ? &x.throw_file_ : 0;
@ -67,12 +67,26 @@ boost
get_info<throw_line>
{
static
int const *
int *
get( exception const & x )
{
return x.throw_line_!=-1 ? &x.throw_line_ : 0;
}
};
template <class T,class R>
struct
get_error_info_return_type
{
typedef R * type;
};
template <class T,class R>
struct
get_error_info_return_type<T const,R>
{
typedef R const * type;
};
}
#ifdef BOOST_NO_RTTI
@ -83,11 +97,18 @@ boost
{
return exception_detail::get_info<ErrorInfo>::get(x);
}
template <class ErrorInfo>
inline
typename ErrorInfo::value_type *
get_error_info( boost::exception & x )
{
return exception_detail::get_info<ErrorInfo>::get(x);
}
#else
template <class ErrorInfo,class E>
inline
typename ErrorInfo::value_type const *
get_error_info( E const & some_exception )
typename exception_detail::get_error_info_return_type<E,typename ErrorInfo::value_type>::type
get_error_info( E & some_exception )
{
if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
return exception_detail::get_info<ErrorInfo>::get(*x);

View File

@ -75,34 +75,36 @@ boost
}
void
set( shared_ptr<error_info_base const> const & x, type_info_ const & typeid_ )
set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
{
BOOST_ASSERT(x);
info_[typeid_] = x;
diagnostic_info_str_.clear();
}
shared_ptr<error_info_base const>
shared_ptr<error_info_base>
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;
shared_ptr<error_info_base> 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>();
return shared_ptr<error_info_base>();
}
char const *
diagnostic_information() const
diagnostic_information( char const * header ) const
{
if( diagnostic_info_str_.empty() )
if( header )
{
BOOST_ASSERT(*header!=0);
std::ostringstream tmp;
tmp << header;
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;
@ -117,7 +119,7 @@ boost
friend class boost::exception;
typedef std::map< type_info_, shared_ptr<error_info_base const> > error_info_map;
typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
error_info_map info_;
mutable std::string diagnostic_info_str_;
mutable int count_;