12 #ifndef DPTR_SHAREDCLASS_0_1_H
13 #define DPTR_SHAREDCLASS_0_1_H
16 namespace Chester_0_1{
34 virtual void detach(){cnt--;
if(cnt==0)
delete this;}
42 using namespace Chester_0_1;
47 #ifdef DEFINE_SHARED_DPTR
48 #undef DEFINE_SHARED_DPTR
57 #define DEFINE_SHARED_DPTR(Class) \
58 Class::DPrivate::DPrivate(){d=new Class::Private;}\
59 Class::DPrivate::DPrivate(const DPrivate&dp){d=dp.d;d->attach();}\
60 Class::DPrivate::~DPrivate(){d->detach();}\
61 Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\
62 Class::DPrivate& Class::DPrivate::operator=(const DPrivate&dp)\
63 {if(d!=dp.d){d->detach();d=dp.d;d->attach();}return *this;}\
64 void Class::DPrivate::decouple()\
65 {if(d->currentRefCount()>1){Private *p=new Class::Private(*d);d->detach();d=p;}}
virtual ~SharedDPtr()
deletes a shared d-pointer
Definition: dptr_shared.h:30
virtual void detach()
called by the wrapper to detach from an instance
Definition: dptr_shared.h:34
Base class of shared d-pointers.
Definition: dptr_shared.h:22
virtual void attach()
called by the wrapper to attach to a new instance
Definition: dptr_shared.h:32
SharedDPtr()
instantiates a shared d-pointer
Definition: dptr_shared.h:28
int currentRefCount() const
called by the wrapper to enable copy-on-write logic
Definition: dptr_shared.h:36
int cnt
Definition: dptr_shared.h:25