00001 // -*- C++ -*- 00002 // $Id: frame_impl.h,v 1.2 2000/11/07 09:18:36 eldamitri Exp $ 00003 00004 // id3lib: a C++ 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_FRAME_IMPL_H_ 00029 #define _ID3LIB_FRAME_IMPL_H_ 00030 00031 #include <vector> 00032 #include <bitset> 00033 #include "frame.h" 00034 #include "header_frame.h" 00035 00036 class ID3_FrameImpl 00037 { 00038 typedef std::bitset<ID3FN_LASTFIELDID> Bitset; 00039 typedef std::vector<ID3_Field *> Fields; 00040 public: 00041 typedef Fields::iterator iterator; 00042 typedef Fields::const_iterator const_iterator; 00043 public: 00044 ID3_FrameImpl(ID3_FrameID id = ID3FID_NOFRAME); 00045 ID3_FrameImpl(const ID3_FrameHeader&); 00046 ID3_FrameImpl(const ID3_Frame&); 00047 00049 virtual ~ID3_FrameImpl(); 00050 00051 void Clear(); 00052 00053 bool SetID(ID3_FrameID id); 00054 ID3_FrameID GetID() const { return _hdr.GetFrameID(); } 00055 00056 ID3_Field* GetField(ID3_FieldID name) const; 00057 00058 size_t NumFields() const; 00059 00060 const char* GetDescription() const; 00061 static const char* GetDescription(ID3_FrameID); 00062 00063 const char* GetTextID() const { return _hdr.GetTextID(); } 00064 00065 ID3_FrameImpl& operator=(const ID3_Frame &); 00066 bool HasChanged() const; 00067 bool Parse(ID3_Reader&); 00068 void Render(ID3_Writer&) const; 00069 size_t Size(); 00070 bool Contains(ID3_FieldID fld) const 00071 { return _bitset.test(fld); } 00072 bool SetSpec(ID3_V2Spec); 00073 ID3_V2Spec GetSpec() const; 00074 00080 bool SetCompression(bool b) { return _hdr.SetCompression(b); } 00089 bool GetCompression() const { return _hdr.GetCompression(); } 00090 size_t GetDataSize() const { return _hdr.GetDataSize(); } 00091 00092 bool SetEncryptionID(uchar id) 00093 { 00094 bool changed = id != _encryption_id; 00095 _encryption_id = id; 00096 _changed = _changed || changed; 00097 _hdr.SetEncryption(true); 00098 return changed; 00099 } 00100 uchar GetEncryptionID() const { return _encryption_id; } 00101 bool SetGroupingID(uchar id) 00102 { 00103 bool changed = id != _grouping_id; 00104 _grouping_id = id; 00105 _changed = _changed || changed; 00106 _hdr.SetGrouping(true); 00107 return changed; 00108 } 00109 uchar GetGroupingID() const { return _grouping_id; } 00110 00111 iterator begin() { return _fields.begin(); } 00112 iterator end() { return _fields.end(); } 00113 const_iterator begin() const { return _fields.begin(); } 00114 const_iterator end() const { return _fields.end(); } 00115 00116 protected: 00117 bool _SetID(ID3_FrameID); 00118 bool _ClearFields(); 00119 void _InitFields(); 00120 void _InitFieldBits(); 00121 void _UpdateFieldDeps(); 00122 00123 private: 00124 mutable bool _changed; // frame changed since last parse/render? 00125 Bitset _bitset; // which fields are present? 00126 Fields _fields; 00127 ID3_FrameHeader _hdr; // 00128 uchar _encryption_id; // encryption id 00129 uchar _grouping_id; // grouping id 00130 } 00131 ; 00132 00133 #endif /* _ID3LIB_FRAME_IMPL_H_ */