From 4adfeeb16bfc4259479740fb199544d3f92b402b Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 17 Nov 2010 09:43:26 +0000 Subject: [PATCH] dptr: made -> operator clearer and safer, added clone method git-svn-id: https://silmor.de/svn/softmagic/elam/trunk@633 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dptr.h | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/dptr.h b/src/dptr.h index 9b81c80..b6c79b9 100644 --- a/src/dptr.h +++ b/src/dptr.h @@ -51,7 +51,9 @@ The d-pointer class Private is only forward declared, you have to fully declare class DPrivate{\ public:DPrivate();DPrivate(const DPrivate&);~DPrivate();\ DPrivate&operator=(const DPrivate&);\ - Private*operator->()const{return d;}\ + const Private*operator->()const{return d;}\ + Private*operator->(){return d;}\ + DPrivate clone()const;\ private:Private*d;\ }; \ DPrivate dp; @@ -84,6 +86,7 @@ To be used in implementation where the actual d-pointer class is implemented. Class::DPrivate::DPrivate(){d=new Class::Private;}\ Class::DPrivate::DPrivate(const Class::DPrivate&dp){d=new Class::Private(*(dp.d));}\ Class::DPrivate::~DPrivate(){delete d;}\ + Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\ Class::DPrivate& Class::DPrivate::operator=(const Class::DPrivate&dp)\ {*d=*(dp.d);return *this;} @@ -115,6 +118,7 @@ To be used in implementation where the actual d-pointer class is implemented. Class::DPrivate::DPrivate(){d=new Class::Private;}\ Class::DPrivate::DPrivate(const DPrivate&dp){d=dp.d;d->attach();}\ Class::DPrivate::~DPrivate(){d->detach();}\ + Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\ Class::DPrivate& Class::DPrivate::operator=(const DPrivate&dp)\ {d->detach();d=dp.d;d->attach();return *this;} -- 1.7.2.5