shared_ptr<T> weak_ptr<T> T = scoped_ptr<Data>. , Data ).
shared_ptr make_shared<unique_ptr<Data>>(new Data(...));
weak_ptr , root.lock().reset()
template <typename T>
struct RootHandle : public boost::weak_ptr< boost::scoped_ptr<T> >
{
typedef boost::weak_ptr< boost::scoped_ptr<T> > weak_type;
typedef boost::shared_ptr< boost::scoped_ptr<T> > strong_type;
RootHandle() {}
RootHandle(const weak_type& impl)
:weak_type(impl) {}
T* get() const
{
strong_type x = lock();
return (x) ? x->get() : 0;
}
void reset()
{
strong_type x = lock();
if (x)
x->reset();
}
};
template <typename T>
struct NormalHandle : public boost::shared_ptr< boost::scoped_ptr<T> >
{
public:
typedef boost::shared_ptr< boost::scoped_ptr<T> > strong_type;
NormalHandle() {}
NormalHandle(const strong_type& impl)
:strong_type(impl) {}
T* get() const
{
boost::scoped_ptr<T>* ppx = strong_type::get();
return (0 != ppx) ? ppx->get() : 0;
}
};
NormalHandles :
NormalHandle<Data> handle1(boost::make_shared< boost::scoped_ptr<Data> >(new Data(4, 3, "abc")));