Removed smart pointers from public headers

This commit is contained in:
Tsuda Kageyu
2013-05-23 10:23:33 +09:00
parent 6e335694c9
commit 7c64b1966a
40 changed files with 862 additions and 1413 deletions

View File

@ -23,32 +23,45 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include <taglib.h>
#include <tdebug.h>
#include "taglib.h"
#include "tdebug.h"
#include "tsmartptr.h"
#include "asfattribute.h"
#include "asffile.h"
using namespace TagLib;
namespace
{
struct AttributeData
{
ASF::Attribute::AttributeTypes type;
String stringValue;
ByteVector byteVectorValue;
ASF::Picture pictureValue;
union {
unsigned int intValue;
unsigned short shortValue;
unsigned long long longLongValue;
bool boolValue;
};
int stream;
int language;
};
}
class ASF::Attribute::AttributePrivate
{
public:
AttributePrivate()
: pictureValue(ASF::Picture::fromInvalid()),
stream(0),
language(0) {}
AttributeTypes type;
String stringValue;
ByteVector byteVectorValue;
ASF::Picture pictureValue;
union {
unsigned int intValue;
unsigned short shortValue;
unsigned long long longLongValue;
bool boolValue;
};
int stream;
int language;
: data(new AttributeData())
{
data->pictureValue = ASF::Picture::fromInvalid();
data->stream = 0;
data->language = 0;
}
SHARED_PTR<AttributeData> data;
};
////////////////////////////////////////////////////////////////////////////////
@ -58,135 +71,127 @@ public:
ASF::Attribute::Attribute()
: d(new AttributePrivate())
{
d->type = UnicodeType;
d->data->type = UnicodeType;
}
ASF::Attribute::Attribute(const ASF::Attribute &other)
: d(other.d)
: d(new AttributePrivate(*other.d))
{
}
ASF::Attribute::Attribute(const String &value)
: d(new AttributePrivate())
{
d->type = UnicodeType;
d->stringValue = value;
d->data->type = UnicodeType;
d->data->stringValue = value;
}
ASF::Attribute::Attribute(const ByteVector &value)
: d(new AttributePrivate())
{
d->type = BytesType;
d->byteVectorValue = value;
d->data->type = BytesType;
d->data->byteVectorValue = value;
}
ASF::Attribute::Attribute(const ASF::Picture &value)
: d(new AttributePrivate())
{
d->type = BytesType;
d->pictureValue = value;
d->data->type = BytesType;
d->data->pictureValue = value;
}
ASF::Attribute::Attribute(unsigned int value)
: d(new AttributePrivate())
{
d->type = DWordType;
d->intValue = value;
d->data->type = DWordType;
d->data->intValue = value;
}
ASF::Attribute::Attribute(unsigned long long value)
: d(new AttributePrivate())
{
d->type = QWordType;
d->longLongValue = value;
d->data->type = QWordType;
d->data->longLongValue = value;
}
ASF::Attribute::Attribute(unsigned short value)
: d(new AttributePrivate())
{
d->type = WordType;
d->shortValue = value;
d->data->type = WordType;
d->data->shortValue = value;
}
ASF::Attribute::Attribute(bool value)
: d(new AttributePrivate())
{
d->type = BoolType;
d->boolValue = value;
d->data->type = BoolType;
d->data->boolValue = value;
}
ASF::Attribute::~Attribute()
{
delete d;
}
ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
{
d = other.d;
*d = *other.d;
return *this;
}
#ifdef TAGLIB_USE_MOVE_SEMANTICS
ASF::Attribute &ASF::Attribute::operator=(ASF::Attribute &&other)
{
d = std::move(other.d);
return *this;
}
#endif
ASF::Attribute::AttributeTypes ASF::Attribute::type() const
{
return d->type;
return d->data->type;
}
String ASF::Attribute::toString() const
{
return d->stringValue;
return d->data->stringValue;
}
ByteVector ASF::Attribute::toByteVector() const
{
if(d->pictureValue.isValid())
return d->pictureValue.render();
return d->byteVectorValue;
if(d->data->pictureValue.isValid())
return d->data->pictureValue.render();
return d->data->byteVectorValue;
}
unsigned short ASF::Attribute::toBool() const
{
return d->shortValue;
return d->data->shortValue;
}
unsigned short ASF::Attribute::toUShort() const
{
return d->shortValue;
return d->data->shortValue;
}
unsigned int ASF::Attribute::toUInt() const
{
return d->intValue;
return d->data->intValue;
}
unsigned long long ASF::Attribute::toULongLong() const
{
return d->longLongValue;
return d->data->longLongValue;
}
ASF::Picture ASF::Attribute::toPicture() const
{
return d->pictureValue;
return d->data->pictureValue;
}
String ASF::Attribute::parse(ASF::File &f, int kind)
{
uint size, nameLength;
String name;
d->pictureValue = Picture::fromInvalid();
d->data->pictureValue = Picture::fromInvalid();
// extended content descriptor
if(kind == 0) {
nameLength = f.readWORD();
name = f.readString(nameLength);
d->type = ASF::Attribute::AttributeTypes(f.readWORD());
d->data->type = ASF::Attribute::AttributeTypes(f.readWORD());
size = f.readWORD();
}
// metadata & metadata library
@ -194,11 +199,11 @@ String ASF::Attribute::parse(ASF::File &f, int kind)
int temp = f.readWORD();
// metadata library
if(kind == 2) {
d->language = temp;
d->data->language = temp;
}
d->stream = f.readWORD();
d->data->stream = f.readWORD();
nameLength = f.readWORD();
d->type = ASF::Attribute::AttributeTypes(f.readWORD());
d->data->type = ASF::Attribute::AttributeTypes(f.readWORD());
size = f.readDWORD();
name = f.readString(nameLength);
}
@ -207,42 +212,42 @@ String ASF::Attribute::parse(ASF::File &f, int kind)
debug("ASF::Attribute::parse() -- Value larger than 64kB");
}
switch(d->type) {
switch(d->data->type) {
case WordType:
d->shortValue = f.readWORD();
d->data->shortValue = f.readWORD();
break;
case BoolType:
if(kind == 0) {
d->boolValue = f.readDWORD() == 1;
d->data->boolValue = f.readDWORD() == 1;
}
else {
d->boolValue = f.readWORD() == 1;
d->data->boolValue = f.readWORD() == 1;
}
break;
case DWordType:
d->intValue = f.readDWORD();
d->data->intValue = f.readDWORD();
break;
case QWordType:
d->longLongValue = f.readQWORD();
d->data->longLongValue = f.readQWORD();
break;
case UnicodeType:
d->stringValue = f.readString(size);
d->data->stringValue = f.readString(size);
break;
case BytesType:
case GuidType:
d->byteVectorValue = f.readBlock(size);
d->data->byteVectorValue = f.readBlock(size);
break;
}
if(d->type == BytesType && name == "WM/Picture") {
d->pictureValue.parse(d->byteVectorValue);
if(d->pictureValue.isValid()) {
d->byteVectorValue.clear();
if(d->data->type == BytesType && name == "WM/Picture") {
d->data->pictureValue.parse(d->data->byteVectorValue);
if(d->data->pictureValue.isValid()) {
d->data->byteVectorValue.clear();
}
}
@ -251,7 +256,7 @@ String ASF::Attribute::parse(ASF::File &f, int kind)
int ASF::Attribute::dataSize() const
{
switch (d->type) {
switch (d->data->type) {
case WordType:
return 2;
case BoolType:
@ -261,12 +266,12 @@ int ASF::Attribute::dataSize() const
case QWordType:
return 5;
case UnicodeType:
return static_cast<int>(d->stringValue.size() * 2 + 2);
return static_cast<int>(d->data->stringValue.size() * 2 + 2);
case BytesType:
if(d->pictureValue.isValid())
return d->pictureValue.dataSize();
if(d->data->pictureValue.isValid())
return d->data->pictureValue.dataSize();
case GuidType:
return static_cast<int>(d->byteVectorValue.size());
return static_cast<int>(d->data->byteVectorValue.size());
}
return 0;
}
@ -275,54 +280,54 @@ ByteVector ASF::Attribute::render(const String &name, int kind) const
{
ByteVector data;
switch (d->type) {
switch (d->data->type) {
case WordType:
data.append(ByteVector::fromUInt16LE(d->shortValue));
data.append(ByteVector::fromUInt16LE(d->data->shortValue));
break;
case BoolType:
if(kind == 0) {
data.append(ByteVector::fromUInt32LE(d->boolValue ? 1 : 0));
data.append(ByteVector::fromUInt32LE(d->data->boolValue ? 1 : 0));
}
else {
data.append(ByteVector::fromUInt16LE(d->boolValue ? 1 : 0));
data.append(ByteVector::fromUInt16LE(d->data->boolValue ? 1 : 0));
}
break;
case DWordType:
data.append(ByteVector::fromUInt32LE(d->intValue));
data.append(ByteVector::fromUInt32LE(d->data->intValue));
break;
case QWordType:
data.append(ByteVector::fromUInt64LE(d->longLongValue));
data.append(ByteVector::fromUInt64LE(d->data->longLongValue));
break;
case UnicodeType:
data.append(File::renderString(d->stringValue));
data.append(File::renderString(d->data->stringValue));
break;
case BytesType:
if(d->pictureValue.isValid()) {
data.append(d->pictureValue.render());
if(d->data->pictureValue.isValid()) {
data.append(d->data->pictureValue.render());
break;
}
case GuidType:
data.append(d->byteVectorValue);
data.append(d->data->byteVectorValue);
break;
}
if(kind == 0) {
data = File::renderString(name, true) +
ByteVector::fromUInt16LE((int)d->type) +
ByteVector::fromUInt16LE((int)d->data->type) +
ByteVector::fromUInt16LE(data.size()) +
data;
}
else {
ByteVector nameData = File::renderString(name);
data = ByteVector::fromUInt16LE(kind == 2 ? d->language : 0) +
ByteVector::fromUInt16LE(d->stream) +
data = ByteVector::fromUInt16LE(kind == 2 ? d->data->language : 0) +
ByteVector::fromUInt16LE(d->data->stream) +
ByteVector::fromUInt16LE(nameData.size()) +
ByteVector::fromUInt16LE((int)d->type) +
ByteVector::fromUInt16LE((int)d->data->type) +
ByteVector::fromUInt32LE(data.size()) +
nameData +
data;
@ -333,21 +338,21 @@ ByteVector ASF::Attribute::render(const String &name, int kind) const
int ASF::Attribute::language() const
{
return d->language;
return d->data->language;
}
void ASF::Attribute::setLanguage(int value)
{
d->language = value;
d->data->language = value;
}
int ASF::Attribute::stream() const
{
return d->stream;
return d->data->stream;
}
void ASF::Attribute::setStream(int value)
{
d->stream = value;
d->data->stream = value;
}

View File

@ -36,7 +36,6 @@ namespace TagLib
namespace ASF
{
class File;
class Picture;
@ -115,17 +114,6 @@ namespace TagLib
*/
ASF::Attribute &operator=(const Attribute &other);
#ifdef TAGLIB_USE_MOVE_SEMANTICS
/*!
* Moves the contents of \a other into this item.
*
* \note Not available unless TAGLIB_USE_MOVE_SEMANTICS macro is defined.
*/
ASF::Attribute &operator=(Attribute &&other);
#endif
/*!
* Destroys the attribute.
*/
@ -191,21 +179,17 @@ namespace TagLib
*/
void setStream(int value);
#ifndef DO_NOT_DOCUMENT
/* THIS IS PRIVATE, DON'T TOUCH IT! */
String parse(ASF::File &file, int kind = 0);
#endif
//! Returns the size of the stored data
int dataSize() const;
private:
friend class File;
String parse(ASF::File &file, int kind = 0);
ByteVector render(const String &name, int kind = 0) const;
class AttributePrivate;
RefCountPtr<AttributePrivate> d;
AttributePrivate *d;
};
}

View File

@ -23,24 +23,39 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include <taglib.h>
#include <tdebug.h>
#include "taglib.h"
#include "tdebug.h"
#include "tsmartptr.h"
#include "asfattribute.h"
#include "asffile.h"
#include "asfpicture.h"
using namespace TagLib;
namespace
{
struct PictureData
{
bool valid;
ASF::Picture::Type type;
String mimeType;
String description;
ByteVector picture;
};
}
class ASF::Picture::PicturePrivate
{
public:
bool valid;
Type type;
String mimeType;
String description;
ByteVector picture;
PicturePrivate()
: data(new PictureData())
{
}
SHARED_PTR<PictureData> data;
};
////////////////////////////////////////////////////////////////////////////////
// Picture class members
////////////////////////////////////////////////////////////////////////////////
@ -48,115 +63,96 @@ public:
ASF::Picture::Picture()
: d(new PicturePrivate())
{
d->valid = true;
d->data->valid = true;
}
ASF::Picture::Picture(const Picture& other)
: d(other.d)
: d(new PicturePrivate(*other.d))
{
}
#ifdef TAGLIB_USE_MOVE_SEMANTICS
ASF::Picture::Picture(Picture &&other)
: d(std::move(other.d))
{
}
#endif
ASF::Picture::~Picture()
{
delete d;
}
bool ASF::Picture::isValid() const
{
return d->valid;
return d->data->valid;
}
String ASF::Picture::mimeType() const
{
return d->mimeType;
return d->data->mimeType;
}
void ASF::Picture::setMimeType(const String &value)
{
d->mimeType = value;
d->data->mimeType = value;
}
ASF::Picture::Type ASF::Picture::type() const
{
return d->type;
return d->data->type;
}
void ASF::Picture::setType(const ASF::Picture::Type& t)
{
d->type = t;
d->data->type = t;
}
String ASF::Picture::description() const
{
return d->description;
return d->data->description;
}
void ASF::Picture::setDescription(const String &desc)
{
d->description = desc;
d->data->description = desc;
}
ByteVector ASF::Picture::picture() const
{
return d->picture;
return d->data->picture;
}
void ASF::Picture::setPicture(const ByteVector &p)
{
d->picture = p;
d->data->picture = p;
}
int ASF::Picture::dataSize() const
{
return static_cast<int>(
9 + (d->mimeType.length() + d->description.length()) * 2 +
d->picture.size());
9 + (d->data->mimeType.length() + d->data->description.length()) * 2 +
d->data->picture.size());
}
ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other)
{
d = other.d;
*d = *other.d;
return *this;
}
#ifdef TAGLIB_USE_MOVE_SEMANTICS
ASF::Picture& ASF::Picture::operator=(ASF::Picture &&other)
{
d = std::move(other.d);
return *this;
}
#endif
ByteVector ASF::Picture::render() const
{
if(!isValid())
return ByteVector::null;
return
ByteVector((char)d->type) +
ByteVector::fromUInt32LE(d->picture.size()) +
ASF::File::renderString(d->mimeType) +
ASF::File::renderString(d->description) +
d->picture;
ByteVector((char)d->data->type) +
ByteVector::fromUInt32LE(d->data->picture.size()) +
ASF::File::renderString(d->data->mimeType) +
ASF::File::renderString(d->data->description) +
d->data->picture;
}
void ASF::Picture::parse(const ByteVector& bytes)
{
d->valid = false;
d->data->valid = false;
if(bytes.size() < 9)
return;
size_t pos = 0;
d->type = (Type)bytes[0]; ++pos;
d->data->type = (Type)bytes[0]; ++pos;
const uint dataLen = bytes.toUInt32LE(pos); pos+=4;
const ByteVector nullStringTerminator(2, 0);
@ -164,27 +160,27 @@ void ASF::Picture::parse(const ByteVector& bytes)
size_t endPos = bytes.find(nullStringTerminator, pos, 2);
if(endPos == ByteVector::npos)
return;
d->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
d->data->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
pos = endPos+2;
endPos = bytes.find(nullStringTerminator, pos, 2);
if(endPos == ByteVector::npos)
return;
d->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
d->data->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
pos = endPos+2;
if(dataLen + pos != bytes.size())
return;
d->picture = bytes.mid(pos, dataLen);
d->valid = true;
d->data->picture = bytes.mid(pos, dataLen);
d->data->valid = true;
return;
}
ASF::Picture ASF::Picture::fromInvalid()
{
Picture ret;
ret.d->valid = false;
ret.d->data->valid = false;
return ret;
}

View File

@ -35,6 +35,7 @@ namespace TagLib
{
namespace ASF
{
class Attribute;
//! An ASF attached picture interface implementation
@ -46,7 +47,8 @@ namespace TagLib
* \see Attribute::toPicture()
* \see Attribute::Attribute(const Picture& picture)
*/
class TAGLIB_EXPORT Picture {
class TAGLIB_EXPORT Picture
{
public:
/*!
@ -107,17 +109,6 @@ namespace TagLib
*/
Picture(const Picture& other);
#ifdef TAGLIB_USE_MOVE_SEMANTICS
/*!
* Constructs an picture equivalent to \a other.
*
* \note Not available unless TAGLIB_USE_MOVE_SEMANTICS macro is defined.
*/
Picture(Picture &&other);
#endif
/*!
* Destroys the picture.
*/
@ -128,17 +119,6 @@ namespace TagLib
*/
Picture& operator=(const Picture& other);
#ifdef TAGLIB_USE_MOVE_SEMANTICS
/*!
* Moves the contents of \a other into this picture.
*
* \note Not available unless TAGLIB_USE_MOVE_SEMANTICS macro is defined.
*/
Picture& operator=(Picture &&other);
#endif
/*!
* Returns true if Picture stores valid picture
*/
@ -223,15 +203,14 @@ namespace TagLib
*/
int dataSize() const;
#ifndef DO_NOT_DOCUMENT
/* THIS IS PRIVATE, DON'T TOUCH IT! */
void parse(const ByteVector& );
static Picture fromInvalid();
friend class Attribute;
#endif
private:
friend class Attribute;
void parse(const ByteVector &);
static Picture fromInvalid();
class PicturePrivate;
RefCountPtr<PicturePrivate> d;
PicturePrivate *d;
};
}
}