1#ifndef TAG_PARSER_TAGVALUE_H
2#define TAG_PARSER_TAGVALUE_H
8#include <c++utilities/chrono/datetime.h>
9#include <c++utilities/chrono/timespan.h>
10#include <c++utilities/conversion/binaryconversion.h>
11#include <c++utilities/misc/flagenumclass.h>
12#include <c++utilities/misc/traits.h>
19#include <unordered_map>
78 std::uint64_t playCounter = 0;
84 bool scaleTo(
TagType targetScale);
86 std::string toString()
const;
87 static Popularity fromString(std::string_view str);
93 return user.empty() && rating == 0.0 && !playCounter;
145struct TagValuePrivate;
151 explicit TagValue(
const char *text, std::size_t textSize, TagTextEncoding textEncoding = TagTextEncoding::Latin1,
152 TagTextEncoding convertTo = TagTextEncoding::Unspecified);
154 const char *text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
156 const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
158 std::string_view text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
159 explicit TagValue(
int value);
162 const char *data, std::size_t length,
TagDataType type = TagDataType::Undefined,
TagTextEncoding encoding = TagTextEncoding::Latin1);
163 explicit TagValue(std::unique_ptr<
char[]> &&data, std::size_t length,
TagDataType type = TagDataType::Binary,
166 explicit TagValue(CppUtilities::DateTime value);
167 explicit TagValue(
const CppUtilities::DateTimeExpression &value);
168 explicit TagValue(CppUtilities::TimeSpan value);
179 operator bool()
const;
183 bool isEmpty()
const;
185 void clearMetadata();
186 void clearDataAndMetadata();
188 std::string toString(
TagTextEncoding encoding = TagTextEncoding::Unspecified)
const;
190 void toString(std::string &result,
TagTextEncoding encoding = TagTextEncoding::Unspecified)
const;
191 std::u16string toWString(
TagTextEncoding encoding = TagTextEncoding::Unspecified)
const;
192 void toWString(std::u16string &result,
TagTextEncoding encoding = TagTextEncoding::Unspecified)
const;
193 std::int32_t toInteger()
const;
194 std::uint64_t toUnsignedInteger()
const;
195 int toStandardGenreIndex()
const;
197 CppUtilities::TimeSpan toTimeSpan()
const;
198 CppUtilities::DateTime toDateTime()
const;
202 std::size_t dataSize()
const;
204 const char *dataPointer()
const;
205 std::string_view data()
const;
206 const std::string &description()
const;
207 void setDescription(std::string_view value,
TagTextEncoding encoding = TagTextEncoding::Latin1);
208 const std::string &mimeType()
const;
209 void setMimeType(std::string_view mimeType);
210 const Locale &locale()
const;
212 void setLocale(
const Locale &locale);
215 bool isLabeledAsReadonly()
const;
216 void setReadonly(
bool readOnly);
217 const std::unordered_map<std::string, std::string> &nativeData()
const;
218 std::unordered_map<std::string, std::string> &nativeData();
221 void convertDataEncodingForTag(
const Tag *tag);
226 void assignText(
const char *text, std::size_t textSize,
TagTextEncoding textEncoding = TagTextEncoding::Latin1,
232 void assignInteger(
int value);
233 void assignUnsignedInteger(std::uint64_t value);
234 void assignStandardGenreIndex(
int index);
239 void assignTimeSpan(CppUtilities::TimeSpan value);
240 void assignDateTime(CppUtilities::DateTime value);
242 void assignPopularity(
const Popularity &value);
244 static void stripBom(
const char *&text, std::size_t &length,
TagTextEncoding encoding);
245 static void ensureHostByteOrder(std::u16string &u16str,
TagTextEncoding currentEncoding);
246 template <
typename ContainerType,
247 CppUtilities::Traits::EnableIf<CppUtilities::Traits::IsIteratable<ContainerType>,
248 std::is_same<typename std::add_const<typename std::remove_pointer<typename ContainerType::value_type>::type>::type,
const TagValue>>
250 static std::vector<std::string> toStrings(
const ContainerType &values,
TagTextEncoding encoding = TagTextEncoding::Utf8);
252 bool compareData(
const TagValue &other,
bool ignoreCase =
false)
const;
253 static bool compareData(
const std::string &data1,
const std::string &data2,
bool ignoreCase =
false);
254 static bool compareData(
const char *data1, std::size_t size1,
const char *data2, std::size_t size2,
bool ignoreCase =
false);
257 std::unique_ptr<char[]> m_ptr;
260 std::string m_mimeType;
262 std::unordered_map<std::string, std::string> m_nativeData;
267 std::unique_ptr<TagValuePrivate> m_p;
349inline TagParser::TagValue::operator bool()
const
365 assignText(text.data(), text.size(), textEncoding, convertTo);
379 assignText(text.data(), text.size(), textEncoding, convertTo);
479 return m_ptr ==
nullptr;
492 return m_ptr ==
nullptr || m_size == 0;
548 return std::string_view(m_ptr.get(), m_size);
580 m_descEncoding = encoding;
730 return m_descEncoding;
738template <
typename ContainerType,
739 CppUtilities::Traits::EnableIf<CppUtilities::Traits::IsIteratable<ContainerType>,
740 std::is_same<typename std::add_const<typename std::remove_pointer<typename ContainerType::value_type>::type>::type,
const TagValue>> *>
743 std::vector<std::string> res;
744 res.reserve(values.size());
745 for (
const auto &value : values) {
746 res.emplace_back(CppUtilities::Traits::dereferenceMaybe(value).
toString(encoding));
756 return compareData(m_ptr.get(), m_size, other.m_ptr.get(), other.m_size, ignoreCase);
764 return compareData(data1.data(), data1.size(), data2.data(), data2.size(), ignoreCase);
The PositionInSet class describes the position of an element in a set which consists of a certain num...
constexpr bool isNull() const
Returns an indication whether both the element position and total element count is 0.
The TagValue class wraps values of different types.
bool compareData(const TagValue &other, bool ignoreCase=false) const
Returns whether the raw data of the current instance equals the raw data of other.
void setMimeType(std::string_view mimeType)
Sets the MIME type.
void setFlags(TagValueFlags flags)
Sets the flags.
const std::unordered_map< std::string, std::string > & nativeData() const
Holds tag format specific meta-data for that field which does not fit into any of the other meta-data...
void clearMetadata()
Wipes assigned meta data.
void assignText(const char *text, std::size_t textSize, TagTextEncoding textEncoding=TagTextEncoding::Latin1, TagTextEncoding convertTo=TagTextEncoding::Unspecified)
Assigns a copy of the given text.
const std::string & mimeType() const
Returns the MIME type.
void assignInteger(int value)
Assigns the given integer value.
bool compareTo(const TagValue &other, TagValueComparisionFlags options=TagValueComparisionFlags::None) const
Returns whether both instances are equal.
std::string toDisplayString() const
CppUtilities::DateTimeExpression toDateTimeExpression() const
TagTextEncoding dataEncoding() const
Returns the data encoding.
void assignPosition(PositionInSet value)
Assigns the given PositionInSet value.
void assignData(const char *data, std::size_t length, TagDataType type=TagDataType::Binary, TagTextEncoding encoding=TagTextEncoding::Latin1)
bool operator==(const TagValue &other) const
Returns whether both instances are equal.
void setDescription(std::string_view value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
TagValue(TagValue &&other)
TagDataType type() const
Returns the type of the assigned value.
void assignPopularity(const Popularity &value)
Assigns the specified popularity value.
void assignTimeSpan(CppUtilities::TimeSpan value)
Assigns the given TimeSpan value.
void assignDateTimeExpression(const CppUtilities::DateTimeExpression &value)
static std::vector< std::string > toStrings(const ContainerType &values, TagTextEncoding encoding=TagTextEncoding::Utf8)
Converts the specified values to string using the specified encoding.
void clearDataAndMetadata()
Wipes assigned data including meta data.
void assignData(std::unique_ptr< char[]> &&data, std::size_t length, TagDataType type=TagDataType::Binary, TagTextEncoding encoding=TagTextEncoding::Latin1)
void assignDateTime(CppUtilities::DateTime value)
Assigns the given DateTime value.
bool isLabeledAsReadonly() const
Returns an indication whether the value is labeled as read-only.
TagValueFlags flags() const
Returns the flags.
bool operator!=(const TagValue &other) const
Returns whether both instances are not equal.
std::string_view data() const
Returns the currently assigned raw data.
std::size_t dataSize() const
Returns the size of the assigned value in bytes.
std::u16string toWString(TagTextEncoding encoding=TagTextEncoding::Unspecified) const
Converts the value of the current TagValue object to its equivalent std::wstring representation.
TagTextEncoding descriptionEncoding() const
Returns the description encoding.
TagValue(std::uint64_t value)
void assignStandardGenreIndex(int index)
Assigns the given standard genre index to be assigned.
std::string toString(TagTextEncoding encoding=TagTextEncoding::Unspecified) const
Converts the value of the current TagValue object to its equivalent std::string representation.
bool isNull() const
Returns whether no value is assigned at all.
void setLocale(const Locale &locale)
Sets the setLocale.
void setReadonly(bool readOnly)
Sets whether the TagValue is labeled as read-only.
void clearData()
Clears the assigned data.
TagValue & operator=(TagValue &&other)
bool isEmpty() const
Returns whether no or an empty value is assigned.
const std::string & description() const
Returns the description.
const Locale & locale() const
Returns the locale.
TagValue()
Constructs an empty TagValue.
char * dataPointer()
Returns a pointer to the raw data assigned to the current instance.
The Tag class is used to store, read and write tag information.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
constexpr int characterSize(TagTextEncoding encoding)
Returns the size of one character for the specified encoding in bytes.
TAG_PARSER_EXPORT std::string_view tagDataTypeString(TagDataType dataType)
Returns the string representation of the specified dataType.
TagTextEncoding
Specifies the text encoding.
constexpr bool operator!=(std::uint8_t lhs, FlacMetaDataBlockType type)
constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)
TagType
Specifies the tag type.
TagValueComparisionFlags
The TagValueComparisionOption enum specifies options for TagValue::compareTo().
TagValueFlags
Specifies additional flags about the tag value.
TagDataType
Specifies the data type.
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(TagParser, TagParser::TagCreationFlags)
The Locale struct specifies a language and/or a country using one or more LocaleDetail objects.
The Popularity class contains a value for ID3v2's "Popularimeter" field.
std::string user
The user who gave the rating / played the file, e.g. identified by e-mail address.
bool isEmpty() const
Returns whether the Popularity is empty. The scale and zero-values don't count.
bool operator==(const Popularity &other) const
Returns whether two instances are equal.
std::uint64_t playCounter
Play counter specific to the user.
bool scaleTo(TagType targetScale)
Scales the rating from the current scale to targetScale.
Popularity scaled(TagType targetScale) const
Same as Popularity::scaleTo() but returns a new object.
TagType scale
Specifies the scale used for rating by the tag defining that scale.
double rating
The rating on a tag type specific scale.
static Popularity fromString(std::string_view str, TagType scale)