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

src/tag_impl.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: tag_impl.h,v 1.1 2000/10/24 16:15:35 eldamitri Exp $
00003 
00004 // id3lib: a software library for creating and manipulating id3v1/v2 tags
00005 // Copyright 1999, 2000  Scott Thomas Haug
00006 
00007 // This library is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU Library General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or (at your
00010 // option) any later version.
00011 //
00012 // This library is distributed in the hope that it will be useful, but WITHOUT
00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 // License for more details.
00016 //
00017 // You should have received a copy of the GNU Library General Public License
00018 // along with this library; if not, write to the Free Software Foundation,
00019 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 
00021 // The id3lib authors encourage improvements and optimisations to be sent to
00022 // the id3lib coordinator.  Please see the README file for details on where to
00023 // send such submissions.  See the AUTHORS file for a list of people who have
00024 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00025 // id3lib.  These files are distributed with id3lib at
00026 // http://download.sourceforge.net/id3lib/
00027 
00028 #ifndef _ID3LIB_TAG_IMPL_H_
00029 #define _ID3LIB_TAG_IMPL_H_
00030 
00031 #include <list>
00032 #include <stdio.h>
00033 #include "tag.h"
00034 #include "header_tag.h"
00035 #include "frame.h"
00036 #include "field.h"
00037 #include "spec.h"
00038 #include "strings.h"
00039 
00040 class ID3_Reader;
00041 class ID3_Writer;
00042 
00043 namespace dami
00044 {
00045   namespace id3
00046   {
00047     namespace v1
00048     {
00049       bool parse(ID3_TagImpl&, ID3_Reader&);
00050       void render(ID3_Writer&, const ID3_TagImpl&);
00051     };
00052     namespace v2
00053     {
00054       bool parse(ID3_TagImpl& tag, ID3_Reader& rdr);
00055       void render(ID3_Writer& writer, const ID3_TagImpl& tag);
00056     };
00057   };
00058   namespace lyr3
00059   {
00060     namespace v1
00061     {
00062       bool parse(ID3_TagImpl&, ID3_Reader&);
00063     };
00064     namespace v2
00065     {
00066       bool parse(ID3_TagImpl&, ID3_Reader&);
00067     };
00068   };
00069   namespace mm
00070   {
00071     bool parse(ID3_TagImpl&, ID3_Reader&);
00072   };
00073 };
00074 
00075 class ID3_TagImpl
00076 {
00077   typedef std::list<ID3_Frame *> Frames;
00078 public:
00079   typedef Frames::iterator       iterator;
00080   typedef Frames::const_iterator const_iterator;
00081 public:
00082   ID3_TagImpl(const char *name = NULL);
00083   ID3_TagImpl(const ID3_Tag &tag);
00084   virtual ~ID3_TagImpl();
00085   
00086   void       Clear();
00087   bool       HasChanged() const;
00088   void       SetChanged(bool b) { _changed = b; }
00089   size_t     Size() const;
00090   
00091   bool       SetUnsync(bool);
00092   bool       SetExtended(bool);
00093   bool       SetExperimental(bool);
00094   bool       SetPadding(bool);
00095 
00096   bool       GetUnsync() const;
00097   bool       GetExtended() const;
00098   bool       GetExperimental() const;
00099   
00100   void       AddFrame(const ID3_Frame&);
00101   void       AddFrame(const ID3_Frame*);
00102   void       AttachFrame(ID3_Frame*);
00103   ID3_Frame* RemoveFrame(const ID3_Frame *);
00104   
00105   size_t     Link(const char *fileInfo, flags_t = (flags_t) ID3TT_ALL);
00106   flags_t    Update(flags_t = (flags_t) ID3TT_ALL);
00107   flags_t    Strip(flags_t = (flags_t) ID3TT_ALL);
00108   
00109   size_t     GetPrependedBytes() const { return _prepended_bytes; }
00110   size_t     GetAppendedBytes() const { return _appended_bytes; }
00111   size_t     GetFileSize() const { return _file_size; }
00112   dami::String GetFileName() const { return _file_name; }
00113   
00114   ID3_Frame* Find(ID3_FrameID id) const;
00115   ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, uint32 data) const;
00116   ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, dami::String) const;
00117   ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, dami::WString) const;
00118   
00119   size_t     NumFrames() const { return _frames.size(); }
00120   ID3_TagImpl&   operator=( const ID3_Tag & );
00121   
00122   bool       HasTagType(uint16 tt) const { return _file_tags.test(tt); }
00123   ID3_V2Spec GetSpec() const;
00124   bool       SetSpec(ID3_V2Spec);
00125   
00126   static size_t IsV2Tag(ID3_Reader&);
00127 
00128   iterator         begin()       { return _frames.begin(); }
00129   iterator         end()         { return _frames.end(); }
00130   const_iterator   begin() const { return _frames.begin(); }
00131   const_iterator   end()   const { return _frames.end(); }
00132   
00133   /* Deprecated! */
00134   void       AddNewFrame(ID3_Frame* f) { this->AttachFrame(f); }
00135   size_t     Link(const char *fileInfo, bool parseID3v1, bool parseLyrics3);
00136   void       SetCompression(bool) { ; }
00137   void       AddFrames(const ID3_Frame *, size_t);
00138   bool       HasLyrics() const { return this->HasTagType(ID3TT_LYRICS); }
00139   bool       HasV2Tag()  const { return this->HasTagType(ID3TT_ID3V2); }
00140   bool       HasV1Tag()  const { return this->HasTagType(ID3TT_ID3V1); }
00141   size_t     PaddingSize(size_t) const;
00142   
00143 protected:
00144   const_iterator Find(const ID3_Frame *) const;
00145   iterator Find(const ID3_Frame *);
00146   
00147   void       RenderExtHeader(uchar *);
00148 
00149   void       ParseFile();
00150   
00151 private:
00152   ID3_TagHeader _hdr;          // information relevant to the tag header
00153   bool       _is_padded;       // add padding to tags?
00154   
00155   Frames     _frames;
00156   
00157   mutable const_iterator   _cursor;  // which frame in list are we at
00158   mutable bool       _changed; // has tag changed since last parse or render?
00159   
00160   // file-related member variables
00161   dami::String _file_name;       // name of the file we are linked to
00162   size_t     _file_size;       // the size of the file (without any tag(s))
00163   size_t     _prepended_bytes; // number of tag bytes at start of file
00164   size_t     _appended_bytes;  // number of tag bytes at end of file
00165   bool       _is_file_writable;// is the associated file (via Link) writable?
00166   ID3_Flags  _tags_to_parse;   // which tag types should attempt to be parsed
00167   ID3_Flags  _file_tags;       // which tag types does the file contain
00168 };
00169 
00170 size_t     ID3_GetDataSize(const ID3_TagImpl&);
00171 
00172 #endif /* _ID3LIB_TAG_IMPL_H_ */

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