id3lib  3.8.3
tag_find.cpp
Go to the documentation of this file.
1 // $Id: tag_find.cpp,v 1.28 2003/03/02 14:39:25 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 #include "tag_impl.h" //has <stdio.h> "tag.h" "header_tag.h" "frame.h" "field.h" "spec.h" "id3lib_strings.h" "utils.h"
28 
29 using namespace dami;
30 
32 {
33  const_iterator cur = _frames.begin();
34 
35  for (; cur != _frames.end(); ++cur)
36  {
37  if (*cur == frame)
38  {
39  break;
40  }
41  }
42 
43  return cur;
44 }
45 
47 {
48  iterator cur = _frames.begin();
49 
50  for (; cur != _frames.end(); ++cur)
51  {
52  if (*cur == frame)
53  {
54  break;
55  }
56  }
57 
58  return cur;
59 }
60 
62 {
63  ID3_Frame *frame = NULL;
64 
65  // reset the cursor if it isn't set
66  if (_frames.end() == _cursor)
67  {
68  _cursor = _frames.begin();
69  }
70 
71 
72  for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
73  {
74  // We want to cycle through the list to find the matching frame. We
75  // should begin from the cursor, search each successive frame, wrapping
76  // if necessary. The enclosing loop and the assignment statments below
77  // ensure that we first begin at the cursor and search to the end of the
78  // list and, if unsuccessful, start from the beginning of the list and
79  // search to the cursor.
81  begin = (0 == iCount ? _cursor : _frames.begin()),
82  end = (0 == iCount ? _frames.end() : _cursor);
83  // search from the cursor to the end
84  for (const_iterator cur = begin; cur != end; ++cur)
85  {
86  if ((*cur != NULL) && ((*cur)->GetID() == id))
87  {
88  // We've found a valid frame. Set the cursor to be the next element
89  frame = *cur;
90  _cursor = ++cur;
91  break;
92  }
93  }
94  }
95 
96  return frame;
97 }
98 
99 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, String data) const
100 {
101  ID3_Frame *frame = NULL;
102  ID3D_NOTICE( "Find: looking for comment with data = " << data.c_str() );
103 
104  // reset the cursor if it isn't set
105  if (_frames.end() == _cursor)
106  {
107  _cursor = _frames.begin();
108  ID3D_NOTICE( "Find: resetting cursor" );
109  }
110 
111  for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
112  {
113  ID3D_NOTICE( "Find: iCount = " << iCount );
114  // We want to cycle through the list to find the matching frame. We
115  // should begin from the cursor, search each successive frame, wrapping
116  // if necessary. The enclosing loop and the assignment statments below
117  // ensure that we first begin at the cursor and search to the end of the
118  // list and, if unsuccessful, start from the beginning of the list and
119  // search to the cursor.
120  const_iterator
121  begin = (0 == iCount ? _cursor : _frames.begin()),
122  end = (0 == iCount ? _frames.end() : _cursor);
123  // search from the cursor to the end
124  for (const_iterator cur = begin; cur != end; ++cur)
125  {
126  ID3D_NOTICE( "Find: frame = 0x" << hex << (uint32) *cur << dec );
127  if ((*cur != NULL) && ((*cur)->GetID() == id) &&
128  (*cur)->Contains(fldID))
129  {
130  ID3_Field* fld = (*cur)->GetField(fldID);
131  if (NULL == fld)
132  {
133  continue;
134  ID3D_NOTICE( "Find: didn't have the right field" );
135  }
136 
137  String text( NULL == fld->GetRawText() ? "" : fld->GetRawText() , fld->Size()); //PHF
138  ID3D_NOTICE( "Find: text = " << text.c_str() );
139 
140  if (text == data)
141  {
142  // We've found a valid frame. Set cursor to be the next element
143  frame = *cur;
144  _cursor = ++cur;
145  break;
146  }
147  }
148  }
149  }
150 
151  return frame;
152 }
153 
154 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, WString data) const
155 {
156  ID3_Frame *frame = NULL;
157 
158  // reset the cursor if it isn't set
159  if (_frames.end() == _cursor)
160  {
161  _cursor = _frames.begin();
162  }
163 
164  for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
165  {
166  // We want to cycle through the list to find the matching frame. We
167  // should begin from the cursor, search each successive frame, wrapping
168  // if necessary. The enclosing loop and the assignment statments below
169  // ensure that we first begin at the cursor and search to the end of the
170  // list and, if unsuccessful, start from the beginning of the list and
171  // search to the cursor.
172  const_iterator
173  begin = (0 == iCount ? _cursor : _frames.begin()),
174  end = (0 == iCount ? _frames.end() : _cursor);
175  // search from the cursor to the end
176  for (const_iterator cur = begin; cur != end; ++cur)
177  {
178  if ((*cur != NULL) && ((*cur)->GetID() == id) &&
179  (*cur)->Contains(fldID))
180  {
181  ID3_Field* fld = (*cur)->GetField(fldID);
182  if (NULL == fld)
183  {
184  continue;
185  }
186  WString text = toWString(fld->GetRawUnicodeText(), fld->Size());
187 
188  if (text == data)
189  {
190  // We've found a valid frame. Set cursor to be the next element
191  frame = *cur;
192  _cursor = ++cur;
193  break;
194  }
195  }
196  }
197  }
198 
199  return frame;
200 }
201 
202 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, uint32 data) const
203 {
204  ID3_Frame *frame = NULL;
205 
206  // reset the cursor if it isn't set
207  if (_frames.end() == _cursor)
208  {
209  _cursor = _frames.begin();
210  }
211 
212  for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
213  {
214  // We want to cycle through the list to find the matching frame. We
215  // should begin from the cursor, search each successive frame, wrapping
216  // if necessary. The enclosing loop and the assignment statments below
217  // ensure that we first begin at the cursor and search to the end of the
218  // list and, if unsuccessful, start from the beginning of the list and
219  // search to the cursor.
221  begin = (0 == iCount ? _cursor : _frames.begin()),
222  end = (0 == iCount ? _frames.end() : _cursor);
223  // search from the cursor to the end
224  for (const_iterator cur = begin; cur != end; ++cur)
225  {
226  if ((*cur != NULL) && ((*cur)->GetID() == id) &&
227  ((*cur)->GetField(fldID)->Get() == data))
228  {
229  // We've found a valid frame. Set the cursor to be the next element
230  frame = *cur;
231  _cursor = ++cur;
232  break;
233  }
234  }
235  }
236 
237  return frame;
238 }
239 
The representative class of an ID3v2 field.
Definition: field.h:37
virtual const char * GetRawText() const =0
virtual const unicode_t * GetRawUnicodeText() const =0
virtual size_t Size() const =0
Returns the size of a field.
The representative class of an id3v2 frame.
ID3_Frame * Find(ID3_FrameID id) const
Definition: tag_find.cpp:61
Frames::iterator iterator
Definition: tag_impl.h:77
Frames::const_iterator const_iterator
Definition: tag_impl.h:78
#define NULL
Definition: globals.h:743
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition: globals.h:198
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition: globals.h:230
Definition: tag_impl.h:42
WString ID3_C_EXPORT toWString(const unicode_t[], size_t)
Definition: utils.cpp:383