id3lib  3.8.3
field_impl.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: field_impl.h,v 1.4 2002/06/29 14:43:00 t1mpy Exp $
3 
4 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
5 // Copyright 1999, 2000 Scott Thomas Haug
6 
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or (at your
10 // option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with this library; if not, write to the Free Software Foundation,
19 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 
21 // The id3lib authors encourage improvements and optimisations to be sent to
22 // the id3lib coordinator. Please see the README file for details on where to
23 // send such submissions. See the AUTHORS file for a list of people who have
24 // contributed to id3lib. See the ChangeLog file for a list of changes to
25 // id3lib. These files are distributed with id3lib at
26 // http://download.sourceforge.net/id3lib/
27 
28 #ifndef _ID3LIB_FIELD_IMPL_H_
29 #define _ID3LIB_FIELD_IMPL_H_
30 
31 #include <stdlib.h>
32 #include "field.h"
33 #include "id3/id3lib_strings.h"
34 
35 struct ID3_FieldDef;
36 struct ID3_FrameDef;
37 class ID3_Frame;
38 class ID3_Reader;
39 
40 class ID3_FieldImpl : public ID3_Field
41 {
42  friend class ID3_FrameImpl;
43 public:
45 
46  void Clear();
47 
48  size_t Size() const;
49  size_t BinSize() const;
50  size_t GetNumTextItems() const;
51 
52  // integer field functions
53  ID3_Field& operator= (uint32 val) { this->Set(val); return *this; }
54  void Set(uint32);
55  uint32 Get() const;
56 
57  void SetInteger(uint32);
58  uint32 GetInteger() const;
59 
60  // ASCII string field functions
61  ID3_Field& operator= (const char* s) { this->Set(s); return *this; }
62  size_t Set(const char* data);
63  size_t Get(char*, size_t) const;
64  size_t Get(char*, size_t, size_t) const;
65  const char* GetRawText() const;
66  const char* GetRawTextItem(size_t) const;
67  size_t Add(const char* data);
68 
69  dami::String GetText() const;
70  dami::String GetTextItem(size_t) const;
71  size_t SetText(dami::String);
72  size_t AddText(dami::String);
73 
74  // Unicode string field functions
75  ID3_Field& operator= (const unicode_t* s) { this->Set(s); return *this; }
76  size_t Set(const unicode_t*);
77  size_t Get(unicode_t *buffer, size_t) const;
78  size_t Get(unicode_t *buffer, size_t, size_t) const;
79  size_t Add(const unicode_t*);
80  const unicode_t* GetRawUnicodeText() const;
81  const unicode_t* GetRawUnicodeTextItem(size_t) const;
82 
83  // binary field functions
84  size_t Set(const uchar* buf, size_t size);
85  size_t Set(const char* buf, size_t size)
86  {
87  return this->Set(reinterpret_cast<const uchar *>(buf), size);
88  }
89  size_t Get(uchar*, size_t) const;
90  const uchar* GetRawBinary() const;
91  void FromFile(const char*);
92  void ToFile(const char *sInfo) const;
93 
94  size_t SetBinary(dami::BString);
95  dami::BString GetBinary() const;
96 
97  // miscelaneous functions
98  ID3_Field& operator=( const ID3_Field & );
99  bool InScope(ID3_V2Spec spec) const
100  { return _spec_begin <= spec && spec <= _spec_end; }
101 
102  ID3_FieldID GetID() const { return _id; }
103  ID3_FieldType GetType() const { return _type; }
104  bool SetEncoding(ID3_TextEnc enc);
105  ID3_TextEnc GetEncoding() const { return _enc; }
106  bool IsEncodable() const { return (_flags & ID3FF_ENCODABLE) > 0; }
107 
108 
109  void Render(ID3_Writer&) const;
110  bool Parse(ID3_Reader&);
111  bool HasChanged() const;
112 
113 private:
114  size_t SetText_i(dami::String);
115  size_t AddText_i(dami::String);
116 
117 private:
118  // To prevent public instantiation, the constructor is made private
119  ID3_FieldImpl();
120  ID3_FieldImpl(const ID3_FieldDef&);
121 
122  const ID3_FieldID _id; // the ID of this field
123  const ID3_FieldType _type; // what type is this field or should be
124  const ID3_V2Spec _spec_begin; // spec end
125  const ID3_V2Spec _spec_end; // spec begin
126  const flags_t _flags; // special field flags
127  mutable bool _changed; // field changed since last parse/render?
128 
129  dami::BString _binary; // for binary strings
130  dami::String _text; // for ascii strings
131  uint32 _integer; // for numbers
132 
133  const size_t _fixed_size; // for fixed length fields (0 if not)
134  size_t _num_items; // the number of items in the text string
135  ID3_TextEnc _enc; // encoding for text fields
136 protected:
137  void RenderInteger(ID3_Writer&) const;
138  void RenderText(ID3_Writer&) const;
139  void RenderBinary(ID3_Writer&) const;
140 
141  bool ParseInteger(ID3_Reader&);
142  bool ParseText(ID3_Reader&);
143  bool ParseBinary(ID3_Reader&);
144 
145 };
146 
147 
148 // Ack! Not for public use
150 ID3_FrameID ID3_FindFrameID(const char *id);
151 
152 #endif /* _ID3LIB_FIELD_H_ */
153 
ID3_FieldImpl::GetType
ID3_FieldType GetType() const
Definition: field_impl.h:103
ID3_FieldImpl::RenderInteger
void RenderInteger(ID3_Writer &) const
Definition: field_integer.cpp:105
ID3_FieldImpl::Add
size_t Add(const char *data)
Definition: field_string_ascii.cpp:250
ID3_FieldImpl::ParseInteger
bool ParseInteger(ID3_Reader &)
Definition: field_integer.cpp:87
ID3_FindFrameID
ID3_FrameID ID3_FindFrameID(const char *id)
Definition: field.cpp:1092
uchar
unsigned char uchar
Definition: globals.h:114
unicode_t
uint16 unicode_t
Definition: globals.h:117
ID3_Field
The representative class of an ID3v2 field.
Definition: field.h:37
ID3_FieldType
ID3_FieldType
Enumeration of the types of field types.
Definition: globals.h:352
ID3_FieldImpl::IsEncodable
bool IsEncodable() const
Definition: field_impl.h:106
ID3_FieldImpl::RenderBinary
void RenderBinary(ID3_Writer &) const
Definition: field_binary.cpp:203
ID3_FieldImpl::ToFile
void ToFile(const char *sInfo) const
Copies binary data from the field to the specified file.
Definition: field_binary.cpp:172
ID3_FrameID
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition: globals.h:230
ID3_FieldID
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition: globals.h:198
ID3_FieldImpl::ParseText
bool ParseText(ID3_Reader &)
Definition: field_string_ascii.cpp:327
ID3_FieldImpl::FromFile
void FromFile(const char *)
Copies binary data from the file specified to the field.
Definition: field_binary.cpp:136
ID3_Reader
Definition: reader.h:34
ID3_FieldDef
Definition: field_def.h:34
ID3_FieldImpl::~ID3_FieldImpl
~ID3_FieldImpl()
Definition: field.cpp:914
ID3_FieldImpl::GetEncoding
ID3_TextEnc GetEncoding() const
Definition: field_impl.h:105
ID3_Frame
The representative class of an id3v2 frame.
Definition: id3lib_frame.h:39
ID3_FieldImpl::Size
size_t Size() const
Returns the size of a field.
Definition: field.cpp:1018
ID3_FieldImpl::SetText
size_t SetText(dami::String)
Definition: field_string_ascii.cpp:189
flags_t
uint16 flags_t
Definition: globals.h:118
ID3_V2Spec
ID3_V2Spec
Definition: globals.h:162
ID3_FrameImpl
Definition: frame_impl.h:42
ID3_FieldImpl::Set
void Set(uint32)
Sets the value of the field to the specified integer.
Definition: field_integer.cpp:47
ID3_FieldImpl::Clear
void Clear()
Clears any data and frees any memory associated with the field.
Definition: field.cpp:923
ID3_FrameDef
Definition: frame_def.h:37
ID3_FieldImpl::Render
void Render(ID3_Writer &) const
Definition: field.cpp:1112
ID3_FieldImpl::operator=
ID3_Field & operator=(uint32 val)
A shortcut for the Set method.
Definition: field_impl.h:53
ID3_FieldImpl::GetTextItem
dami::String GetTextItem(size_t) const
Definition: field_string_ascii.cpp:134
ID3_FieldImpl::GetRawBinary
const uchar * GetRawBinary() const
Definition: field_binary.cpp:92
ID3_FieldImpl::GetInteger
uint32 GetInteger() const
Definition: field_integer.cpp:77
ID3_FieldImpl::Get
uint32 Get() const
Returns the value of the integer field.
Definition: field_integer.cpp:72
ID3_FieldImpl
Definition: field_impl.h:41
ID3_FieldImpl::GetRawText
const char * GetRawText() const
Definition: field_string_ascii.cpp:261
field.h
ID3_FieldImpl::GetRawTextItem
const char * GetRawTextItem(size_t) const
Definition: field_string_ascii.cpp:272
ID3_FieldImpl::SetInteger
void SetInteger(uint32)
Definition: field_integer.cpp:52
ID3_FieldImpl::GetRawUnicodeText
const unicode_t * GetRawUnicodeText() const
Definition: field_string_unicode.cpp:111
ID3_FieldImpl::SetEncoding
bool SetEncoding(ID3_TextEnc enc)
Definition: field.cpp:1175
ID3_Writer
Definition: writer.h:34
ID3_FieldImpl::RenderText
void RenderText(ID3_Writer &) const
Definition: field_string_ascii.cpp:376
ID3_FieldImpl::HasChanged
bool HasChanged() const
Definition: field.cpp:968
ID3_FieldImpl::GetRawUnicodeTextItem
const unicode_t * GetRawUnicodeTextItem(size_t) const
Definition: field_string_unicode.cpp:122
ID3_FieldImpl::Parse
bool Parse(ID3_Reader &)
Definition: field.cpp:1043
ID3_TextEnc
ID3_TextEnc
Definition: globals.h:138
ID3_FieldImpl::Set
size_t Set(const char *buf, size_t size)
Definition: field_impl.h:85
ID3_FieldImpl::GetID
ID3_FieldID GetID() const
Definition: field_impl.h:102
ID3_FieldImpl::ParseBinary
bool ParseBinary(ID3_Reader &)
Definition: field_binary.cpp:195
ID3_FieldImpl::InScope
bool InScope(ID3_V2Spec spec) const
Definition: field_impl.h:99
ID3_FieldImpl::GetText
dami::String GetText() const
Definition: field_string_ascii.cpp:124
ID3_FieldImpl::SetBinary
size_t SetBinary(dami::BString)
Copies the supplied unicode string to the field.
Definition: field_binary.cpp:55
ID3_FindFrameDef
ID3_FrameDef * ID3_FindFrameDef(ID3_FrameID id)
Definition: field.cpp:1075
ID3_FieldImpl::GetBinary
dami::BString GetBinary() const
Definition: field_binary.cpp:81
ID3_FieldImpl::BinSize
size_t BinSize() const
Definition: field.cpp:992
ID3_FieldImpl::GetNumTextItems
size_t GetNumTextItems() const
Returns the number of items in a text list.
Definition: field_string_ascii.cpp:399
ID3FF_ENCODABLE
@ ID3FF_ENCODABLE
Definition: globals.h:346
ID3_FieldImpl::AddText
size_t AddText(dami::String)
Definition: field_string_ascii.cpp:240

Generated for id3lib by doxygen 1.8.18