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