1 /**************************************************************************
2 copyright : (C) 2007 by Lukáš Lalinský
3 email : lalinsky@gmail.com
4 **************************************************************************/
5
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. *
10 * *
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. *
15 * *
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., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
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 ***************************************************************************/
25
26 #include <taglib.h>
27 #include <tdebug.h>
28 #include "trefcounter.h"
29 #include "mp4item.h"
30
31 using namespace TagLib;
32
33 class MP4::Item::ItemPrivate : public RefCounter
34 {
35 public:
ItemPrivate()36 ItemPrivate() :
37 RefCounter(),
38 valid(true),
39 atomDataType(TypeUndefined) {}
40
41 bool valid;
42 AtomDataType atomDataType;
43 union {
44 bool m_bool;
45 int m_int;
46 IntPair m_intPair;
47 unsigned char m_byte;
48 unsigned int m_uint;
49 long long m_longlong;
50 };
51 StringList m_stringList;
52 ByteVectorList m_byteVectorList;
53 MP4::CoverArtList m_coverArtList;
54 };
55
Item()56 MP4::Item::Item() :
57 d(new ItemPrivate())
58 {
59 d->valid = false;
60 }
61
Item(const Item & item)62 MP4::Item::Item(const Item &item) :
63 d(item.d)
64 {
65 d->ref();
66 }
67
68 MP4::Item &
operator =(const Item & item)69 MP4::Item::operator=(const Item &item)
70 {
71 Item(item).swap(*this);
72 return *this;
73 }
74
75 void
swap(Item & item)76 MP4::Item::swap(Item &item)
77 {
78 using std::swap;
79
80 swap(d, item.d);
81 }
82
~Item()83 MP4::Item::~Item()
84 {
85 if(d->deref())
86 delete d;
87 }
88
Item(bool value)89 MP4::Item::Item(bool value) :
90 d(new ItemPrivate())
91 {
92 d->m_bool = value;
93 }
94
Item(int value)95 MP4::Item::Item(int value) :
96 d(new ItemPrivate())
97 {
98 d->m_int = value;
99 }
100
Item(unsigned char value)101 MP4::Item::Item(unsigned char value) :
102 d(new ItemPrivate())
103 {
104 d->m_byte = value;
105 }
106
Item(unsigned int value)107 MP4::Item::Item(unsigned int value) :
108 d(new ItemPrivate())
109 {
110 d->m_uint = value;
111 }
112
Item(long long value)113 MP4::Item::Item(long long value) :
114 d(new ItemPrivate())
115 {
116 d->m_longlong = value;
117 }
118
Item(int value1,int value2)119 MP4::Item::Item(int value1, int value2) :
120 d(new ItemPrivate())
121 {
122 d->m_intPair.first = value1;
123 d->m_intPair.second = value2;
124 }
125
Item(const ByteVectorList & value)126 MP4::Item::Item(const ByteVectorList &value) :
127 d(new ItemPrivate())
128 {
129 d->m_byteVectorList = value;
130 }
131
Item(const StringList & value)132 MP4::Item::Item(const StringList &value) :
133 d(new ItemPrivate())
134 {
135 d->m_stringList = value;
136 }
137
Item(const MP4::CoverArtList & value)138 MP4::Item::Item(const MP4::CoverArtList &value) :
139 d(new ItemPrivate())
140 {
141 d->m_coverArtList = value;
142 }
143
setAtomDataType(MP4::AtomDataType type)144 void MP4::Item::setAtomDataType(MP4::AtomDataType type)
145 {
146 d->atomDataType = type;
147 }
148
atomDataType() const149 MP4::AtomDataType MP4::Item::atomDataType() const
150 {
151 return d->atomDataType;
152 }
153
154 bool
toBool() const155 MP4::Item::toBool() const
156 {
157 return d->m_bool;
158 }
159
160 int
toInt() const161 MP4::Item::toInt() const
162 {
163 return d->m_int;
164 }
165
166 unsigned char
toByte() const167 MP4::Item::toByte() const
168 {
169 return d->m_byte;
170 }
171
172 unsigned int
toUInt() const173 MP4::Item::toUInt() const
174 {
175 return d->m_uint;
176 }
177
178 long long
toLongLong() const179 MP4::Item::toLongLong() const
180 {
181 return d->m_longlong;
182 }
183
184 MP4::Item::IntPair
toIntPair() const185 MP4::Item::toIntPair() const
186 {
187 return d->m_intPair;
188 }
189
190 StringList
toStringList() const191 MP4::Item::toStringList() const
192 {
193 return d->m_stringList;
194 }
195
196 ByteVectorList
toByteVectorList() const197 MP4::Item::toByteVectorList() const
198 {
199 return d->m_byteVectorList;
200 }
201
202 MP4::CoverArtList
toCoverArtList() const203 MP4::Item::toCoverArtList() const
204 {
205 return d->m_coverArtList;
206 }
207
208 bool
isValid() const209 MP4::Item::isValid() const
210 {
211 return d->valid;
212 }
213