src/tag_find.cpp

Go to the documentation of this file.
00001 // $Id: tag_find.cpp,v 1.28 2003/03/02 14:39:25 t1mpy 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 #include "tag_impl.h" //has <stdio.h> "tag.h" "header_tag.h" "frame.h" "field.h" "spec.h" "id3lib_strings.h" "utils.h"
00028 
00029 using namespace dami;
00030 
00031 ID3_TagImpl::const_iterator ID3_TagImpl::Find(const ID3_Frame *frame) const
00032 {
00033   const_iterator cur = _frames.begin();
00034 
00035   for (; cur != _frames.end(); ++cur)
00036   {
00037     if (*cur == frame)
00038     {
00039       break;
00040     }
00041   }
00042 
00043   return cur;
00044 }
00045 
00046 ID3_TagImpl::iterator ID3_TagImpl::Find(const ID3_Frame *frame)
00047 {
00048   iterator cur = _frames.begin();
00049 
00050   for (; cur != _frames.end(); ++cur)
00051   {
00052     if (*cur == frame)
00053     {
00054       break;
00055     }
00056   }
00057 
00058   return cur;
00059 }
00060 
00061 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id) const
00062 {
00063   ID3_Frame *frame = NULL;
00064 
00065   // reset the cursor if it isn't set
00066   if (_frames.end() == _cursor)
00067   {
00068     _cursor = _frames.begin();
00069   }
00070 
00071 
00072   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00073   {
00074     // We want to cycle through the list to find the matching frame.  We
00075     // should begin from the cursor, search each successive frame, wrapping
00076     // if necessary.  The enclosing loop and the assignment statments below
00077     // ensure that we first begin at the cursor and search to the end of the
00078     // list and, if unsuccessful, start from the beginning of the list and
00079     // search to the cursor.
00080     const_iterator
00081       begin  = (0 == iCount ? _cursor       : _frames.begin()),
00082       end    = (0 == iCount ? _frames.end() : _cursor);
00083     // search from the cursor to the end
00084     for (const_iterator cur = begin; cur != end; ++cur)
00085     {
00086       if ((*cur != NULL) && ((*cur)->GetID() == id))
00087       {
00088         // We've found a valid frame.  Set the cursor to be the next element
00089         frame = *cur;
00090         _cursor = ++cur;
00091         break;
00092       }
00093     }
00094   }
00095 
00096   return frame;
00097 }
00098 
00099 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, String data) const
00100 {
00101   ID3_Frame *frame = NULL;
00102   ID3D_NOTICE( "Find: looking for comment with data = " << data.c_str() );
00103 
00104   // reset the cursor if it isn't set
00105   if (_frames.end() == _cursor)
00106   {
00107     _cursor = _frames.begin();
00108     ID3D_NOTICE( "Find: resetting cursor" );
00109   }
00110 
00111   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00112   {
00113     ID3D_NOTICE( "Find: iCount = " << iCount );
00114     // We want to cycle through the list to find the matching frame.  We
00115     // should begin from the cursor, search each successive frame, wrapping
00116     // if necessary.  The enclosing loop and the assignment statments below
00117     // ensure that we first begin at the cursor and search to the end of the
00118     // list and, if unsuccessful, start from the beginning of the list and
00119     // search to the cursor.
00120     const_iterator
00121       begin  = (0 == iCount ? _cursor       : _frames.begin()),
00122       end    = (0 == iCount ? _frames.end() : _cursor);
00123     // search from the cursor to the end
00124     for (const_iterator cur = begin; cur != end; ++cur)
00125     {
00126       ID3D_NOTICE( "Find: frame = 0x" << hex << (uint32) *cur << dec );
00127       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00128           (*cur)->Contains(fldID))
00129       {
00130         ID3_Field* fld = (*cur)->GetField(fldID);
00131         if (NULL == fld)
00132         {
00133           continue;
00134           ID3D_NOTICE( "Find: didn't have the right field" );
00135         }
00136 
00137         String text( NULL == fld->GetRawText() ? "" : fld->GetRawText() , fld->Size()); //PHF
00138         ID3D_NOTICE( "Find: text = " << text.c_str() );
00139 
00140         if (text == data)
00141         {
00142           // We've found a valid frame.  Set cursor to be the next element
00143           frame = *cur;
00144           _cursor = ++cur;
00145           break;
00146         }
00147       }
00148     }
00149   }
00150 
00151   return frame;
00152 }
00153 
00154 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, WString data) const
00155 {
00156   ID3_Frame *frame = NULL;
00157 
00158   // reset the cursor if it isn't set
00159   if (_frames.end() == _cursor)
00160   {
00161     _cursor = _frames.begin();
00162   }
00163 
00164   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00165   {
00166     // We want to cycle through the list to find the matching frame.  We
00167     // should begin from the cursor, search each successive frame, wrapping
00168     // if necessary.  The enclosing loop and the assignment statments below
00169     // ensure that we first begin at the cursor and search to the end of the
00170     // list and, if unsuccessful, start from the beginning of the list and
00171     // search to the cursor.
00172     const_iterator
00173       begin  = (0 == iCount ? _cursor       : _frames.begin()),
00174       end    = (0 == iCount ? _frames.end() : _cursor);
00175     // search from the cursor to the end
00176     for (const_iterator cur = begin; cur != end; ++cur)
00177     {
00178       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00179           (*cur)->Contains(fldID))
00180       {
00181         ID3_Field* fld = (*cur)->GetField(fldID);
00182         if (NULL == fld)
00183         {
00184           continue;
00185         }
00186         WString text = toWString(fld->GetRawUnicodeText(), fld->Size());
00187 
00188         if (text == data)
00189         {
00190           // We've found a valid frame.  Set cursor to be the next element
00191           frame = *cur;
00192           _cursor = ++cur;
00193           break;
00194         }
00195       }
00196     }
00197   }
00198 
00199   return frame;
00200 }
00201 
00202 ID3_Frame *ID3_TagImpl::Find(ID3_FrameID id, ID3_FieldID fldID, uint32 data) const
00203 {
00204   ID3_Frame *frame = NULL;
00205 
00206   // reset the cursor if it isn't set
00207   if (_frames.end() == _cursor)
00208   {
00209     _cursor = _frames.begin();
00210   }
00211 
00212   for (int iCount = 0; iCount < 2 && frame == NULL; iCount++)
00213   {
00214     // We want to cycle through the list to find the matching frame.  We
00215     // should begin from the cursor, search each successive frame, wrapping
00216     // if necessary.  The enclosing loop and the assignment statments below
00217     // ensure that we first begin at the cursor and search to the end of the
00218     // list and, if unsuccessful, start from the beginning of the list and
00219     // search to the cursor.
00220     const_iterator
00221       begin  = (0 == iCount ? _cursor       : _frames.begin()),
00222       end    = (0 == iCount ? _frames.end() : _cursor);
00223     // search from the cursor to the end
00224     for (const_iterator cur = begin; cur != end; ++cur)
00225     {
00226       if ((*cur != NULL) && ((*cur)->GetID() == id) &&
00227           ((*cur)->GetField(fldID)->Get() == data))
00228       {
00229         // We've found a valid frame.  Set the cursor to be the next element
00230         frame = *cur;
00231         _cursor = ++cur;
00232         break;
00233       }
00234     }
00235   }
00236 
00237   return frame;
00238 }
00239 

Generated on Mon Aug 20 17:48:46 2007 for id3lib by  doxygen 1.5.2