Converted exception_ptr from a shared_ptr typedef to a stand-alone class to allow simpler declaration of namespace boost { class exception_ptr; }

[SVN r68202]
This commit is contained in:
Emil Dotchevski
2011-01-17 07:01:35 +00:00
parent c210c38dae
commit 6b0bfad6bf
2 changed files with 39 additions and 7 deletions

View File

@ -29,10 +29,42 @@
namespace namespace
boost boost
{ {
typedef shared_ptr<exception_detail::clone_base const> exception_ptr; class exception_ptr;
void rethrow_exception( exception_ptr const & );
exception_ptr current_exception(); exception_ptr current_exception();
class
exception_ptr
{
typedef boost::shared_ptr<exception_detail::clone_base const> impl;
impl ptr_;
friend void rethrow_exception( exception_ptr const & );
typedef exception_detail::clone_base const * (impl::*unspecified_bool_type)() const;
public:
exception_ptr()
{
}
explicit
exception_ptr( impl const & ptr ):
ptr_(ptr)
{
}
bool
operator==( exception_ptr const & other ) const
{
return ptr_==other.ptr_;
}
bool
operator!=( exception_ptr const & other ) const
{
return ptr_!=other.ptr_;
}
operator unspecified_bool_type() const
{
return ptr_?&impl::get:0;
}
};
template <class T> template <class T>
inline inline
exception_ptr exception_ptr
@ -89,7 +121,7 @@ boost
throw_function(BOOST_CURRENT_FUNCTION) << throw_function(BOOST_CURRENT_FUNCTION) <<
throw_file(__FILE__) << throw_file(__FILE__) <<
throw_line(__LINE__); throw_line(__LINE__);
static exception_ptr ep(new exception_detail::clone_impl<Exception>(c)); static exception_ptr ep(shared_ptr<exception_detail::clone_base const>(new exception_detail::clone_impl<Exception>(c)));
return ep; return ep;
} }
@ -272,7 +304,7 @@ boost
success: success:
{ {
BOOST_ASSERT(e!=0); BOOST_ASSERT(e!=0);
return exception_ptr(e); return exception_ptr(shared_ptr<exception_detail::clone_base const>(e));
} }
case exception_detail::clone_current_exception_result:: case exception_detail::clone_current_exception_result::
bad_alloc: bad_alloc:
@ -299,7 +331,7 @@ boost
catch( catch(
exception_detail::clone_base & e ) exception_detail::clone_base & e )
{ {
return exception_ptr(e.clone()); return exception_ptr(shared_ptr<exception_detail::clone_base const>(e.clone()));
} }
catch( catch(
std::domain_error & e ) std::domain_error & e )
@ -421,7 +453,7 @@ boost
rethrow_exception( exception_ptr const & p ) rethrow_exception( exception_ptr const & p )
{ {
BOOST_ASSERT(p); BOOST_ASSERT(p);
p->rethrow(); p.ptr_->rethrow();
} }
inline inline

View File

@ -12,7 +12,7 @@ boost
namespace exception_detail { class clone_base; }; namespace exception_detail { class clone_base; };
template <class Tag,class T> class error_info; template <class Tag,class T> class error_info;
template <class T> class shared_ptr; template <class T> class shared_ptr;
typedef shared_ptr<exception_detail::clone_base const> exception_ptr; class exception_ptr;
typedef error_info<struct errinfo_nested_exception_,exception_ptr> errinfo_nested_exception; typedef error_info<struct errinfo_nested_exception_,exception_ptr> errinfo_nested_exception;
} }