id3lib 3.8.3
tag_impl.h
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: tag_impl.h,v 1.10 2002/11/02 17:35:56 t1mpy Exp $
3
4// id3lib: a software library for creating and manipulating id3v1/v2 tags
5// Copyright 1999, 2000 Scott Thomas Haug
6// Copyright 2002 Thijmen Klok (thijmen@id3lib.org)
7
8// This library is free software; you can redistribute it and/or modify it
9// under the terms of the GNU Library General Public License as published by
10// the Free Software Foundation; either version 2 of the License, or (at your
11// option) any later version.
12//
13// This library is distributed in the hope that it will be useful, but WITHOUT
14// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16// License for more details.
17//
18// You should have received a copy of the GNU Library General Public License
19// along with this library; if not, write to the Free Software Foundation,
20// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22// The id3lib authors encourage improvements and optimisations to be sent to
23// the id3lib coordinator. Please see the README file for details on where to
24// send such submissions. See the AUTHORS file for a list of people who have
25// contributed to id3lib. See the ChangeLog file for a list of changes to
26// id3lib. These files are distributed with id3lib at
27// http://download.sourceforge.net/id3lib/
28
29#ifndef _ID3LIB_TAG_IMPL_H_
30#define _ID3LIB_TAG_IMPL_H_
31
32#include <list>
33#include <stdio.h>
34#include "tag.h" // has frame.h, field.h
35#include "header_tag.h"
36#include "mp3_header.h" //has io_decorators.h
37
38class ID3_Reader;
39class ID3_Writer;
40
41namespace dami
42{
43 namespace id3
44 {
45 namespace v1
46 {
48 void render(ID3_Writer&, const ID3_TagImpl&);
49 };
50 namespace v2
51 {
52 bool parse(ID3_TagImpl& tag, ID3_Reader& rdr);
53 void render(ID3_Writer& writer, const ID3_TagImpl& tag);
54 };
55 };
56 namespace lyr3
57 {
58 namespace v1
59 {
61 };
62 namespace v2
63 {
65 };
66 };
67 namespace mm
68 {
70 };
71};
72
74{
75 typedef std::list<ID3_Frame *> Frames;
76public:
77 typedef Frames::iterator iterator;
78 typedef Frames::const_iterator const_iterator;
79public:
80 ID3_TagImpl(const char *name = NULL);
81 ID3_TagImpl(const ID3_Tag &tag);
82 virtual ~ID3_TagImpl();
83
84 void Clear();
85 bool HasChanged() const;
86 void SetChanged(bool b) { _changed = b; }
87 size_t Size() const;
88
89 bool SetUnsync(bool);
90 bool SetExtended(bool);
91 bool SetExperimental(bool);
92 bool SetPadding(bool);
93
94 bool GetUnsync() const;
95 bool GetExtended() const;
96 bool GetExperimental() const;
97 bool GetFooter() const;
98
99 size_t GetExtendedBytes() const;
100
101 void AddFrame(const ID3_Frame&);
102 void AddFrame(const ID3_Frame*);
103 bool AttachFrame(ID3_Frame*);
105
106 size_t Link(const char *fileInfo, flags_t = (flags_t) ID3TT_ALL);
107 size_t Link(ID3_Reader &reader, flags_t = (flags_t) ID3TT_ALL);
110
111 size_t GetPrependedBytes() const { return _prepended_bytes; }
112 size_t GetAppendedBytes() const { return _appended_bytes; }
113 size_t GetFileSize() const { return _file_size; }
114 dami::String GetFileName() const { return _file_name; }
115
116 ID3_Frame* Find(ID3_FrameID id) const;
117 ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, uint32 data) const;
118 ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, dami::String) const;
119 ID3_Frame* Find(ID3_FrameID id, ID3_FieldID fld, dami::WString) const;
120
121 size_t NumFrames() const { return _frames.size(); }
122 ID3_TagImpl& operator=( const ID3_Tag & );
123
124 bool HasTagType(ID3_TagType tt) const { return _file_tags.test(tt); }
125 ID3_V2Spec GetSpec() const;
126 bool SetSpec(ID3_V2Spec);
127
128 static size_t IsV2Tag(ID3_Reader&);
129
130 const Mp3_Headerinfo* GetMp3HeaderInfo() const { if (_mp3_info) return _mp3_info->GetMp3HeaderInfo(); else return NULL; }
131
132 iterator begin() { return _frames.begin(); }
133 iterator end() { return _frames.end(); }
134 const_iterator begin() const { return _frames.begin(); }
135 const_iterator end() const { return _frames.end(); }
136
137 /* Deprecated! */
138 void AddNewFrame(ID3_Frame* f) { this->AttachFrame(f); }
139 size_t Link(const char *fileInfo, bool parseID3v1, bool parseLyrics3);
140 void SetCompression(bool) { ; }
141 void AddFrames(const ID3_Frame *, size_t);
142 bool HasLyrics() const { return this->HasTagType(ID3TT_LYRICS); }
143 bool HasV2Tag() const { return this->HasTagType(ID3TT_ID3V2); }
144 bool HasV1Tag() const { return this->HasTagType(ID3TT_ID3V1); }
145 size_t PaddingSize(size_t) const;
146
147protected:
148 const_iterator Find(const ID3_Frame *) const;
149 iterator Find(const ID3_Frame *);
150
151 void RenderExtHeader(uchar *);
152
153 void ParseFile();
154 void ParseReader(ID3_Reader &reader);
155
156private:
157 ID3_TagHeader _hdr; // information relevant to the tag header
158 bool _is_padded; // add padding to tags?
159
160 Frames _frames;
161
162 mutable const_iterator _cursor; // which frame in list are we at
163 mutable bool _changed; // has tag changed since last parse or render?
164
165 // file-related member variables
166 dami::String _file_name; // name of the file we are linked to
167 size_t _file_size; // the size of the file (without any tag(s))
168 size_t _prepended_bytes; // number of tag bytes at start of file
169 size_t _appended_bytes; // number of tag bytes at end of file
170 bool _is_file_writable;// is the associated file (via Link) writable?
171 ID3_Flags _tags_to_parse; // which tag types should attempt to be parsed
172 ID3_Flags _file_tags; // which tag types does the file contain
173 Mp3Info *_mp3_info; // class used to retrieve _mp3_header
174};
175
176size_t ID3_GetDataSize(const ID3_TagImpl&);
177
178#endif /* _ID3LIB_TAG_IMPL_H_ */
179
The representative class of an id3v2 frame.
The representative class of an id3 tag.
Definition tag.h:42
void SetChanged(bool b)
Definition tag_impl.h:86
flags_t Strip(flags_t=(flags_t) ID3TT_ALL)
Definition tag_file.cpp:371
size_t GetFileSize() const
Definition tag_impl.h:113
size_t GetAppendedBytes() const
Definition tag_impl.h:112
bool HasTagType(ID3_TagType tt) const
Definition tag_impl.h:124
dami::String GetFileName() const
Definition tag_impl.h:114
bool SetSpec(ID3_V2Spec)
Definition tag_impl.cpp:225
bool SetExperimental(bool)
Definition tag_impl.cpp:251
ID3_Frame * Find(ID3_FrameID id, ID3_FieldID fld, dami::String) const
ID3_Frame * Find(ID3_FrameID id) const
Definition tag_find.cpp:61
ID3_Frame * Find(ID3_FrameID id, ID3_FieldID fld, dami::WString) const
size_t GetExtendedBytes() const
Definition tag_impl.cpp:278
ID3_TagImpl(const char *name=NULL)
Definition tag_impl.cpp:91
void AddFrame(const ID3_Frame &)
Definition tag_impl.cpp:153
size_t PaddingSize(size_t) const
void ParseReader(ID3_Reader &reader)
const_iterator end() const
Definition tag_impl.h:135
const Mp3_Headerinfo * GetMp3HeaderInfo() const
Definition tag_impl.h:130
bool GetExperimental() const
Definition tag_impl.cpp:268
size_t NumFrames() const
Definition tag_impl.h:121
bool GetUnsync() const
Definition tag_impl.cpp:258
Frames::iterator iterator
Definition tag_impl.h:77
size_t GetPrependedBytes() const
Definition tag_impl.h:111
const_iterator begin() const
Definition tag_impl.h:134
bool SetExtended(bool)
Definition tag_impl.cpp:244
bool SetPadding(bool)
Definition tag_impl.cpp:291
void AddFrames(const ID3_Frame *, size_t)
flags_t Update(flags_t=(flags_t) ID3TT_ALL)
Definition tag_file.cpp:323
void AddNewFrame(ID3_Frame *f)
Definition tag_impl.h:138
size_t Link(const char *fileInfo, flags_t=(flags_t) ID3TT_ALL)
Definition tag_file.cpp:131
virtual ~ID3_TagImpl()
Definition tag_impl.cpp:121
bool GetExtended() const
Definition tag_impl.cpp:263
iterator begin()
Definition tag_impl.h:132
ID3_TagImpl & operator=(const ID3_Tag &)
Definition tag_impl.cpp:305
Frames::const_iterator const_iterator
Definition tag_impl.h:78
ID3_Frame * RemoveFrame(const ID3_Frame *)
Definition tag_impl.cpp:185
void RenderExtHeader(uchar *)
bool HasV1Tag() const
Definition tag_impl.h:144
bool SetUnsync(bool)
Definition tag_impl.cpp:237
bool GetFooter() const
Definition tag_impl.cpp:273
void ParseFile()
ID3_V2Spec GetSpec() const
Definition tag_impl.cpp:232
static size_t IsV2Tag(ID3_Reader &)
Definition tag_impl.cpp:38
size_t Size() const
bool AttachFrame(ID3_Frame *)
Definition tag_impl.cpp:167
bool HasChanged() const
Definition tag_impl.cpp:202
void SetCompression(bool)
Definition tag_impl.h:140
bool HasV2Tag() const
Definition tag_impl.h:143
void Clear()
Definition tag_impl.cpp:126
iterator end()
Definition tag_impl.h:133
bool HasLyrics() const
Definition tag_impl.h:142
#define NULL
Definition globals.h:743
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition globals.h:198
ID3_TagType
The various types of tags that id3lib can handle.
Definition globals.h:175
@ ID3TT_ID3V2
Represents an id3v2 tag.
Definition globals.h:178
@ ID3TT_LYRICS
Definition globals.h:183
@ ID3TT_ID3V1
Represents an id3v1 or id3v1.1 tag.
Definition globals.h:177
@ ID3TT_ALL
Represents all possible types of tags.
Definition globals.h:187
ID3_V2Spec
Definition globals.h:162
unsigned char uchar
Definition globals.h:114
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition globals.h:230
uint16 flags_t
Definition globals.h:118
bool parse(ID3_TagImpl &, ID3_Reader &)
void render(ID3_Writer &, const ID3_TagImpl &)
void render(ID3_Writer &writer, const ID3_TagImpl &tag)
bool parse(ID3_TagImpl &tag, ID3_Reader &rdr)
bool parse(ID3_TagImpl &, ID3_Reader &)
bool parse(ID3_TagImpl &, ID3_Reader &)
bool parse(ID3_TagImpl &, ID3_Reader &)
size_t ID3_GetDataSize(const ID3_TagImpl &)
Definition tag_impl.cpp:323