id3lib  3.8.3
frame_impl.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: frame_impl.h,v 1.6 2002/08/10 10:50:31 t1mpy Exp $
3 
4 // id3lib: a C++ 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_FRAME_IMPL_H_
30 #define _ID3LIB_FRAME_IMPL_H_
31 
32 #include <vector>
33 #ifndef HAVE_BITSET
34 #include "id3/id3lib_bitset"
35 #else
36 #include <bitset>
37 #endif
38 #include "id3/id3lib_frame.h"
39 #include "header_frame.h"
40 
42 {
43  typedef std::bitset<ID3FN_LASTFIELDID> Bitset;
44  typedef std::vector<ID3_Field *> Fields;
45 public:
46  typedef Fields::iterator iterator;
47  typedef Fields::const_iterator const_iterator;
48 public:
51  ID3_FrameImpl(const ID3_Frame&);
52 
54  virtual ~ID3_FrameImpl();
55 
56  void Clear();
57 
58  bool SetID(ID3_FrameID id);
59  ID3_FrameID GetID() const { return _hdr.GetFrameID(); }
60 
61  ID3_Field* GetField(ID3_FieldID name) const;
62 
63  size_t NumFields() const;
64 
65  const char* GetDescription() const;
66  static const char* GetDescription(ID3_FrameID);
67 
68  const char* GetTextID() const { return _hdr.GetTextID(); }
69 
71  bool HasChanged() const;
72  bool Parse(ID3_Reader&);
73  void Render(ID3_Writer&) const;
74  size_t Size();
75  bool Contains(ID3_FieldID fld) const
76  { return _bitset.test(fld); }
77  bool SetSpec(ID3_V2Spec);
78  ID3_V2Spec GetSpec() const;
79 
85  bool SetCompression(bool b) { return _hdr.SetCompression(b); }
94  bool GetCompression() const { return _hdr.GetCompression(); }
95  size_t GetDataSize() const { return _hdr.GetDataSize(); }
96 
98  {
99  bool changed = id != _encryption_id;
100  _encryption_id = id;
101  _changed = _changed || changed;
102  _hdr.SetEncryption(true);
103  return changed;
104  }
105  uchar GetEncryptionID() const { return _encryption_id; }
107  {
108  bool changed = id != _grouping_id;
109  _grouping_id = id;
110  _changed = _changed || changed;
111  _hdr.SetGrouping(true);
112  return changed;
113  }
114  uchar GetGroupingID() const { return _grouping_id; }
115 
116  iterator begin() { return _fields.begin(); }
117  iterator end() { return _fields.end(); }
118  const_iterator begin() const { return _fields.begin(); }
119  const_iterator end() const { return _fields.end(); }
120 
121 protected:
122  bool _SetID(ID3_FrameID);
123  bool _ClearFields();
124  void _InitFields();
127 
128 private:
129  mutable bool _changed; // frame changed since last parse/render?
130  Bitset _bitset; // which fields are present?
131  Fields _fields;
132  ID3_FrameHeader _hdr; //
133  uchar _encryption_id; // encryption id
134  uchar _grouping_id; // grouping id
135 }
136 ;
137 
138 #endif /* _ID3LIB_FRAME_IMPL_H_ */
The representative class of an ID3v2 field.
Definition: field.h:37
ID3_FrameID GetFrameID() const
const char * GetTextID() const
bool SetEncryption(bool b)
Definition: header_frame.h:64
bool SetCompression(bool b)
Definition: header_frame.h:63
bool GetCompression() const
Definition: header_frame.h:67
bool SetGrouping(bool b)
Definition: header_frame.h:65
The representative class of an id3v2 frame.
const_iterator begin() const
Definition: frame_impl.h:118
bool Parse(ID3_Reader &)
size_t GetDataSize() const
Definition: frame_impl.h:95
ID3_FrameID GetID() const
Definition: frame_impl.h:59
bool SetGroupingID(uchar id)
Definition: frame_impl.h:106
bool HasChanged() const
Definition: frame_impl.cpp:207
void _InitFields()
Definition: frame_impl.cpp:97
size_t Size()
Definition: frame_impl.cpp:172
uchar GetGroupingID() const
Definition: frame_impl.h:114
bool GetCompression() const
Returns whether or not the compression flag is set.
Definition: frame_impl.h:94
uchar GetEncryptionID() const
Definition: frame_impl.h:105
ID3_FrameImpl(ID3_FrameID id=ID3FID_NOFRAME)
Definition: frame_impl.cpp:38
bool SetSpec(ID3_V2Spec)
Definition: frame_impl.cpp:140
size_t NumFields() const
Definition: frame_impl.cpp:167
const char * GetTextID() const
Definition: frame_impl.h:68
iterator end()
Definition: frame_impl.h:117
ID3_V2Spec GetSpec() const
Definition: frame_impl.cpp:145
bool SetCompression(bool b)
Sets the compression flag within the frame.
Definition: frame_impl.h:85
Fields::iterator iterator
Definition: frame_impl.h:46
void _UpdateFieldDeps()
void Render(ID3_Writer &) const
void _InitFieldBits()
bool SetEncryptionID(uchar id)
Definition: frame_impl.h:97
bool _SetID(ID3_FrameID)
Definition: frame_impl.cpp:132
ID3_Field * GetField(ID3_FieldID name) const
Definition: frame_impl.cpp:150
const char * GetDescription() const
Definition: frame_impl.cpp:258
bool _ClearFields()
Definition: frame_impl.cpp:75
virtual ~ID3_FrameImpl()
Destructor.
Definition: frame_impl.cpp:70
Fields::const_iterator const_iterator
Definition: frame_impl.h:47
ID3_FrameImpl & operator=(const ID3_Frame &)
Definition: frame_impl.cpp:223
bool Contains(ID3_FieldID fld) const
Definition: frame_impl.h:75
const_iterator end() const
Definition: frame_impl.h:119
iterator begin()
Definition: frame_impl.h:116
bool SetID(ID3_FrameID id)
Definition: frame_impl.cpp:121
size_t GetDataSize() const
Definition: header.h:71
ID3_FieldID
Enumeration of the different types of fields in a frame.
Definition: globals.h:198
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
@ ID3FID_NOFRAME
No known frame.
Definition: globals.h:231