Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

src/tag_find.cpp

Go to the documentation of this file.
00001 // $Id: tag_find.cpp,v 1.26 2000/10/29 01:37:29 eldamitri Exp $
00002 
00003 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
00004 // Copyright 1999, 2000  Scott Thomas Haug
00005 
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Library General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or (at your
00009 // option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful, but WITHOUT
00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 // License for more details.
00015 //
00016 // You should have received a copy of the GNU Library General Public License
00017 // along with this library; if not, write to the Free Software Foundation,
00018 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020 // The id3lib authors encourage improvements and optimisations to be sent to
00021 // the id3lib coordinator.  Please see the README file for details on where to
00022 // send such submissions.  See the AUTHORS file for a list of people who have
00023 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00024 // id3lib.  These files are distributed with id3lib at
00025 // http://download.sourceforge.net/id3lib/
00026 
00027 #if defined HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030 
00031 
00032 
00033 #include <string.h>
00034 
00035 #include "tag_impl.h"
00036 #include "field.h"
00037 #include "utils.h"
00038 
00039 using namespace dami;
00040 
00041 ID3_TagImpl::const_iterator ID3_TagImpl::Find(const ID3_Frame *frame) const
00042 {
00043   const_iterator cur = _frames.begin();
00044   
00045   for (; cur != _frames.end(); ++cur)
00046   {
00047     if (*cur == frame)
00048     {
00049       break;
00050     }
00051   }
00052   
00053   return cur;
00054 }
00055 
00056 ID3_TagImpl::iterator ID3_TagImpl::Find(const ID3_Frame *frame)
00057 {
00058   iterator cur = _frames.begin();
00059   
00060   for (; cur != _frames.end(); ++cur)
00061   {
00062     if (*cur == frame)
00063     {
00064       break;
00065     }
00066   }
00067   
00068   return cur;
00069 }
00070 
00071 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id) const
00072 {
00073   ID3_Frame *frame = NULL;
00074   
00075   // reset the cursor if it isn't set
00076   if (_frames.end() == _cursor)
00077   {
00078     _cursor = _frames.begin();
00079   }
00080 
00081 
00082   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00083   {
00084     // We want to cycle through the list to find the matching frame.  We
00085     // should begin from the cursor, search each successive frame, wrapping
00086     // if necessary.  The enclosing loop and the assignment statments below
00087     // ensure that we first begin at the cursor and search to the end of the
00088     // list and, if unsuccessful, start from the beginning of the list and
00089     // search to the cursor.
00090     const_iterator
00091       begin  = (0 == iCount ? _cursor       : _frames.begin()), 
00092       end    = (0 == iCount ? _frames.end() : _cursor);
00093     // search from the cursor to the end
00094     for (const_iterator cur = begin; cur != end; ++cur)
00095     {
00096       if ((*cur != NULL) && ((*cur)->GetID() == id))
00097       {
00098         // We've found a valid frame.  Set the cursor to be the next element
00099         frame = *cur;
00100         _cursor = ++cur;
00101         break;
00102       }
00103     }
00104   }
00105   
00106   return frame;
00107 }
00108 
00109 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, String data) const
00110 {
00111   ID3_Frame *frame = NULL;
00112   ID3D_NOTICE( "Find: looking for comment with data = " << data.c_str() );
00113   
00114   // reset the cursor if it isn't set
00115   if (_frames.end() == _cursor)
00116   {
00117     _cursor = _frames.begin();
00118     ID3D_NOTICE( "Find: resetting cursor" );
00119   }
00120 
00121   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00122   {
00123     ID3D_NOTICE( "Find: iCount = " << iCount );
00124     // We want to cycle through the list to find the matching frame.  We
00125     // should begin from the cursor, search each successive frame, wrapping
00126     // if necessary.  The enclosing loop and the assignment statments below
00127     // ensure that we first begin at the cursor and search to the end of the
00128     // list and, if unsuccessful, start from the beginning of the list and
00129     // search to the cursor.
00130     const_iterator
00131       begin  = (0 == iCount ? _cursor       : _frames.begin()), 
00132       end    = (0 == iCount ? _frames.end() : _cursor);
00133     // search from the cursor to the end
00134     for (const_iterator cur = begin; cur != end; ++cur)
00135     {
00136       ID3D_NOTICE( "Find: frame = 0x" << hex << (uint32) *cur << dec );
00137       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00138           (*cur)->Contains(fldID))
00139       {
00140         ID3_Field* fld = (*cur)->GetField(fldID);
00141         if (NULL == fld)
00142         {
00143           continue;
00144           ID3D_NOTICE( "Find: didn't have the right field" );
00145         }
00146 
00147         String text(fld->GetRawText(), fld->Size());
00148         ID3D_NOTICE( "Find: text = " << text.c_str() );
00149 
00150         if (text == data)
00151         {
00152           // We've found a valid frame.  Set cursor to be the next element
00153           frame = *cur;
00154           _cursor = ++cur;
00155           break;
00156         }
00157       }
00158     }
00159   }
00160   
00161   return frame;
00162 }
00163 
00164 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, WString data) const
00165 {
00166   ID3_Frame *frame = NULL;
00167   
00168   // reset the cursor if it isn't set
00169   if (_frames.end() == _cursor)
00170   {
00171     _cursor = _frames.begin();
00172   }
00173 
00174   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00175   {
00176     // We want to cycle through the list to find the matching frame.  We
00177     // should begin from the cursor, search each successive frame, wrapping
00178     // if necessary.  The enclosing loop and the assignment statments below
00179     // ensure that we first begin at the cursor and search to the end of the
00180     // list and, if unsuccessful, start from the beginning of the list and
00181     // search to the cursor.
00182     const_iterator
00183       begin  = (0 == iCount ? _cursor       : _frames.begin()), 
00184       end    = (0 == iCount ? _frames.end() : _cursor);
00185     // search from the cursor to the end
00186     for (const_iterator cur = begin; cur != end; ++cur)
00187     {
00188       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00189           (*cur)->Contains(fldID))
00190       {
00191         ID3_Field* fld = (*cur)->GetField(fldID);
00192         if (NULL == fld)
00193         {
00194           continue;
00195         }
00196         WString text = toWString(fld->GetRawUnicodeText(), fld->Size());
00197 
00198         if (text == data)
00199         {
00200           // We've found a valid frame.  Set cursor to be the next element
00201           frame = *cur;
00202           _cursor = ++cur;
00203           break;
00204         }
00205       }
00206     }
00207   }
00208   
00209   return frame;
00210 }
00211 
00212 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, uint32 data) const
00213 {
00214   ID3_Frame *frame = NULL;
00215   
00216   // reset the cursor if it isn't set
00217   if (_frames.end() == _cursor)
00218   {
00219     _cursor = _frames.begin();
00220   }
00221 
00222   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00223   {
00224     // We want to cycle through the list to find the matching frame.  We
00225     // should begin from the cursor, search each successive frame, wrapping
00226     // if necessary.  The enclosing loop and the assignment statments below
00227     // ensure that we first begin at the cursor and search to the end of the
00228     // list and, if unsuccessful, start from the beginning of the list and
00229     // search to the cursor.
00230     const_iterator
00231       begin  = (0 == iCount ? _cursor       : _frames.begin()), 
00232       end    = (0 == iCount ? _frames.end() : _cursor);
00233     // search from the cursor to the end
00234     for (const_iterator cur = begin; cur != end; ++cur)
00235     {
00236       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00237           ((*cur)->GetField(fldID)->Get() == data))
00238       {
00239         // We've found a valid frame.  Set the cursor to be the next element
00240         frame = *cur;
00241         _cursor = ++cur;
00242         break;
00243       }
00244     }
00245   }
00246   
00247   return frame;
00248 }
00249 

Generated at Sat Sep 8 15:51:10 2001 for id3lib by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001