1 /**************************************************************************
2 copyright : (C) 2005-2007 by Lukáš Lalinský
3 email : lalinsky@gmail.com
4 **************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
34 #include "asfattribute.h"
37 using namespace TagLib;
39 class ASF::Attribute::AttributePrivate : public RefCounter
47 ByteVector byteVectorValue;
49 unsigned int intValue;
50 unsigned short shortValue;
51 unsigned long long longLongValue;
58 ////////////////////////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////////////////////////
62 ASF::Attribute::Attribute()
64 d = new AttributePrivate;
65 d->type = UnicodeType;
68 ASF::Attribute::Attribute(const ASF::Attribute &other)
75 ASF::Attribute::operator=(const ASF::Attribute &other)
84 ASF::Attribute::~Attribute()
90 ASF::Attribute::Attribute(const String &value)
92 d = new AttributePrivate;
93 d->type = UnicodeType;
94 d->stringValue = value;
97 ASF::Attribute::Attribute(const ByteVector &value)
99 d = new AttributePrivate;
101 d->byteVectorValue = value;
104 ASF::Attribute::Attribute(unsigned int value)
106 d = new AttributePrivate;
111 ASF::Attribute::Attribute(unsigned long long value)
113 d = new AttributePrivate;
115 d->longLongValue = value;
118 ASF::Attribute::Attribute(unsigned short value)
120 d = new AttributePrivate;
122 d->shortValue = value;
125 ASF::Attribute::Attribute(bool value)
127 d = new AttributePrivate;
129 d->boolValue = value;
132 ASF::Attribute::AttributeTypes
133 ASF::Attribute::type() const
139 ASF::Attribute::toString() const
141 return d->stringValue;
145 ASF::Attribute::toByteVector() const
147 return d->byteVectorValue;
151 ASF::Attribute::toBool() const
153 return d->shortValue;
157 ASF::Attribute::toUShort() const
159 return d->shortValue;
163 ASF::Attribute::toUInt() const
169 ASF::Attribute::toULongLong() const
171 return d->longLongValue;
175 ASF::Attribute::parse(ASF::File &f, int kind)
177 int size, nameLength;
180 // extended content descriptor
182 nameLength = f.readWORD();
183 name = f.readString(nameLength);
184 d->type = ASF::Attribute::AttributeTypes(f.readWORD());
187 // metadata & metadata library
189 int temp = f.readWORD();
194 d->stream = f.readWORD();
195 nameLength = f.readWORD();
196 d->type = ASF::Attribute::AttributeTypes(f.readWORD());
197 size = f.readDWORD();
198 name = f.readString(nameLength);
201 if(kind != 2 && size > 65535) {
202 debug("ASF::Attribute::parse() -- Value larger than 64kB");
207 d->shortValue = f.readWORD();
212 d->boolValue = f.readDWORD() == 1;
215 d->boolValue = f.readWORD() == 1;
220 d->intValue = f.readDWORD();
224 d->longLongValue = f.readQWORD();
228 d->stringValue = f.readString(size);
233 d->byteVectorValue = f.readBlock(size);
241 ASF::Attribute::dataSize() const
253 return d->stringValue.size() * 2 + 2;
256 return d->byteVectorValue.size();
262 ASF::Attribute::render(const String &name, int kind) const
268 data.append(ByteVector::fromShort(d->shortValue, false));
273 data.append(ByteVector::fromUInt(d->boolValue ? 1 : 0, false));
276 data.append(ByteVector::fromShort(d->boolValue ? 1 : 0, false));
281 data.append(ByteVector::fromUInt(d->intValue, false));
285 data.append(ByteVector::fromLongLong(d->longLongValue, false));
289 data.append(File::renderString(d->stringValue));
294 data.append(d->byteVectorValue);
299 data = File::renderString(name, true) +
300 ByteVector::fromShort((int)d->type, false) +
301 ByteVector::fromShort(data.size(), false) +
305 ByteVector nameData = File::renderString(name);
306 data = ByteVector::fromShort(kind == 2 ? d->language : 0, false) +
307 ByteVector::fromShort(d->stream, false) +
308 ByteVector::fromShort(nameData.size(), false) +
309 ByteVector::fromShort((int)d->type, false) +
310 ByteVector::fromUInt(data.size(), false) +
319 ASF::Attribute::language() const
325 ASF::Attribute::setLanguage(int value)
331 ASF::Attribute::stream() const
337 ASF::Attribute::setStream(int value)