id3lib 3.8.3

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

frame_impl.cpp
Go to the documentation of this file.
1 // $Id: frame_impl.cpp,v 1.9 2002/07/02 22:12:38 t1mpy Exp $
2
3 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
4 // Copyright 1999, 2000 Scott Thomas Haug
5
6 // This library is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Library General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or (at your
9 // option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public License
17 // along with this library; if not, write to the Free Software Foundation,
18 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 // The id3lib authors encourage improvements and optimisations to be sent to
21 // the id3lib coordinator. Please see the README file for details on where to
22 // send such submissions. See the AUTHORS file for a list of people who have
23 // contributed to id3lib. See the ChangeLog file for a list of changes to
24 // id3lib. These files are distributed with id3lib at
25 // http://download.sourceforge.net/id3lib/
26
27 #if defined HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 //#include <string.h>
32 #include "tag.h"
33 #include "frame_impl.h"
34 #include "field_impl.h"
35 #include "frame_def.h"
36 #include "field_def.h"
37
38 ID3_FrameImpl::ID3_FrameImpl(ID3_FrameID id)
39 : _changed(false),
40 _bitset(),
41 _fields(),
42 _encryption_id('\0'),
43 _grouping_id('\0')
44 {
45 this->SetSpec(ID3V2_LATEST);
46 this->SetID(id);
47 }
48
49 ID3_FrameImpl::ID3_FrameImpl(const ID3_FrameHeader &hdr)
50 : _changed(false),
51 _bitset(),
52 _fields(),
53 _hdr(hdr),
54 _encryption_id('\0'),
55 _grouping_id('\0')
56 {
57 this->_InitFields();
58 }
59
60 ID3_FrameImpl::ID3_FrameImpl(const ID3_Frame& frame)
61 : _changed(false),
62 _bitset(),
63 _fields(),
64 _encryption_id('\0'),
65 _grouping_id('\0')
66 {
67 *this = frame;
68 }
69
70 ID3_FrameImpl::~ID3_FrameImpl()
71 {
72 Clear();
73 }
74
75 bool ID3_FrameImpl::_ClearFields()
76 {
77 for (iterator fi = _fields.begin(); fi != _fields.end(); ++fi)
78 {
79 delete (ID3_FieldImpl*) *fi;
80 }
81
82 _fields.clear();
83 _bitset.reset();
84
85 _changed = true;
86 return true;
87 }
88
89 void ID3_FrameImpl::Clear()
90 {
91 this->_ClearFields();
92 _hdr.Clear();
93 _encryption_id = '\0';
94 _grouping_id = '\0';
95 }
96
97 void ID3_FrameImpl::_InitFields()
98 {
99 const ID3_FrameDef* info = _hdr.GetFrameDef();
100 if (NULL == info)
101 {
102 // log this
103 ID3_Field* fld = new ID3_FieldImpl(ID3_FieldDef::DEFAULT[0]);
104 _fields.push_back(fld);
105 _bitset.set(fld->GetID());
106 }
107 else
108 {
109
110 for (size_t i = 0; info->aeFieldDefs[i]._id != ID3FN_NOFIELD; ++i)
111 {
112 ID3_Field* fld = new ID3_FieldImpl(info->aeFieldDefs[i]);
113 _fields.push_back(fld);
114 _bitset.set(fld->GetID());
115 }
116
117 _changed = true;
118 }
119 }
120
121 bool ID3_FrameImpl::SetID(ID3_FrameID id)
122 {
123 bool changed = (this->GetID() != id);
124 if (changed)
125 {
126 this->_SetID(id);
127 _changed = true;
128 }
129 return changed;
130 }
131
132 bool ID3_FrameImpl::_SetID(ID3_FrameID id)
133 {
134 bool changed = this->_ClearFields();
135 changed = _hdr.SetFrameID(id) || changed;
136 this->_InitFields();
137 return changed;
138 }
139
140 bool ID3_FrameImpl::SetSpec(ID3_V2Spec spec)
141 {
142 return _hdr.SetSpec(spec);
143 }
144
145 ID3_V2Spec ID3_FrameImpl::GetSpec() const
146 {
147 return _hdr.GetSpec();
148 }
149
150 ID3_Field* ID3_FrameImpl::GetField(ID3_FieldID fieldName) const
151 {
152 ID3_Field* field = NULL;
153 if (this->Contains(fieldName))
154 {
155 for (const_iterator fi = _fields.begin(); fi != _fields.end(); ++fi)
156 {
157 if ((*fi)->GetID() == fieldName)
158 {
159 field = *fi;
160 break;
161 }
162 }
163 }
164 return field;
165 }
166
167 size_t ID3_FrameImpl::NumFields() const
168 {
169 return _fields.size();
170 }
171
172 size_t ID3_FrameImpl::Size()
173 {
174 size_t bytesUsed = _hdr.Size();
175
176 if (this->GetEncryptionID())
177 {
178 bytesUsed++;
179 }
180
181 if (this->GetGroupingID())
182 {
183 bytesUsed++;
184 }
185
186 ID3_TextEnc enc = ID3TE_ASCII;
187 for (iterator fi = _fields.begin(); fi != _fields.end(); ++fi)
188 {
189 if (*fi && (*fi)->InScope(this->GetSpec()))
190 {
191 if ((*fi)->GetID() == ID3FN_TEXTENC)
192 {
193 enc = (ID3_TextEnc) (*fi)->Get();
194 }
195 else
196 {
197 (*fi)->SetEncoding(enc);
198 }
199 bytesUsed += (*fi)->BinSize();
200 }
201 }
202
203 return bytesUsed;
204 }
205
206
207 bool ID3_FrameImpl::HasChanged() const
208 {
209 bool changed = _changed;
210
211 for (const_iterator fi = _fields.begin(); fi != _fields.end(); ++fi)
212 {
213 if (*fi && (*fi)->InScope(this->GetSpec()))
214 {
215 changed = (*fi)->HasChanged();
216 }
217 }
218
219 return changed;
220 }
221
222 ID3_FrameImpl &
223 ID3_FrameImpl::operator=( const ID3_Frame &rFrame )
224 {
225 ID3_FrameID eID = rFrame.GetID();
226 this->SetID(eID);
227 ID3_Frame::ConstIterator* ri = rFrame.CreateIterator();
228 iterator li = this->begin();
229 while (li != this->end())
230 {
231 ID3_Field* thisFld = *li++;
232 const ID3_Field* thatFld = ri->GetNext();
233 if (thisFld != NULL && thatFld != NULL)
234 {
235 *thisFld = *thatFld;
236 }
237 }
238 delete ri;
239 this->SetEncryptionID(rFrame.GetEncryptionID());
240 this->SetGroupingID(rFrame.GetGroupingID());
241 this->SetCompression(rFrame.GetCompression());
242 this->SetSpec(rFrame.GetSpec());
243 _changed = false;
244
245 return *this;
246 }
247
248 const char* ID3_FrameImpl::GetDescription(ID3_FrameID id)
249 {
250 ID3_FrameDef* myFrameDef = ID3_FindFrameDef(id);
251 if (myFrameDef != NULL)
252 {
253 return myFrameDef->sDescription;
254 }
255 return NULL;
256 }
257
258 const char* ID3_FrameImpl::GetDescription() const
259 {
260 const ID3_FrameDef* def = _hdr.GetFrameDef();
261 if (def)
262 {
263 return def->sDescription;
264 }
265 return NULL;
266 }
267
ID3_FrameHeader::SetFrameID
bool SetFrameID(ID3_FrameID id)
Definition: header_frame.cpp:65
ID3_FrameImpl::_SetID
bool _SetID(ID3_FrameID)
Definition: frame_impl.cpp:132
tag.h
ID3_FrameImpl::GetGroupingID
uchar GetGroupingID() const
Definition: frame_impl.h:114
ID3_FindFrameDef
ID3_FrameDef * ID3_FindFrameDef(ID3_FrameID id)
Definition: field.cpp:1077
ID3_FrameImpl::_InitFields
void _InitFields()
Definition: frame_impl.cpp:97
ID3_FrameImpl::GetEncryptionID
uchar GetEncryptionID() const
Definition: frame_impl.h:105
ID3_FrameDef::aeFieldDefs
const ID3_FieldDef * aeFieldDefs
Definition: frame_def.h:43
ID3_FrameImpl::NumFields
size_t NumFields() const
Definition: frame_impl.cpp:167
ID3_FrameDef
Definition: frame_def.h:36
ID3_FrameImpl::iterator
Fields::iterator iterator
Definition: frame_impl.h:46
ID3_FrameImpl
Definition: frame_impl.h:41
ID3_FrameImpl::SetEncryptionID
bool SetEncryptionID(uchar id)
Definition: frame_impl.h:97
ID3_FieldDef::_id
ID3_FieldID _id
Definition: field_def.h:35
ID3_FrameHeader::Size
size_t Size() const
Definition: header_frame.cpp:79
ID3_FrameHeader::Clear
bool Clear()
Definition: header_frame.cpp:225
ID3TE_ASCII
Definition: globals.h:145
ID3_Frame::GetID
ID3_FrameID GetID() const
Returns the type of frame that the object represents.
Definition: frame.cpp:94
ID3_FrameID
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition: globals.h:229
ID3_FrameImpl::~ID3_FrameImpl
virtual ~ID3_FrameImpl()
Destructor.
Definition: frame_impl.cpp:70
ID3_FieldImpl
Definition: field_impl.h:40
ID3_FrameImpl::begin
iterator begin()
Definition: frame_impl.h:116
ID3_Field::GetID
virtual ID3_FieldID GetID() const =0
field_def.h
ID3_Frame::GetGroupingID
uchar GetGroupingID() const
Definition: frame.cpp:257
ID3_FrameImpl::SetGroupingID
bool SetGroupingID(uchar id)
Definition: frame_impl.h:106
ID3_Frame::GetSpec
ID3_V2Spec GetSpec() const
Definition: frame.cpp:126
field_impl.h
ID3_FrameImpl::ID3_FrameImpl
ID3_FrameImpl(ID3_FrameID id=ID3FID_NOFRAME)
Definition: frame_impl.cpp:38
ID3_FrameImpl::SetID
bool SetID(ID3_FrameID id)
Definition: frame_impl.cpp:121
ID3_FrameImpl::GetID
ID3_FrameID GetID() const
Definition: frame_impl.h:59
ID3_FieldDef::DEFAULT
static const ID3_FieldDef * DEFAULT
Definition: field_def.h:42
ID3_V2Spec
ID3_V2Spec
Definition: globals.h:161
ID3_TextEnc
ID3_TextEnc
Enumeration of the types of text encodings: ascii or unicode.
Definition: globals.h:137
ID3_FrameImpl::HasChanged
bool HasChanged() const
Definition: frame_impl.cpp:207
ID3_FrameHeader
Definition: header_frame.h:36
ID3_Header::SetSpec
virtual bool SetSpec(ID3_V2Spec)
Definition: header.cpp:34
ID3_FrameImpl::Clear
void Clear()
Definition: frame_impl.cpp:89
ID3_Frame::CreateIterator
Iterator * CreateIterator()
Definition: frame.cpp:310
ID3_Header::GetSpec
ID3_V2Spec GetSpec() const
Definition: header.h:62
ID3_Frame
The representative class of an id3v2 frame.
Definition: id3lib_frame.h:38
ID3_FrameImpl::GetDescription
const char * GetDescription() const
Definition: frame_impl.cpp:258
frame_impl.h
ID3FN_TEXTENC
Text encoding (unicode or ASCII)
Definition: globals.h:200
ID3_FrameHeader::GetFrameDef
const ID3_FrameDef * GetFrameDef() const
Definition: header_frame.cpp:220
frame_def.h
ID3_FrameDef::sDescription
const char * sDescription
Definition: frame_def.h:44
ID3_FrameImpl::SetSpec
bool SetSpec(ID3_V2Spec)
Definition: frame_impl.cpp:140
ID3_Frame::GetCompression
bool GetCompression() const
Returns whether or not the compression flag is set.
Definition: frame.cpp:232
ID3FN_NOFIELD
No field.
Definition: globals.h:199
NULL
#define NULL
Definition: globals.h:743
ID3_FrameImpl::const_iterator
Fields::const_iterator const_iterator
Definition: frame_impl.h:47
ID3_Field
The representative class of an ID3v2 field.
Definition: field.h:36
ID3_Frame::ConstIterator::GetNext
virtual const ID3_Field * GetNext()=0
ID3_FrameImpl::end
iterator end()
Definition: frame_impl.h:117
ID3_Frame::GetEncryptionID
uchar GetEncryptionID() const
Definition: frame.cpp:247
ID3_FrameImpl::SetCompression
bool SetCompression(bool b)
Sets the compression flag within the frame.
Definition: frame_impl.h:85
ID3_FrameImpl::_ClearFields
bool _ClearFields()
Definition: frame_impl.cpp:75
ID3_FrameImpl::Size
size_t Size()
Definition: frame_impl.cpp:172
ID3_FrameImpl::GetSpec
ID3_V2Spec GetSpec() const
Definition: frame_impl.cpp:145
ID3_FrameImpl::Contains
bool Contains(ID3_FieldID fld) const
Definition: frame_impl.h:75
ID3_FieldID
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition: globals.h:197
ID3_FrameImpl::GetField
ID3_Field * GetField(ID3_FieldID name) const
Definition: frame_impl.cpp:150
ID3_FrameImpl::operator=
ID3_FrameImpl & operator=(const ID3_Frame &)
Definition: frame_impl.cpp:223
ID3_Frame::ConstIterator
Definition: id3lib_frame.h:49
ID3V2_LATEST
Definition: globals.h:169