mirror of
https://github.com/boostorg/exception.git
synced 2025-07-13 04:26:44 +02:00
mutable get_error_info support
[SVN r55707]
This commit is contained in:
@ -28,7 +28,10 @@ namespace
|
||||
boost
|
||||
{
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoIncludeSPAN">template <class ErrorInfo,class E>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const * <span class="RenoLink"><a href="get_error_info.html">get_error_info</a></span>( E const & x );</span></span>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info::value_type">error_info::value_type</a></span> const * <span class="RenoLink"><a href="get_error_info">get_error_info</a></span>( E const & x );
|
||||
|
||||
template <class ErrorInfo,class E>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info::value_type">error_info::value_type</a></span> * <span class="RenoLink"><a href="get_error_info">get_error_info</a></span>( E & x );</span></span>
|
||||
}</pre>
|
||||
</div></div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
|
||||
<h3>See Also:</h3>
|
||||
|
@ -36,7 +36,8 @@ boost
|
||||
<span class="RenoIncludeSPAN"> typedef T <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span>;</span>
|
||||
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_error_info.html">error_info</a></span>( <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & v );</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;
|
||||
<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> & <span class="RenoLink"><a href="error_info_value.html">value</a></span>();</span>
|
||||
};</span>
|
||||
|
||||
<span class="RenoIncludeSPAN">template <class E, class Tag, class T>
|
||||
|
@ -34,7 +34,8 @@ boost
|
||||
<span class="RenoIncludeSPAN"> typedef T <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span>;</span>
|
||||
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_error_info.html">error_info</a></span>( <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & v );</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;
|
||||
<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> & <span class="RenoLink"><a href="error_info_value.html">value</a></span>();</span>
|
||||
};</span>
|
||||
}</pre>
|
||||
</div><h4>Requirements:</h4>
|
||||
|
@ -22,9 +22,10 @@
|
||||
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>error_info::value</h3>
|
||||
</div>
|
||||
<div class="RenoIncludeDIV"><p><span class="RenoEscape">#<!--<wiki>`#</wiki>--></span>include <<span class="RenoLink"><a href="boost_exception_info_hpp.html">boost/exception/info.hpp</a></span>></p>
|
||||
<pre><span class="RenoIncludeSPAN"><span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink">value</span>() const;</span></pre>
|
||||
<pre><span class="RenoIncludeSPAN"><span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink">value</span>() const;
|
||||
<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> & <span class="RenoLink">value</span>();</span></pre>
|
||||
</div><h4>Description:</h4>
|
||||
<p>Returns a const reference to the copy of the value passed to <span class="RenoLink"><a href="error_info.html">error_info</a></span>'s constructor stored in the <span class="RenoLink"><a href="error_info.html">error_info</a></span> object.</p>
|
||||
<p>Returns a (const) reference to the copy of the value passed to <span class="RenoLink"><a href="error_info.html">error_info</a></span>'s constructor stored in the <span class="RenoLink"><a href="error_info.html">error_info</a></span> object.</p>
|
||||
<h4>Throws:</h4>
|
||||
<p>Nothing.</p>
|
||||
</div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
|
||||
|
@ -30,7 +30,6 @@
|
||||
<div class="RenoPageList"><a href="error_info.html">error_info<br/>
|
||||
</a><a href="error_info_error_info.html">error_info::error_info<br/>
|
||||
</a><a href="error_info_value.html">error_info::value<br/>
|
||||
</a><a href="get_error_info.html">get_error_info<br/>
|
||||
</a></div>
|
||||
</div>
|
||||
<!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
|
||||
|
@ -25,7 +25,10 @@
|
||||
boost
|
||||
{
|
||||
<span class="RenoIncludeSPAN"> template <class ErrorInfo,class E>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const * <span class="RenoLink">get_error_info</span>( E const & x );</span>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info::value_type">error_info::value_type</a></span> const * <span class="RenoLink"><a href="get_error_info">get_error_info</a></span>( E const & x );
|
||||
|
||||
template <class ErrorInfo,class E>
|
||||
typename ErrorInfo::<span class="RenoLink"><a href="error_info::value_type">error_info::value_type</a></span> * <span class="RenoLink"><a href="get_error_info">get_error_info</a></span>( E & x );</span>
|
||||
}</pre>
|
||||
</div><h4>Requirements:</h4>
|
||||
<div><ul><li> ErrorInfo must be an instance of the <span class="RenoLink"><a href="error_info.html">error_info</a></span> template.</li>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -64,7 +64,8 @@ boost
|
||||
<span class="RenoIncludeSPAN"> typedef T <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span>;</span>
|
||||
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_error_info.html">error_info</a></span>( <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & v );</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;</span>
|
||||
<span class="RenoIncludeSPAN"> <span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> const & <span class="RenoLink"><a href="error_info_value.html">value</a></span>() const;
|
||||
<span class="RenoLink"><a href="error_info_value_type.html">value_type</a></span> & <span class="RenoLink"><a href="error_info_value.html">value</a></span>();</span>
|
||||
};</span>
|
||||
|
||||
<span class="RenoIncludeSPAN">template <class E, class Tag, class T>
|
||||
|
@ -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_;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -144,8 +144,8 @@ boost
|
||||
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 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;
|
||||
|
||||
|
@ -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,7 +67,7 @@ boost
|
||||
get_info<throw_line>
|
||||
{
|
||||
static
|
||||
int const *
|
||||
int *
|
||||
get( exception const & x )
|
||||
{
|
||||
return x.throw_line_!=-1 ? &x.throw_line_ : 0;
|
||||
@ -83,6 +83,13 @@ 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
|
||||
@ -94,6 +101,16 @@ boost
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
template <class ErrorInfo,class E>
|
||||
inline
|
||||
typename ErrorInfo::value_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);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -75,26 +75,26 @@ 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 *
|
||||
@ -117,7 +117,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_;
|
||||
|
@ -30,15 +30,19 @@ main()
|
||||
using namespace boost;
|
||||
try
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(
|
||||
test_exception() <<
|
||||
test_exception e;
|
||||
e <<
|
||||
errinfo_api_function("failed_api_function") <<
|
||||
errinfo_at_line(42) <<
|
||||
errinfo_errno(errno) <<
|
||||
errinfo_file_handle(weak_ptr<FILE>()) <<
|
||||
errinfo_file_name("filename.txt") <<
|
||||
errinfo_file_open_mode("rb") <<
|
||||
errinfo_type_info_name(typeid(int).name()) );
|
||||
errinfo_file_open_mode("rb");
|
||||
#ifdef BOOST_NO_TYPEID
|
||||
BOOST_THROW_EXCEPTION(e);
|
||||
#else
|
||||
BOOST_THROW_EXCEPTION(e<<errinfo_type_info_name(typeid(int).name()));
|
||||
#endif
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
@ -50,7 +54,9 @@ main()
|
||||
BOOST_TEST(get_error_info<errinfo_file_handle>(e) && get_error_info<errinfo_file_handle>(e)->expired());
|
||||
BOOST_TEST(get_error_info<errinfo_file_name>(e) && *get_error_info<errinfo_file_name>(e)=="filename.txt");
|
||||
BOOST_TEST(get_error_info<errinfo_file_open_mode>(e) && *get_error_info<errinfo_file_open_mode>(e)=="rb");
|
||||
#ifndef BOOST_NO_TYPEID
|
||||
BOOST_TEST(get_error_info<errinfo_type_info_name>(e) && *get_error_info<errinfo_type_info_name>(e)==typeid(int).name());
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
|
@ -83,6 +83,23 @@ basic_test()
|
||||
}
|
||||
catch(
|
||||
test_exception & x )
|
||||
{
|
||||
++*boost::get_error_info<test_1>(x);
|
||||
++*boost::get_error_info<test_2>(x);
|
||||
++*boost::get_error_info<test_3>(x);
|
||||
BOOST_TEST(*boost::get_error_info<test_1>(x)==2);
|
||||
BOOST_TEST(*boost::get_error_info<test_2>(x)==3u);
|
||||
BOOST_TEST(*boost::get_error_info<test_3>(x)==4.14159f);
|
||||
BOOST_TEST(!boost::get_error_info<test_4>(x));
|
||||
}
|
||||
try
|
||||
{
|
||||
test_exception x;
|
||||
x << test_1(1) << test_2(2u) << test_3(3.14159f);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
test_exception const & x )
|
||||
{
|
||||
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
|
||||
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
|
||||
@ -317,6 +334,28 @@ test_lifetime()
|
||||
BOOST_TEST(!count);
|
||||
}
|
||||
|
||||
bool
|
||||
is_const( int const * )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
is_const( int * )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
test_const()
|
||||
{
|
||||
test_exception e;
|
||||
boost::exception const & c(e);
|
||||
boost::exception & m(e);
|
||||
BOOST_TEST(is_const(boost::get_error_info<test_1>(c)));
|
||||
BOOST_TEST(!is_const(boost::get_error_info<test_1>(m)));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -327,5 +366,6 @@ main()
|
||||
test_catch_add_info();
|
||||
test_add_tuple();
|
||||
test_lifetime();
|
||||
test_const();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user