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 ***************************************************************************/
33 #include "asfattribute.h"
36 using namespace TagLib;
38 class ASF::Attribute::AttributePrivate : public RefCounter
46 ByteVector byteVectorValue;
48 unsigned int intValue;
49 unsigned short shortValue;
50 unsigned long long longLongValue;
57 ////////////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////////////
61 ASF::Attribute::Attribute()
63 d = new AttributePrivate;
64 d->type = UnicodeType;
67 ASF::Attribute::Attribute(const ASF::Attribute &other)
74 ASF::Attribute::operator=(const ASF::Attribute &other)
83 ASF::Attribute::~Attribute()
89 ASF::Attribute::Attribute(const String &value)
91 d = new AttributePrivate;
92 d->type = UnicodeType;
93 d->stringValue = value;
96 ASF::Attribute::Attribute(const ByteVector &value)
98 d = new AttributePrivate;
100 d->byteVectorValue = value;
103 ASF::Attribute::Attribute(unsigned int value)
105 d = new AttributePrivate;
110 ASF::Attribute::Attribute(unsigned long long value)
112 d = new AttributePrivate;
114 d->longLongValue = value;
117 ASF::Attribute::Attribute(unsigned short value)
119 d = new AttributePrivate;
121 d->shortValue = value;
124 ASF::Attribute::Attribute(bool value)
126 d = new AttributePrivate;
128 d->boolValue = value;
131 ASF::Attribute::AttributeTypes
132 ASF::Attribute::type() const
138 ASF::Attribute::toString() const
140 return d->stringValue;
144 ASF::Attribute::toByteVector() const
146 return d->byteVectorValue;
150 ASF::Attribute::toBool() const
152 return d->shortValue;
156 ASF::Attribute::toUShort() const
158 return d->shortValue;
162 ASF::Attribute::toUInt() const
168 ASF::Attribute::toULongLong() const
170 return d->longLongValue;
174 ASF::Attribute::parse(ASF::File &f, int kind)
176 int size, nameLength;
179 // extended content descriptor
181 nameLength = f.readWORD();
182 name = f.readString(nameLength);
183 d->type = ASF::Attribute::AttributeTypes(f.readWORD());
186 // metadata & metadata library
188 int temp = f.readWORD();
193 d->stream = f.readWORD();
194 nameLength = f.readWORD();
195 d->type = ASF::Attribute::AttributeTypes(f.readWORD());
196 size = f.readDWORD();
197 name = f.readString(nameLength);
200 if(kind != 2 && size > 65535) {
201 debug("ASF::Attribute::parse() -- Value larger than 64kB");
206 d->shortValue = f.readWORD();
211 d->boolValue = f.readDWORD() == 1;
214 d->boolValue = f.readWORD() == 1;
219 d->intValue = f.readDWORD();
223 d->longLongValue = f.readQWORD();
227 d->stringValue = f.readString(size);
232 d->byteVectorValue = f.readBlock(size);
240 ASF::Attribute::dataSize() const
252 return d->stringValue.size() * 2 + 2;
255 return d->byteVectorValue.size();
261 ASF::Attribute::render(const String &name, int kind) const
267 data.append(ByteVector::fromShort(d->shortValue, false));
272 data.append(ByteVector::fromUInt(d->boolValue ? 1 : 0, false));
275 data.append(ByteVector::fromShort(d->boolValue ? 1 : 0, false));
280 data.append(ByteVector::fromUInt(d->intValue, false));
284 data.append(ByteVector::fromLongLong(d->longLongValue, false));
288 data.append(File::renderString(d->stringValue));
293 data.append(d->byteVectorValue);
298 data = File::renderString(name, true) +
299 ByteVector::fromShort((int)d->type, false) +
300 ByteVector::fromShort(data.size(), false) +
304 ByteVector nameData = File::renderString(name);
305 data = ByteVector::fromShort(kind == 2 ? d->language : 0, false) +
306 ByteVector::fromShort(d->stream, false) +
307 ByteVector::fromShort(nameData.size(), false) +
308 ByteVector::fromShort((int)d->type, false) +
309 ByteVector::fromUInt(data.size(), false) +
318 ASF::Attribute::language() const
324 ASF::Attribute::setLanguage(int value)
330 ASF::Attribute::stream() const
336 ASF::Attribute::setStream(int value)