Tag Parser  10.0.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 
38  TagField(const IdentifierType &id, const TagValue &value);
40 
41  const IdentifierType &id() const;
42  std::string idToString() const;
43  void setId(const IdentifierType &id);
44  void clearId();
45 
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);
54  bool isTypeInfoAssigned() const;
55 
56  bool isDefault() const;
57  void setDefault(bool isDefault);
58 
59  void clear();
60 
62 
63  const std::vector<ImplementationType> &nestedFields() const;
64  std::vector<ImplementationType> &nestedFields();
65  bool supportsNestedFields() const;
66 
67 protected:
70 
71 private:
72  IdentifierType m_id;
73  TagValue m_value;
74  TypeInfoType m_typeInfo;
75  bool m_typeInfoAssigned;
76  bool m_default;
77  std::vector<ImplementationType> m_nestedFields;
78 };
79 
83 template <class ImplementationType>
85  : m_id(IdentifierType())
86  , m_value(TagValue())
87  , m_typeInfo(TypeInfoType())
88  , m_typeInfoAssigned(false)
89  , m_default(false)
90 {
91 }
92 
96 template <class ImplementationType>
98  : m_id(id)
99  , m_value(value)
100  , m_typeInfo(TypeInfoType())
101  , m_typeInfoAssigned(false)
102  , m_default(false)
103 {
104 }
105 
109 template <class ImplementationType> TagField<ImplementationType>::~TagField()
110 {
111 }
112 
116 template <class ImplementationType> inline const typename TagField<ImplementationType>::IdentifierType &TagField<ImplementationType>::id() const
117 {
118  return m_id;
119 }
120 
121 template <class ImplementationType> inline std::string TagField<ImplementationType>::idToString() const
122 {
123  return ImplementationType::fieldIdToString(m_id);
124 }
125 
129 template <class ImplementationType> inline void TagField<ImplementationType>::setId(const IdentifierType &id)
130 {
131  m_id = id;
132 }
133 
137 template <class ImplementationType> inline void TagField<ImplementationType>::clearId()
138 {
139  m_id = IdentifierType();
140 }
141 
145 template <class ImplementationType> inline TagValue &TagField<ImplementationType>::value()
146 {
147  return m_value;
148 }
149 
153 template <class ImplementationType> inline const TagValue &TagField<ImplementationType>::value() const
154 {
155  return m_value;
156 }
157 
161 template <class ImplementationType> inline void TagField<ImplementationType>::setValue(const TagValue &value)
162 {
163  m_value = value;
164 }
165 
169 template <class ImplementationType> inline void TagField<ImplementationType>::clearValue()
170 {
171  static_cast<ImplementationType *>(this)->internallyClearValue();
172 }
173 
177 template <class ImplementationType> inline const typename TagField<ImplementationType>::TypeInfoType &TagField<ImplementationType>::typeInfo() const
178 {
179  return m_typeInfo;
180 }
181 
185 template <class ImplementationType> inline void TagField<ImplementationType>::setTypeInfo(const TypeInfoType &typeInfo)
186 {
187  m_typeInfo = typeInfo;
188  m_typeInfoAssigned = true;
189 }
190 
194 template <class ImplementationType> inline void TagField<ImplementationType>::removeTypeInfo()
195 {
196  m_typeInfo = TypeInfoType();
197  m_typeInfoAssigned = false;
198 }
199 
203 template <class ImplementationType> inline bool TagField<ImplementationType>::isTypeInfoAssigned() const
204 {
205  return m_typeInfoAssigned;
206 }
207 
211 template <class ImplementationType> inline bool TagField<ImplementationType>::isDefault() const
212 {
213  return m_default;
214 }
215 
219 template <class ImplementationType> inline void TagField<ImplementationType>::setDefault(bool isDefault)
220 {
221  m_default = isDefault;
222 }
223 
227 template <class ImplementationType> void TagField<ImplementationType>::clear()
228 {
229  clearId();
230  clearValue();
231  static_cast<ImplementationType *>(this)->internallyClearFurtherData();
232  m_typeInfo = TypeInfoType();
233  m_typeInfoAssigned = false;
234  m_default = true;
235 }
236 
243 template <class ImplementationType> inline bool TagField<ImplementationType>::isAdditionalTypeInfoUsed() const
244 {
245  return static_cast<ImplementationType *>(this)->isAdditionalTypeInfoUsed();
246 }
247 
251 template <class ImplementationType> const std::vector<ImplementationType> &TagField<ImplementationType>::nestedFields() const
252 {
253  return m_nestedFields;
254 }
255 
261 template <class ImplementationType> inline std::vector<ImplementationType> &TagField<ImplementationType>::nestedFields()
262 {
263  return m_nestedFields;
264 }
265 
269 template <class ImplementationType> inline bool TagField<ImplementationType>::supportsNestedFields() const
270 {
271  return static_cast<ImplementationType *>(this)->supportsNestedFields();
272 }
273 
278 template <class ImplementationType> void TagField<ImplementationType>::internallyClearValue()
279 {
280  m_value.clearDataAndMetadata();
281 }
282 
287 template <class ImplementationType> void TagField<ImplementationType>::internallyClearFurtherData()
288 {
289 }
290 
291 } // namespace TagParser
292 
293 #endif // TAG_PARSER_TAGFIELD_H
Defines traits for the specified ImplementationType.
The TagField class is used by FieldMapBasedTag to store the fields.
void clearId()
Clears the id of the current TagField.
TagField()
Constructs an empty TagField.
~TagField()
Destroys the TagField.
void internallyClearValue()
Clears the assigned value; called via clearValue() and clear().
bool supportsNestedFields() const
Returns whether nested fields are supported by the implementation.
std::vector< ImplementationType > & nestedFields()
Returns the nested fields.
void setTypeInfo(const TypeInfoType &typeInfo)
Sets the type info of the current TagField.
const TagValue & value() const
Returns the value of the current TagField.
typename TagFieldTraits< ImplementationType >::IdentifierType IdentifierType
const TypeInfoType & typeInfo() const
Returns the type info of the current TagField.
void clear()
Clears id, value, type info, sets default flag to false and resets further implementation specific va...
void setDefault(bool isDefault)
Sets whether the field is labeled as default.
const IdentifierType & id() const
Returns the id of the current TagField.
bool isTypeInfoAssigned() const
Returns an indication whether a type info is assigned.
void internallyClearFurtherData()
Clears further data; called via clear().
const std::vector< ImplementationType > & nestedFields() const
Returns the nested fields.
void setValue(const TagValue &value)
Sets the value of the current TagField.
void removeTypeInfo()
Removes the type info from the current TagField.
void setId(const IdentifierType &id)
Sets the id of the current Tag Field.
bool isDefault() const
Returns an indication whether the field is labeled as default.
std::string idToString() const
bool isAdditionalTypeInfoUsed() const
Returns an indication whether the additional type info is used.
typename TagFieldTraits< ImplementationType >::TypeInfoType TypeInfoType
TagField(const IdentifierType &id, const TagValue &value)
Constructs a new TagField with the specified id and value.
void clearValue()
Clears the value of the current TagField.
TagValue & value()
Returns the value of the current TagField.
The TagValue class wraps values of different types.
Definition: tagvalue.h:95
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10