id3lib
3.8.3
|
00001 // -*- C++ -*- 00002 // $Id: field_impl.h,v 1.4 2002/06/29 14:43:00 t1mpy 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_FIELD_IMPL_H_ 00029 #define _ID3LIB_FIELD_IMPL_H_ 00030 00031 #include <stdlib.h> 00032 #include "field.h" 00033 #include "id3/id3lib_strings.h" 00034 00035 struct ID3_FieldDef; 00036 struct ID3_FrameDef; 00037 class ID3_Frame; 00038 class ID3_Reader; 00039 00040 class ID3_FieldImpl : public ID3_Field 00041 { 00042 friend class ID3_FrameImpl; 00043 public: 00044 ~ID3_FieldImpl(); 00045 00046 void Clear(); 00047 00048 size_t Size() const; 00049 size_t BinSize() const; 00050 size_t GetNumTextItems() const; 00051 00052 // integer field functions 00053 ID3_Field& operator= (uint32 val) { this->Set(val); return *this; } 00054 void Set(uint32); 00055 uint32 Get() const; 00056 00057 void SetInteger(uint32); 00058 uint32 GetInteger() const; 00059 00060 // ASCII string field functions 00061 ID3_Field& operator= (const char* s) { this->Set(s); return *this; } 00062 size_t Set(const char* data); 00063 size_t Get(char*, size_t) const; 00064 size_t Get(char*, size_t, size_t) const; 00065 const char* GetRawText() const; 00066 const char* GetRawTextItem(size_t) const; 00067 size_t Add(const char* data); 00068 00069 dami::String GetText() const; 00070 dami::String GetTextItem(size_t) const; 00071 size_t SetText(dami::String); 00072 size_t AddText(dami::String); 00073 00074 // Unicode string field functions 00075 ID3_Field& operator= (const unicode_t* s) { this->Set(s); return *this; } 00076 size_t Set(const unicode_t*); 00077 size_t Get(unicode_t *buffer, size_t) const; 00078 size_t Get(unicode_t *buffer, size_t, size_t) const; 00079 size_t Add(const unicode_t*); 00080 const unicode_t* GetRawUnicodeText() const; 00081 const unicode_t* GetRawUnicodeTextItem(size_t) const; 00082 00083 // binary field functions 00084 size_t Set(const uchar* buf, size_t size); 00085 size_t Set(const char* buf, size_t size) 00086 { 00087 return this->Set(reinterpret_cast<const uchar *>(buf), size); 00088 } 00089 size_t Get(uchar*, size_t) const; 00090 const uchar* GetRawBinary() const; 00091 void FromFile(const char*); 00092 void ToFile(const char *sInfo) const; 00093 00094 size_t SetBinary(dami::BString); 00095 dami::BString GetBinary() const; 00096 00097 // miscelaneous functions 00098 ID3_Field& operator=( const ID3_Field & ); 00099 bool InScope(ID3_V2Spec spec) const 00100 { return _spec_begin <= spec && spec <= _spec_end; } 00101 00102 ID3_FieldID GetID() const { return _id; } 00103 ID3_FieldType GetType() const { return _type; } 00104 bool SetEncoding(ID3_TextEnc enc); 00105 ID3_TextEnc GetEncoding() const { return _enc; } 00106 bool IsEncodable() const { return (_flags & ID3FF_ENCODABLE) > 0; } 00107 00108 00109 void Render(ID3_Writer&) const; 00110 bool Parse(ID3_Reader&); 00111 bool HasChanged() const; 00112 00113 private: 00114 size_t SetText_i(dami::String); 00115 size_t AddText_i(dami::String); 00116 00117 private: 00118 // To prevent public instantiation, the constructor is made private 00119 ID3_FieldImpl(); 00120 ID3_FieldImpl(const ID3_FieldDef&); 00121 00122 const ID3_FieldID _id; // the ID of this field 00123 const ID3_FieldType _type; // what type is this field or should be 00124 const ID3_V2Spec _spec_begin; // spec end 00125 const ID3_V2Spec _spec_end; // spec begin 00126 const flags_t _flags; // special field flags 00127 mutable bool _changed; // field changed since last parse/render? 00128 00129 dami::BString _binary; // for binary strings 00130 dami::String _text; // for ascii strings 00131 uint32 _integer; // for numbers 00132 00133 const size_t _fixed_size; // for fixed length fields (0 if not) 00134 size_t _num_items; // the number of items in the text string 00135 ID3_TextEnc _enc; // encoding for text fields 00136 protected: 00137 void RenderInteger(ID3_Writer&) const; 00138 void RenderText(ID3_Writer&) const; 00139 void RenderBinary(ID3_Writer&) const; 00140 00141 bool ParseInteger(ID3_Reader&); 00142 bool ParseText(ID3_Reader&); 00143 bool ParseBinary(ID3_Reader&); 00144 00145 }; 00146 00147 00148 // Ack! Not for public use 00149 ID3_FrameDef *ID3_FindFrameDef(ID3_FrameID id); 00150 ID3_FrameID ID3_FindFrameID(const char *id); 00151 00152 #endif /* _ID3LIB_FIELD_H_ */ 00153