Tag Parser  9.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 
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 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
TagParser::TagField::typeInfo
const TypeInfoType & typeInfo() const
Returns the type info of the current TagField.
Definition: generictagfield.h:176
TagParser::TagFieldTraits
Defines traits for the specified ImplementationType.
Definition: generictagfield.h:16
TagParser::TagField::clear
void clear()
Clears id, value, type info, sets default flag to false and resets further implementation specific va...
Definition: generictagfield.h:226
TagParser::TagField::setTypeInfo
void setTypeInfo(const TypeInfoType &typeInfo)
Sets the type info of the current TagField.
Definition: generictagfield.h:184
tagvalue.h
TagParser::TagField::nestedFields
std::vector< ImplementationType > & nestedFields()
Returns the nested fields.
Definition: generictagfield.h:260
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::TagField::id
const IdentifierType & id() const
Returns the id of the current TagField.
Definition: generictagfield.h:115
TagParser::TagField::supportsNestedFields
bool supportsNestedFields() const
Returns whether nested fields are supported by the implementation.
Definition: generictagfield.h:268
TagParser::TagField::TagField
TagField()
Constructs an empty TagField.
Definition: generictagfield.h:83
TagParser::TagField
The TagField class is used by FieldMapBasedTag to store the fields.
Definition: generictagfield.h:8
TagParser::TagField::value
TagValue & value()
Returns the value of the current TagField.
Definition: generictagfield.h:144
TagParser::TagField::isAdditionalTypeInfoUsed
bool isAdditionalTypeInfoUsed() const
Returns an indication whether the additional type info is used.
Definition: generictagfield.h:242
TagParser::TagField::TagField
TagField(const IdentifierType &id, const TagValue &value)
Constructs a new TagField with the specified id and value.
Definition: generictagfield.h:96
TagParser::TagValue
The TagValue class wraps values of different types. It is meant to be assigned to a tag field.
Definition: tagvalue.h:75
TagParser::TagField::~TagField
~TagField()
Destroys the TagField.
Definition: generictagfield.h:108
TagParser::TagField::isTypeInfoAssigned
bool isTypeInfoAssigned() const
Returns an indication whether a type info is assigned.
Definition: generictagfield.h:202
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagParser::TagField::clearId
void clearId()
Clears the id of the current TagField.
Definition: generictagfield.h:136
TagParser::TagField::nestedFields
const std::vector< ImplementationType > & nestedFields() const
Returns the nested fields.
Definition: generictagfield.h:250
TagParser::TagField::setId
void setId(const IdentifierType &id)
Sets the id of the current Tag Field.
Definition: generictagfield.h:128
TagParser::TagField::setDefault
void setDefault(bool isDefault)
Sets whether the field is labeled as default.
Definition: generictagfield.h:218
TagParser::TagField< Id3v2Frame >::TypeInfoType
typename TagFieldTraits< Id3v2Frame >::TypeInfoType TypeInfoType
Definition: generictagfield.h:35
TagParser::TagField::value
const TagValue & value() const
Returns the value of the current TagField.
Definition: generictagfield.h:152
TagParser::TagField::isDefault
bool isDefault() const
Returns an indication whether the field is labeled as default.
Definition: generictagfield.h:210
TagParser::TagField::idToString
std::string idToString() const
Definition: generictagfield.h:120
TagParser::TagField< Id3v2Frame >::IdentifierType
typename TagFieldTraits< Id3v2Frame >::IdentifierType IdentifierType
Definition: generictagfield.h:34
TagParser::TagField::setValue
void setValue(const TagValue &value)
Sets the value of the current TagField.
Definition: generictagfield.h:160
TagParser::TagField::clearValue
void clearValue()
Clears the value of the current TagField.
Definition: generictagfield.h:168
TagParser::TagField::removeTypeInfo
void removeTypeInfo()
Removes the type info from the current TagField.
Definition: generictagfield.h:193