diff --git a/tagvalue.cpp b/tagvalue.cpp index 355b6b2..293095e 100644 --- a/tagvalue.cpp +++ b/tagvalue.cpp @@ -33,7 +33,7 @@ TagValue::TagValue(const TagValue &other) , m_type(other.m_type) , m_desc(other.m_desc) , m_mimeType(other.m_mimeType) - , m_lng(other.m_lng) + , m_language(other.m_language) , m_labeledAsReadonly(other.m_labeledAsReadonly) , m_encoding(other.m_encoding) , m_descEncoding(other.m_descEncoding) @@ -54,7 +54,7 @@ TagValue &TagValue::operator=(const TagValue &other) m_type = other.m_type; m_desc = other.m_desc; m_mimeType = other.m_mimeType; - m_lng = other.m_lng; + m_language = other.m_language; m_labeledAsReadonly = other.m_labeledAsReadonly; m_encoding = other.m_encoding; m_descEncoding = other.m_descEncoding; @@ -79,7 +79,7 @@ TagValue &TagValue::operator=(const TagValue &other) bool TagValue::operator==(const TagValue &other) const { if (m_desc != other.m_desc || (!m_desc.empty() && m_descEncoding != other.m_descEncoding) || m_mimeType != other.m_mimeType - || m_lng != other.m_lng || m_labeledAsReadonly != other.m_labeledAsReadonly) { + || m_language != other.m_language || m_labeledAsReadonly != other.m_labeledAsReadonly) { return false; } if (m_type == other.m_type) { @@ -122,13 +122,6 @@ bool TagValue::operator==(const TagValue &other) const } } -/*! - * \brief Destroys the TagValue. - */ -TagValue::~TagValue() -{ -} - /*! * \brief Wipes assigned meta data. * - Clears description, mime type and language. @@ -140,23 +133,12 @@ void TagValue::clearMetadata() { m_desc.clear(); m_mimeType.clear(); - m_lng.clear(); + m_language.clear(); m_labeledAsReadonly = false; m_encoding = TagTextEncoding::Latin1; m_type = TagDataType::Undefined; } -/*! - * \brief Wipes assigned data including meta data. - * \sa clearData() - * \sa clearMetadata() - */ -void TagValue::clearDataAndMetadata() -{ - clearData(); - clearMetadata(); -} - /*! * \brief Converts the value of the current TagValue object to its equivalent * integer representation. @@ -317,9 +299,9 @@ DateTime TagValue::toDateTime() const case TagDataType::Integer: case TagDataType::DateTime: if (m_size == sizeof(int32)) { - return DateTime(*(reinterpret_cast(m_ptr.get()))); + return DateTime(*(reinterpret_cast(m_ptr.get()))); } else if (m_size == sizeof(int64)) { - return DateTime(*(reinterpret_cast(m_ptr.get()))); + return DateTime(*(reinterpret_cast(m_ptr.get()))); } else { throw ConversionException("The assigned data is of unappropriate size."); } @@ -625,17 +607,6 @@ void TagValue::assignInteger(int value) m_encoding = TagTextEncoding::Latin1; } -/*! - * \brief Assigns the given standard genre \a index to be assigned. - * \param index Specifies the index to be assigned. - * \sa List of genres - Wikipedia - */ -void TagValue::assignStandardGenreIndex(int index) -{ - assignInteger(index); - m_type = TagDataType::StandardGenreIndex; -} - /*! * \brief Assigns a copy of the given \a data. * \param data Specifies the data to be assigned. diff --git a/tagvalue.h b/tagvalue.h index 407c8e6..5ec28d6 100644 --- a/tagvalue.h +++ b/tagvalue.h @@ -61,8 +61,6 @@ enum class TagDataType : unsigned int { }; class TAG_PARSER_EXPORT TagValue { - friend class Id3v2Frame; // FIXME: make ensureHostByteOrder() public in next minor release - public: // constructor, destructor TagValue(); @@ -100,16 +98,17 @@ public: PositionInSet toPositionInSet() const; ChronoUtilities::TimeSpan toTimeSpan() const; ChronoUtilities::DateTime toDateTime() const; - size_t dataSize() const; - char *dataPointer() const; + std::size_t dataSize() const; + char *dataPointer(); + const char *dataPointer() const; const std::string &description() const; void setDescription(const std::string &value, TagTextEncoding encoding = TagTextEncoding::Latin1); const std::string &mimeType() const; - void setMimeType(const std::string &value); + void setMimeType(const std::string &mimeType); const std::string &language() const; - void setLanguage(const std::string &value); + void setLanguage(const std::string &language); bool isLabeledAsReadonly() const; - void setReadonly(bool value); + void setReadonly(bool readOnly); TagTextEncoding dataEncoding() const; void convertDataEncoding(TagTextEncoding encoding); void convertDataEncodingForTag(const Tag *tag); @@ -129,16 +128,17 @@ public: void assignTimeSpan(ChronoUtilities::TimeSpan value); void assignDateTime(ChronoUtilities::DateTime value); -private: static void stripBom(const char *&text, size_t &length, TagTextEncoding encoding); static void ensureHostByteOrder(std::u16string &u16str, TagTextEncoding currentEncoding); +private: + std::unique_ptr m_ptr; - std::string::size_type m_size; + std::size_t m_size; TagDataType m_type; std::string m_desc; std::string m_mimeType; - std::string m_lng; + std::string m_language; bool m_labeledAsReadonly; TagTextEncoding m_encoding; TagTextEncoding m_descEncoding; @@ -156,6 +156,13 @@ inline TagValue::TagValue() { } +/*! + * \brief Destroys the TagValue. + */ +inline TagValue::~TagValue() +{ +} + /*! * \brief Constructs a new TagValue holding a copy of the given \a text. * \param text Specifies the text to be assigned. @@ -207,7 +214,7 @@ inline TagValue::TagValue(int value) * encoding will only be considered if a text is assigned. * \remarks Strips the BOM of the specified \a data if \a type is TagDataType::Text. */ -inline TagValue::TagValue(const char *data, size_t length, TagDataType type, TagTextEncoding encoding) +inline TagValue::TagValue(const char *data, std::size_t length, TagDataType type, TagTextEncoding encoding) : m_size(length) , m_type(type) , m_labeledAsReadonly(false) @@ -226,7 +233,7 @@ inline TagValue::TagValue(const char *data, size_t length, TagDataType type, Tag /*! * \brief Constructs a new TagValue holding with the given \a data. * - * The data is not copied. It is moved. + * The \a data is not copied. It is moved. * * \param data Specifies a pointer to the data. * \param length Specifies the length of the data. @@ -235,7 +242,7 @@ inline TagValue::TagValue(const char *data, size_t length, TagDataType type, Tag * encoding will only be considered if a text is assigned. * \remarks Does not strip the BOM so for consistency the caller must ensure there is no BOM present. */ -inline TagValue::TagValue(std::unique_ptr &&data, size_t length, TagDataType type, TagTextEncoding encoding) +inline TagValue::TagValue(std::unique_ptr &&data, std::size_t length, TagDataType type, TagTextEncoding encoding) : m_size(length) , m_type(type) , m_labeledAsReadonly(false) @@ -308,6 +315,17 @@ inline void TagValue::assignDateTime(ChronoUtilities::DateTime value) assignData(reinterpret_cast(&value), sizeof(value), TagDataType::DateTime); } +/*! + * \brief Assigns the given standard genre \a index to be assigned. + * \param index Specifies the index to be assigned. + * \sa List of genres - Wikipedia + */ +inline void TagValue::assignStandardGenreIndex(int index) +{ + assignInteger(index); + m_type = TagDataType::StandardGenreIndex; +} + /*! * \brief Returns the type of the assigned value. */ @@ -364,6 +382,17 @@ inline void TagValue::clearData() m_ptr.reset(); } +/*! + * \brief Wipes assigned data including meta data. + * \sa clearData() + * \sa clearMetadata() + */ +inline void TagValue::clearDataAndMetadata() +{ + clearData(); + clearMetadata(); +} + /*! * \brief Returns the size of the assigned value in bytes. * \remarks Meta data such as description and MIME type is not considered as part of the assigned value. @@ -376,10 +405,15 @@ inline size_t TagValue::dataSize() const /*! * \brief Returns a pointer to the raw data assigned to the current instance. * \remarks The instance keeps ownership over the data which will be invalidated when the - * it gets destroyed or an other value is assigned. + * TagValue gets destroyed or another value is assigned. * \remarks The raw data is not null terminated. See dataSize(). */ -inline char *TagValue::dataPointer() const +inline char *TagValue::dataPointer() +{ + return m_ptr.get(); +} + +inline const char *TagValue::dataPointer() const { return m_ptr.get(); } @@ -425,9 +459,9 @@ inline const std::string &TagValue::mimeType() const * \remarks The usage of this meta information depends on the tag implementation. * \sa mimeType() */ -inline void TagValue::setMimeType(const std::string &value) +inline void TagValue::setMimeType(const std::string &mimeType) { - m_mimeType = value; + m_mimeType = mimeType; } /*! @@ -437,7 +471,7 @@ inline void TagValue::setMimeType(const std::string &value) */ inline const std::string &TagValue::language() const { - return m_lng; + return m_language; } /*! @@ -446,9 +480,9 @@ inline const std::string &TagValue::language() const * \remarks The usage of this meta information depends on the tag implementation. * \sa language() */ -inline void TagValue::setLanguage(const std::string &value) +inline void TagValue::setLanguage(const std::string &language) { - m_lng = value; + m_language = language; } /*! @@ -472,9 +506,9 @@ inline bool TagValue::isLabeledAsReadonly() const * assignments simply use the "const" keyword). * \sa isLabeledAsReadonly() */ -inline void TagValue::setReadonly(bool value) +inline void TagValue::setReadonly(bool readOnly) { - m_labeledAsReadonly = value; + m_labeledAsReadonly = readOnly; } /*!