Improve customization point for clearing tag field

* Allow customizing clearing only the value
* Use same naming scheme as in other places
* Avoid having to add an empty reset() function in subclasses
This commit is contained in:
Martchus 2021-01-30 18:25:46 +01:00
parent cbd7e75972
commit 65d52b2d57
7 changed files with 51 additions and 29 deletions

View File

@ -64,6 +64,10 @@ public:
std::vector<ImplementationType> &nestedFields(); std::vector<ImplementationType> &nestedFields();
bool supportsNestedFields() const; bool supportsNestedFields() const;
protected:
void internallyClearValue();
void internallyClearFurtherData();
private: private:
IdentifierType m_id; IdentifierType m_id;
TagValue m_value; TagValue m_value;
@ -164,7 +168,7 @@ template <class ImplementationType> inline void TagField<ImplementationType>::se
*/ */
template <class ImplementationType> inline void TagField<ImplementationType>::clearValue() template <class ImplementationType> inline void TagField<ImplementationType>::clearValue()
{ {
m_value.clearDataAndMetadata(); static_cast<ImplementationType *>(this)->internallyClearValue();
} }
/*! /*!
@ -224,10 +228,10 @@ template <class ImplementationType> void TagField<ImplementationType>::clear()
{ {
clearId(); clearId();
clearValue(); clearValue();
static_cast<ImplementationType *>(this)->internallyClearFurtherData();
m_typeInfo = TypeInfoType(); m_typeInfo = TypeInfoType();
m_typeInfoAssigned = false; m_typeInfoAssigned = false;
m_default = true; m_default = true;
static_cast<ImplementationType *>(this)->reset();
} }
/*! /*!
@ -267,6 +271,23 @@ template <class ImplementationType> inline bool TagField<ImplementationType>::su
return static_cast<ImplementationType *>(this)->supportsNestedFields(); return static_cast<ImplementationType *>(this)->supportsNestedFields();
} }
/*!
* \brief Clears the assigned value; called via clearValue() and clear().
* \remarks Shadow when subclassing to customize clearning a value.
*/
template <class ImplementationType> void TagField<ImplementationType>::internallyClearValue()
{
m_value.clearDataAndMetadata();
}
/*!
* \brief Clears further data; called via clear().
* \remarks Shadow when subclassing to clear further data the subclass has.
*/
template <class ImplementationType> void TagField<ImplementationType>::internallyClearFurtherData()
{
}
} // namespace TagParser } // namespace TagParser
#endif // TAG_PARSER_TAGFIELD_H #endif // TAG_PARSER_TAGFIELD_H

View File

@ -398,9 +398,18 @@ void Id3v2Frame::make(BinaryWriter &writer, std::uint8_t version, Diagnostics &d
} }
/*! /*!
* \brief Resets ID3v2-specific values. Called via clear(). * \brief Clears ID3v2-specific values. Called via clear() and clearValue().
*/ */
void Id3v2Frame::reset() void Id3v2Frame::internallyClearValue()
{
value().clearDataAndMetadata();
m_additionalValues.clear();
}
/*!
* \brief Clears ID3v2-specific values. Called via clear().
*/
void Id3v2Frame::internallyClearFurtherData()
{ {
m_flag = 0; m_flag = 0;
m_group = 0; m_group = 0;
@ -408,7 +417,6 @@ void Id3v2Frame::reset()
m_dataSize = 0; m_dataSize = 0;
m_totalSize = 0; m_totalSize = 0;
m_padding = false; m_padding = false;
m_additionalValues.clear();
} }
/*! /*!

View File

@ -144,7 +144,8 @@ public:
static std::string fieldIdToString(IdentifierType id); static std::string fieldIdToString(IdentifierType id);
private: private:
void reset(); void internallyClearValue();
void internallyClearFurtherData();
std::string ignoreAdditionalValuesDiagMsg() const; std::string ignoreAdditionalValuesDiagMsg() const;
std::vector<TagValue> m_additionalValues; std::vector<TagValue> m_additionalValues;

View File

@ -79,9 +79,6 @@ public:
static typename std::string fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static typename std::string fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
static std::string fieldIdToString(const std::string &id); static std::string fieldIdToString(const std::string &id);
private:
void reset();
}; };
/*! /*!
@ -118,13 +115,6 @@ inline std::string MatroskaTagField::fieldIdToString(const std::string &id)
return id; return id;
} }
/*!
* \brief Resets Matroska-specific values. Called via clear().
*/
inline void MatroskaTagField::reset()
{
}
} // namespace TagParser } // namespace TagParser
#endif // TAG_PARSER_MATROSKATAGFIELD_H #endif // TAG_PARSER_MATROSKATAGFIELD_H

View File

@ -464,15 +464,24 @@ std::uint32_t Mp4TagField::appropriateRawDataTypeForValue(const TagValue &value)
} }
/*! /*!
* \brief Resets MP4-specific values. Called via clear(). * \brief Clears MP4-specific values. Called via clear() and clearValue().
*/ */
void Mp4TagField::reset() void Mp4TagField::internallyClearValue()
{
value().clearDataAndMetadata();
m_additionalData.clear();
m_countryIndicator = 0;
m_langIndicator = 0;
}
/*!
* \brief Clears MP4-specific values. Called via clear() and clearValue().
*/
void Mp4TagField::internallyClearFurtherData()
{ {
m_name.clear(); m_name.clear();
m_mean.clear(); m_mean.clear();
m_parsedRawDataType = RawDataType::Reserved; m_parsedRawDataType = RawDataType::Reserved;
m_countryIndicator = 0;
m_langIndicator = 0;
} }
/// \cond /// \cond

View File

@ -147,7 +147,8 @@ public:
static std::string fieldIdToString(IdentifierType id); static std::string fieldIdToString(IdentifierType id);
private: private:
void reset(); void internallyClearValue();
void internallyClearFurtherData();
std::string m_name; std::string m_name;
std::string m_mean; std::string m_mean;
std::vector<AdditionalData> m_additionalData; std::vector<AdditionalData> m_additionalData;

View File

@ -62,7 +62,6 @@ public:
static std::string fieldIdToString(const std::string &id); static std::string fieldIdToString(const std::string &id);
private: private:
void reset();
template <class StreamType> void internalParse(StreamType &stream, std::uint64_t &maxSize, Diagnostics &diag); template <class StreamType> void internalParse(StreamType &stream, std::uint64_t &maxSize, Diagnostics &diag);
}; };
@ -100,13 +99,6 @@ inline std::string VorbisCommentField::fieldIdToString(const std::string &id)
return id; return id;
} }
/*!
* \brief Resets Vorbis Comment-specific values. Called via clear().
*/
inline void VorbisCommentField::reset()
{
}
} // namespace TagParser } // namespace TagParser
#endif // TAG_PARSER_VORBISCOMMENTFIELD_H #endif // TAG_PARSER_VORBISCOMMENTFIELD_H