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
35struct ID3_FieldDef;
36struct ID3_FrameDef;
37class ID3_Frame;
38class ID3_Reader;
39
41{
42 friend class ID3_FrameImpl;
43public:
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
113private:
114 size_t SetText_i(dami::String);
115 size_t AddText_i(dami::String);
116
117private:
118 // To prevent public instantiation, the constructor is made private
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
136protected:
137 void RenderInteger(ID3_Writer&) const;
138 void RenderText(ID3_Writer&) const;
139 void RenderBinary(ID3_Writer&) const;
140
142 bool ParseText(ID3_Reader&);
143 bool ParseBinary(ID3_Reader&);
144
145};
146
147
148// Ack! Not for public use
150ID3_FrameID ID3_FindFrameID(const char *id);
151
152#endif /* _ID3LIB_FIELD_H_ */
153
The representative class of an ID3v2 field.
Definition field.h:37
dami::String GetText() const
size_t Add(const char *data)
bool HasChanged() const
Definition field.cpp:968
bool ParseInteger(ID3_Reader &)
bool IsEncodable() const
Definition field_impl.h:106
const unicode_t * GetRawUnicodeTextItem(size_t) const
const char * GetRawTextItem(size_t) const
size_t SetText(dami::String)
void RenderInteger(ID3_Writer &) const
const unicode_t * GetRawUnicodeText() const
void RenderText(ID3_Writer &) const
uint32 GetInteger() const
void SetInteger(uint32)
const char * GetRawText() const
size_t GetNumTextItems() const
Returns the number of items in a text list.
void ToFile(const char *sInfo) const
Copies binary data from the field to the specified file.
dami::String GetTextItem(size_t) const
size_t AddText(dami::String)
ID3_FieldType GetType() const
Definition field_impl.h:103
bool ParseBinary(ID3_Reader &)
void Set(uint32)
Sets the value of the field to the specified integer.
void Clear()
Clears any data and frees any memory associated with the field.
Definition field.cpp:923
size_t Set(const char *buf, size_t size)
Definition field_impl.h:85
ID3_TextEnc GetEncoding() const
Definition field_impl.h:105
uint32 Get() const
Returns the value of the integer field.
ID3_Field & operator=(uint32 val)
A shortcut for the Set method.
Definition field_impl.h:53
ID3_FieldID GetID() const
Definition field_impl.h:102
const uchar * GetRawBinary() const
void Render(ID3_Writer &) const
Definition field.cpp:1112
bool ParseText(ID3_Reader &)
bool Parse(ID3_Reader &)
Definition field.cpp:1043
size_t Size() const
Returns the size of a field.
Definition field.cpp:1018
void RenderBinary(ID3_Writer &) const
bool InScope(ID3_V2Spec spec) const
Definition field_impl.h:99
bool SetEncoding(ID3_TextEnc enc)
Definition field.cpp:1175
size_t SetBinary(dami::BString)
Copies the supplied unicode string to the field.
dami::BString GetBinary() const
size_t BinSize() const
Definition field.cpp:992
void FromFile(const char *)
Copies binary data from the file specified to the field.
The representative class of an id3v2 frame.
ID3_FrameDef * ID3_FindFrameDef(ID3_FrameID id)
Definition field.cpp:1075
ID3_FrameID ID3_FindFrameID(const char *id)
Definition field.cpp:1092
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition globals.h:198
ID3_TextEnc
Enumeration of the types of text encodings: ascii or unicode.
Definition globals.h:138
ID3_V2Spec
Definition globals.h:162
unsigned char uchar
Definition globals.h:114
uint16 unicode_t
Definition globals.h:117
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition globals.h:230
@ ID3FF_ENCODABLE
Definition globals.h:346
uint16 flags_t
Definition globals.h:118
ID3_FieldType
Enumeration of the types of field types.
Definition globals.h:352

Generated for id3lib by doxygen 1.10.0