Add flags to TagValue, replacing dedicated field for read-only flag

This commit is contained in:
Martchus 2020-12-05 20:52:01 +01:00
parent aa23750307
commit 9368b7a245
2 changed files with 51 additions and 14 deletions

View File

@ -101,7 +101,7 @@ TagValue::TagValue(const TagValue &other)
, m_type(other.m_type) , m_type(other.m_type)
, m_encoding(other.m_encoding) , m_encoding(other.m_encoding)
, m_descEncoding(other.m_descEncoding) , m_descEncoding(other.m_descEncoding)
, m_labeledAsReadonly(other.m_labeledAsReadonly) , m_flags(TagValueFlags::None)
{ {
if (!other.isEmpty()) { if (!other.isEmpty()) {
m_ptr = make_unique<char[]>(m_size); m_ptr = make_unique<char[]>(m_size);
@ -122,7 +122,7 @@ TagValue &TagValue::operator=(const TagValue &other)
m_desc = other.m_desc; m_desc = other.m_desc;
m_mimeType = other.m_mimeType; m_mimeType = other.m_mimeType;
m_language = other.m_language; m_language = other.m_language;
m_labeledAsReadonly = other.m_labeledAsReadonly; m_flags = other.m_flags;
m_encoding = other.m_encoding; m_encoding = other.m_encoding;
m_descEncoding = other.m_descEncoding; m_descEncoding = other.m_descEncoding;
if (other.isEmpty()) { if (other.isEmpty()) {
@ -183,7 +183,7 @@ bool TagValue::compareTo(const TagValue &other, TagValueComparisionFlags options
// check whether meta-data is equal (except description) // check whether meta-data is equal (except description)
if (!(options & TagValueComparisionFlags::IgnoreMetaData)) { if (!(options & TagValueComparisionFlags::IgnoreMetaData)) {
// check meta-data which always uses UTF-8 (everything but description) // check meta-data which always uses UTF-8 (everything but description)
if (m_mimeType != other.m_mimeType || m_language != other.m_language || m_labeledAsReadonly != other.m_labeledAsReadonly) { if (m_mimeType != other.m_mimeType || m_language != other.m_language || m_flags != other.m_flags) {
return false; return false;
} }
@ -299,8 +299,7 @@ bool TagValue::compareTo(const TagValue &other, TagValueComparisionFlags options
/*! /*!
* \brief Wipes assigned meta data. * \brief Wipes assigned meta data.
* - Clears description, mime type and language. * - Clears description, mime type, language and flags.
* - Resets the read-only flag to false.
* - Resets the encoding to TagTextEncoding::Latin1. * - Resets the encoding to TagTextEncoding::Latin1.
* - Resets the data type to TagDataType::Undefined. * - Resets the data type to TagDataType::Undefined.
*/ */
@ -309,7 +308,7 @@ void TagValue::clearMetadata()
m_desc.clear(); m_desc.clear();
m_mimeType.clear(); m_mimeType.clear();
m_language.clear(); m_language.clear();
m_labeledAsReadonly = false; m_flags = TagValueFlags::None;
m_encoding = TagTextEncoding::Latin1; m_encoding = TagTextEncoding::Latin1;
m_descEncoding = TagTextEncoding::Latin1; m_descEncoding = TagTextEncoding::Latin1;
m_type = TagDataType::Undefined; m_type = TagDataType::Undefined;

View File

@ -9,6 +9,7 @@
#include <c++utilities/misc/flagenumclass.h> #include <c++utilities/misc/flagenumclass.h>
#include <c++utilities/misc/traits.h> #include <c++utilities/misc/traits.h>
#include <cstdint>
#include <cstring> #include <cstring>
#include <iosfwd> #include <iosfwd>
#include <memory> #include <memory>
@ -30,6 +31,23 @@ enum class TagTextEncoding : unsigned int {
Unspecified /**< unspecified encoding */ Unspecified /**< unspecified encoding */
}; };
/*!
* \brief Specifies additional flags about the tag value.
* \remarks It depends on the tag format whether these flags can be present. When setting a flag
* which is not supported by the tag format, the tag implementation for that tag format
* is supposed to ignore these flags.
*/
enum class TagValueFlags : std::uint64_t {
None, /**< no flags present */
ReadOnly, /**< the tag value is labeled as read-only */
};
} // namespace TagParser
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(TagParser, TagParser::TagValueFlags)
namespace TagParser {
/*! /*!
* \brief Returns the size of one character for the specified \a encoding in bytes. * \brief Returns the size of one character for the specified \a encoding in bytes.
* \remarks For variable-width encoding the minimum size is returned. * \remarks For variable-width encoding the minimum size is returned.
@ -126,6 +144,8 @@ public:
void setMimeType(const std::string &mimeType); void setMimeType(const std::string &mimeType);
const std::string &language() const; const std::string &language() const;
void setLanguage(const std::string &language); void setLanguage(const std::string &language);
TagValueFlags flags() const;
void setFlags(TagValueFlags flags);
bool isLabeledAsReadonly() const; bool isLabeledAsReadonly() const;
void setReadonly(bool readOnly); void setReadonly(bool readOnly);
TagTextEncoding dataEncoding() const; TagTextEncoding dataEncoding() const;
@ -169,7 +189,7 @@ private:
TagDataType m_type; TagDataType m_type;
TagTextEncoding m_encoding; TagTextEncoding m_encoding;
TagTextEncoding m_descEncoding; TagTextEncoding m_descEncoding;
bool m_labeledAsReadonly; TagValueFlags m_flags;
}; };
/*! /*!
@ -180,7 +200,7 @@ inline TagValue::TagValue()
, m_type(TagDataType::Undefined) , m_type(TagDataType::Undefined)
, m_encoding(TagTextEncoding::Latin1) , m_encoding(TagTextEncoding::Latin1)
, m_descEncoding(TagTextEncoding::Latin1) , m_descEncoding(TagTextEncoding::Latin1)
, m_labeledAsReadonly(false) , m_flags(TagValueFlags::None)
{ {
} }
@ -203,7 +223,7 @@ inline TagValue::~TagValue()
*/ */
inline TagValue::TagValue(const char *text, std::size_t textSize, TagTextEncoding textEncoding, TagTextEncoding convertTo) inline TagValue::TagValue(const char *text, std::size_t textSize, TagTextEncoding textEncoding, TagTextEncoding convertTo)
: m_descEncoding(TagTextEncoding::Latin1) : m_descEncoding(TagTextEncoding::Latin1)
, m_labeledAsReadonly(false) , m_flags(TagValueFlags::None)
{ {
assignText(text, textSize, textEncoding, convertTo); assignText(text, textSize, textEncoding, convertTo);
} }
@ -233,7 +253,7 @@ inline TagValue::TagValue(const char *text, TagTextEncoding textEncoding, TagTex
*/ */
inline TagValue::TagValue(const std::string &text, TagTextEncoding textEncoding, TagTextEncoding convertTo) inline TagValue::TagValue(const std::string &text, TagTextEncoding textEncoding, TagTextEncoding convertTo)
: m_descEncoding(TagTextEncoding::Latin1) : m_descEncoding(TagTextEncoding::Latin1)
, m_labeledAsReadonly(false) , m_flags(TagValueFlags::None)
{ {
assignText(text, textEncoding, convertTo); assignText(text, textEncoding, convertTo);
} }
@ -261,7 +281,7 @@ inline TagValue::TagValue(const char *data, std::size_t length, TagDataType type
, m_type(type) , m_type(type)
, m_encoding(encoding) , m_encoding(encoding)
, m_descEncoding(TagTextEncoding::Latin1) , m_descEncoding(TagTextEncoding::Latin1)
, m_labeledAsReadonly(false) , m_flags(TagValueFlags::None)
{ {
if (length) { if (length) {
if (type == TagDataType::Text) { if (type == TagDataType::Text) {
@ -289,7 +309,7 @@ inline TagValue::TagValue(std::unique_ptr<char[]> &&data, std::size_t length, Ta
, m_type(type) , m_type(type)
, m_encoding(encoding) , m_encoding(encoding)
, m_descEncoding(TagTextEncoding::Latin1) , m_descEncoding(TagTextEncoding::Latin1)
, m_labeledAsReadonly(false) , m_flags(TagValueFlags::None)
{ {
if (length) { if (length) {
m_ptr = move(data); m_ptr = move(data);
@ -586,6 +606,24 @@ inline void TagValue::setLanguage(const std::string &language)
m_language = language; m_language = language;
} }
/*!
* \brief Returns the flags.
* \sa TagValueFlags
*/
inline TagValueFlags TagValue::flags() const
{
return m_flags;
}
/*!
* \brief Sets the flags.
* \sa TagValueFlags
*/
inline void TagValue::setFlags(TagValueFlags flags)
{
m_flags = flags;
}
/*! /*!
* \brief Returns an indication whether the value is labeled as read-only. * \brief Returns an indication whether the value is labeled as read-only.
* \remarks The usage of this meta information depends on the tag implementation. * \remarks The usage of this meta information depends on the tag implementation.
@ -596,7 +634,7 @@ inline void TagValue::setLanguage(const std::string &language)
*/ */
inline bool TagValue::isLabeledAsReadonly() const inline bool TagValue::isLabeledAsReadonly() const
{ {
return m_labeledAsReadonly; return m_flags & TagValueFlags::ReadOnly;
} }
/*! /*!
@ -609,7 +647,7 @@ inline bool TagValue::isLabeledAsReadonly() const
*/ */
inline void TagValue::setReadonly(bool readOnly) inline void TagValue::setReadonly(bool readOnly)
{ {
m_labeledAsReadonly = readOnly; readOnly ? (m_flags += TagValueFlags::ReadOnly) : (m_flags -= TagValueFlags::ReadOnly);
} }
/*! /*!