RefCounter mimics std::shared_ptr

This commit is contained in:
Tsuda kageyu
2013-04-17 06:39:14 +09:00
parent 5c96ff42c3
commit c44351aab5
26 changed files with 318 additions and 696 deletions

View File

@ -34,7 +34,7 @@
using namespace TagLib;
class ASF::Attribute::AttributePrivate : public RefCounter
class ASF::Attribute::AttributePrivate
{
public:
AttributePrivate()
@ -68,11 +68,6 @@ ASF::Attribute::Attribute()
ASF::Attribute::Attribute(const ASF::Attribute &other)
: d(other.d)
{
#ifndef TAGLIB_USE_CXX11
d->ref();
#endif
}
ASF::Attribute::Attribute(const String &value)
@ -126,29 +121,11 @@ ASF::Attribute::Attribute(bool value)
ASF::Attribute::~Attribute()
{
#ifndef TAGLIB_USE_CXX11
if(d->deref())
delete d;
#endif
}
ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
{
#ifdef TAGLIB_USE_CXX11
d = other.d;
#else
if(d->deref())
delete d;
d = other.d;
d->ref();
#endif
return *this;
}

View File

@ -205,12 +205,7 @@ namespace TagLib
ByteVector render(const String &name, int kind = 0) const;
class AttributePrivate;
#ifdef TAGLIB_USE_CXX11
std::shared_ptr<AttributePrivate> d;
#else
AttributePrivate *d;
#endif
RefCountPtr<AttributePrivate> d;
};
}

View File

@ -35,7 +35,7 @@
using namespace TagLib;
class ASF::Picture::PicturePrivate : public RefCounter
class ASF::Picture::PicturePrivate
{
public:
bool valid;
@ -58,11 +58,6 @@ ASF::Picture::Picture()
ASF::Picture::Picture(const Picture& other)
: d(other.d)
{
#ifndef TAGLIB_USE_CXX11
d->ref();
#endif
}
#ifdef TAGLIB_USE_CXX11
@ -76,12 +71,6 @@ ASF::Picture::Picture(Picture &&other)
ASF::Picture::~Picture()
{
#ifndef TAGLIB_USE_CXX11
if(d->deref())
delete d;
#endif
}
bool ASF::Picture::isValid() const
@ -138,21 +127,7 @@ int ASF::Picture::dataSize() const
ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other)
{
#ifdef TAGLIB_USE_CXX11
d = other.d;
#else
if(other.d != d) {
if(d->deref())
delete d;
d = other.d;
d->ref();
}
#endif
return *this;
}

View File

@ -231,12 +231,7 @@ namespace TagLib
#endif
private:
class PicturePrivate;
#ifdef TAGLIB_USE_CXX11
std::shared_ptr<PicturePrivate> d;
#else
PicturePrivate *d;
#endif
RefCountPtr<PicturePrivate> d;
};
}
}