mirror of
https://github.com/boostorg/exception.git
synced 2025-07-16 22:12:05 +02:00
Both enable_error_info.hpp and enable_current_exception.hpp now do not depend on intrusive_ptr or any other Boost lib.
[SVN r48482]
This commit is contained in:
@ -6,8 +6,6 @@
|
||||
#ifndef UUID_DBA0D90C930911DCBA7B675A56D89593
|
||||
#define UUID_DBA0D90C930911DCBA7B675A56D89593
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
@ -36,12 +34,7 @@ boost
|
||||
|
||||
protected:
|
||||
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
||||
virtual //Disable bogus msvc warning.
|
||||
#endif
|
||||
virtual
|
||||
~counted_base() throw()
|
||||
{
|
||||
}
|
||||
|
79
include/boost/exception/detail/refcount_ptr.hpp
Normal file
79
include/boost/exception/detail/refcount_ptr.hpp
Normal file
@ -0,0 +1,79 @@
|
||||
//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_490EADC876F011DDA2F00A4756D89593
|
||||
#define UUID_490EADC876F011DDA2F00A4756D89593
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <class T>
|
||||
class
|
||||
refcount_ptr
|
||||
{
|
||||
public:
|
||||
|
||||
refcount_ptr():
|
||||
px_(0)
|
||||
{
|
||||
}
|
||||
|
||||
~refcount_ptr()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
refcount_ptr( refcount_ptr const & x ):
|
||||
px_(x.px_)
|
||||
{
|
||||
add_ref();
|
||||
}
|
||||
|
||||
refcount_ptr &
|
||||
operator=( refcount_ptr const & x )
|
||||
{
|
||||
adopt(x.px_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
adopt( T * px )
|
||||
{
|
||||
release();
|
||||
px_=px;
|
||||
add_ref();
|
||||
}
|
||||
|
||||
T *
|
||||
get() const
|
||||
{
|
||||
return px_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T * px_;
|
||||
|
||||
void
|
||||
add_ref()
|
||||
{
|
||||
if( px_ )
|
||||
intrusive_ptr_add_ref(px_);
|
||||
}
|
||||
|
||||
void
|
||||
release()
|
||||
{
|
||||
if( px_ )
|
||||
intrusive_ptr_release(px_);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -7,8 +7,6 @@
|
||||
#define UUID_0C5D492E909711DCB658AD4556D89593
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace
|
||||
@ -57,43 +55,21 @@ boost
|
||||
typedef error_info_injector<T> type;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
template <class T>
|
||||
struct
|
||||
sizeof_dispatch
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(int, value = sizeof(dispatch((T*)0)) );
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof_dispatch<T>::value>::type type;
|
||||
};
|
||||
#else
|
||||
template <class T>
|
||||
struct
|
||||
enable_error_info_return_type
|
||||
{
|
||||
typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
typename
|
||||
#endif
|
||||
exception_detail::enable_error_info_return_type<T>::type
|
||||
enable_error_info( T const & x )
|
||||
{
|
||||
return
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
|
||||
typename
|
||||
#endif
|
||||
exception_detail::enable_error_info_return_type<T>::type(x);
|
||||
return typename exception_detail::enable_error_info_return_type<T>::type(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#define UUID_274DA366004E11DCB1DDFE2E56D89593
|
||||
|
||||
#include <boost/exception/detail/counted_base.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/exception/detail/refcount_ptr.hpp>
|
||||
|
||||
namespace
|
||||
boost
|
||||
@ -61,27 +61,15 @@ boost
|
||||
{
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
|
||||
//Force class exception to be abstract.
|
||||
//Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
|
||||
virtual ~exception() throw()=0;
|
||||
#else
|
||||
#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
|
||||
virtual //Disable bogus GCC warning.
|
||||
#endif
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
char const *
|
||||
_diagnostic_information() const throw()
|
||||
{
|
||||
if( data_ )
|
||||
if( exception_detail::error_info_container * c=data_.get() )
|
||||
try
|
||||
{
|
||||
char const * w = data_->diagnostic_information();
|
||||
BOOST_ASSERT(w!=0);
|
||||
if( char const * w = c->diagnostic_information() )
|
||||
return w;
|
||||
}
|
||||
catch(...)
|
||||
@ -97,16 +85,14 @@ boost
|
||||
template <class ErrorInfo>
|
||||
friend shared_ptr<typename ErrorInfo::value_type const> exception_detail::get_data( exception const & );
|
||||
|
||||
mutable intrusive_ptr<exception_detail::error_info_container> data_;
|
||||
mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above.
|
||||
inline
|
||||
exception::
|
||||
~exception() throw()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -22,8 +22,8 @@ boost
|
||||
shared_ptr<typename ErrorInfo::value_type const>
|
||||
get_data( exception const & x )
|
||||
{
|
||||
if( x.data_ )
|
||||
if( shared_ptr<exception_detail::error_info_base const> eib = x.data_->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
|
||||
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)) )
|
||||
{
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
|
||||
|
@ -151,9 +151,10 @@ boost
|
||||
void
|
||||
set_data( exception const * e, shared_ptr<exception_detail::error_info_base const> const & x, exception_detail::type_info_ const & typeid_ )
|
||||
{
|
||||
if( !e->data_ )
|
||||
e->data_ = intrusive_ptr<exception_detail::error_info_container>(new exception_detail::error_info_container_impl);
|
||||
e->data_->set(x,typeid_);
|
||||
exception_detail::error_info_container * c;
|
||||
if( !(c=e->data_.get()) )
|
||||
e->data_.adopt(c=new exception_detail::error_info_container_impl);
|
||||
c->set(x,typeid_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
#include <boost/exception/detail/type_info.hpp>
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <stdexcept>
|
||||
#include <new>
|
||||
|
||||
|
@ -29,6 +29,7 @@ run throw_exception_test.cpp helper2.cpp ;
|
||||
run errno_test.cpp ;
|
||||
run error_info_test.cpp ;
|
||||
run diagnostic_information_test.cpp ;
|
||||
run refcount_ptr_test.cpp ;
|
||||
compile-fail exception_fail.cpp ;
|
||||
compile-fail throw_exception_fail.cpp ;
|
||||
|
||||
|
105
test/refcount_ptr_test.cpp
Normal file
105
test/refcount_ptr_test.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
//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)
|
||||
|
||||
#include <boost/exception/detail/refcount_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
struct
|
||||
test_type
|
||||
{
|
||||
test_type( int & count ):
|
||||
count_(count)
|
||||
{
|
||||
BOOST_TEST(count_==42);
|
||||
count_=0;
|
||||
}
|
||||
|
||||
~test_type()
|
||||
{
|
||||
BOOST_TEST(!count_);
|
||||
count_=42;
|
||||
}
|
||||
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_add_ref( test_type const * c )
|
||||
{
|
||||
++c->count_;
|
||||
}
|
||||
|
||||
friend
|
||||
void
|
||||
intrusive_ptr_release( test_type const * c )
|
||||
{
|
||||
if( !--c->count_ )
|
||||
delete c;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
test_type( test_type const & );
|
||||
test_type & operator=( test_type const & );
|
||||
|
||||
mutable int & count_;
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using boost::exception_detail::refcount_ptr;
|
||||
|
||||
{
|
||||
refcount_ptr<test_type> x;
|
||||
BOOST_TEST(!x.get());
|
||||
}
|
||||
|
||||
{
|
||||
int count=42;
|
||||
test_type * a=new test_type(count);
|
||||
BOOST_TEST(!count);
|
||||
{
|
||||
refcount_ptr<test_type> p;
|
||||
BOOST_TEST(0==count);
|
||||
p.adopt(a);
|
||||
BOOST_TEST(p.get()==a);
|
||||
BOOST_TEST(1==count);
|
||||
{
|
||||
refcount_ptr<test_type> q;
|
||||
q.adopt(p.get());
|
||||
BOOST_TEST(q.get()==a);
|
||||
BOOST_TEST(2==count);
|
||||
{
|
||||
refcount_ptr<test_type> t(p);
|
||||
BOOST_TEST(t.get()==a);
|
||||
BOOST_TEST(3==count);
|
||||
{
|
||||
refcount_ptr<test_type> n;
|
||||
n=t;
|
||||
BOOST_TEST(n.get()==a);
|
||||
BOOST_TEST(4==count);
|
||||
int cb=42;
|
||||
test_type * b=new test_type(cb);
|
||||
BOOST_TEST(0==cb);
|
||||
n.adopt(b);
|
||||
BOOST_TEST(1==cb);
|
||||
BOOST_TEST(n.get()==b);
|
||||
BOOST_TEST(3==count);
|
||||
n.adopt(0);
|
||||
BOOST_TEST(42==cb);
|
||||
}
|
||||
BOOST_TEST(t.get()==a);
|
||||
BOOST_TEST(3==count);
|
||||
}
|
||||
BOOST_TEST(q.get()==a);
|
||||
BOOST_TEST(2==count);
|
||||
}
|
||||
BOOST_TEST(p.get()==a);
|
||||
BOOST_TEST(1==count);
|
||||
}
|
||||
BOOST_TEST(42==count);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user