Tag Parser  8.2.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
generictagfield.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_TAGFIELD_H
2 #define TAG_PARSER_TAGFIELD_H
3 
4 #include "./tagvalue.h"
5 
6 namespace TagParser {
7 
8 template <class implementationType> class TagField;
9 
16 template <typename ImplementationType> class TagFieldTraits {
17 };
18 
30 template <class ImplementationType> class TAG_PARSER_EXPORT TagField {
31  friend class TagFieldTraits<ImplementationType>;
32 
33 public:
36 
37  TagField();
38  TagField(const IdentifierType &id, const TagValue &value);
39  ~TagField();
40 
41  const IdentifierType &id() const;
42  std::string idToString() const;
43  void setId(const IdentifierType &id);
44  void clearId();
45 
46  TagValue &value();
47  const TagValue &value() const;
48  void setValue(const TagValue &value);
49  void clearValue();
50 
51  const TypeInfoType &typeInfo() const;
52  void setTypeInfo(const TypeInfoType &typeInfo);
53  void removeTypeInfo();
54  bool isTypeInfoAssigned() const;
55 
56  bool isDefault() const;
57  void setDefault(bool isDefault);
58 
59  void clear();
60 
61  bool isAdditionalTypeInfoUsed() const;
62 
63  const std::vector<ImplementationType> &nestedFields() const;
64  std::vector<ImplementationType> &nestedFields();
65  bool supportsNestedFields() const;
66 
67 private:
68  void cleared();
69 
70 private:
71  IdentifierType m_id;
72  TagValue m_value;
73  TypeInfoType m_typeInfo;
74  bool m_typeInfoAssigned;
75  bool m_default;
76  std::vector<ImplementationType> m_nestedFields;
77 };
78 
82 template <class ImplementationType>
84  : m_id(IdentifierType())
85  , m_value(TagValue())
86  , m_typeInfo(TypeInfoType())
87  , m_typeInfoAssigned(false)
88  , m_default(false)
89 {
90 }
91 
95 template <class ImplementationType>
97  : m_id(id)
98  , m_value(value)
99  , m_typeInfo(TypeInfoType())
100  , m_typeInfoAssigned(false)
101  , m_default(false)
102 {
103 }
104 
108 template <class ImplementationType> TagField<ImplementationType>::~TagField()
109 {
110 }
111 
115 template <class ImplementationType> inline const typename TagField<ImplementationType>::IdentifierType &TagField<ImplementationType>::id() const
116 {
117  return m_id;
118 }
119 
120 template <class ImplementationType> inline std::string TagField<ImplementationType>::idToString() const
121 {
122  return ImplementationType::fieldIdToString(m_id);
123 }
124 
128 template <class ImplementationType> inline void TagField<ImplementationType>::setId(const IdentifierType &id)
129 {
130  m_id = id;
131 }
132 
136 template <class ImplementationType> inline void TagField<ImplementationType>::clearId()
137 {
138  m_id = IdentifierType();
139 }
140 
144 template <class ImplementationType> inline TagValue &TagField<ImplementationType>::value()
145 {
146  return m_value;
147 }
148 
152 template <class ImplementationType> inline const TagValue &TagField<ImplementationType>::value() const
153 {
154  return m_value;
155 }
156 
160 template <class ImplementationType> inline void TagField<ImplementationType>::setValue(const TagValue &value)
161 {
162  m_value = value;
163 }
164 
168 template <class ImplementationType> inline void TagField<ImplementationType>::clearValue()
169 {
170  m_value.clearDataAndMetadata();
171 }
172 
176 template <class ImplementationType> inline const typename TagField<ImplementationType>::TypeInfoType &TagField<ImplementationType>::typeInfo() const
177 {
178  return m_typeInfo;
179 }
180 
184 template <class ImplementationType> inline void TagField<ImplementationType>::setTypeInfo(const TypeInfoType &typeInfo)
185 {
186  m_typeInfo = typeInfo;
187  m_typeInfoAssigned = true;
188 }
189 
193 template <class ImplementationType> inline void TagField<ImplementationType>::removeTypeInfo()
194 {
195  m_typeInfo = TypeInfoType();
196  m_typeInfoAssigned = false;
197 }
198 
202 template <class ImplementationType> inline bool TagField<ImplementationType>::isTypeInfoAssigned() const
203 {
204  return m_typeInfoAssigned;
205 }
206 
210 template <class ImplementationType> inline bool TagField<ImplementationType>::isDefault() const
211 {
212  return m_default;
213 }
214 
218 template <class ImplementationType> inline void TagField<ImplementationType>::setDefault(bool isDefault)
219 {
220  m_default = isDefault;
221 }
222 
226 template <class ImplementationType> void TagField<ImplementationType>::clear()
227 {
228  clearId();
229  clearValue();
230  m_typeInfo = TypeInfoType();
231  m_typeInfoAssigned = false;
232  m_default = true;
233  static_cast<ImplementationType *>(this)->reset();
234 }
235 
242 template <class ImplementationType> inline bool TagField<ImplementationType>::isAdditionalTypeInfoUsed() const
243 {
244  return static_cast<ImplementationType *>(this)->isAdditionalTypeInfoUsed();
245 }
246 
250 template <class ImplementationType> const std::vector<ImplementationType> &TagField<ImplementationType>::nestedFields() const
251 {
252  return m_nestedFields;
253 }
254 
260 template <class ImplementationType> inline std::vector<ImplementationType> &TagField<ImplementationType>::nestedFields()
261 {
262  return m_nestedFields;
263 }
264 
268 template <class ImplementationType> inline bool TagField<ImplementationType>::supportsNestedFields() const
269 {
270  return static_cast<ImplementationType *>(this)->supportsNestedFields();
271 }
272 
276 template <class ImplementationType> inline void TagField<ImplementationType>::cleared()
277 {
278 }
279 
280 } // namespace TagParser
281 
282 #endif // TAG_PARSER_TAGFIELD_H
Defines traits for the specified ImplementationType.
bool supportsNestedFields() const
Returns whether nested fields are supported by the implementation.
The TagField class is used by FieldMapBasedTag to store the fields.
typename TagFieldTraits< Id3v2Frame >::IdentifierType IdentifierType
typename TagFieldTraits< Id3v2Frame >::TypeInfoType TypeInfoType
The TagValue class wraps values of different types.
Definition: tagvalue.h:65
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagField()
Constructs an empty TagField.
bool isAdditionalTypeInfoUsed() const
Returns an indication whether the additional type info is used.