Tag Parser 11.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
positioninset.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_POSITIONINSET_H
2#define TAG_PARSER_POSITIONINSET_H
3
4#include "./global.h"
5
6#include <c++utilities/conversion/stringconversion.h>
7#include <c++utilities/misc/traits.h>
8
9#include <string>
10
11namespace TagParser {
12
22public:
23 constexpr explicit PositionInSet(std::int32_t position = 0, std::int32_t total = 0);
24 template <typename StringType = std::string,
25 CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> * = nullptr>
26 PositionInSet(const StringType &numericString);
27
28 constexpr std::int32_t position() const;
29 constexpr std::int32_t total() const;
30 constexpr bool isNull() const;
31 constexpr bool operator==(const PositionInSet &other) const;
32
33 template <typename StringType = std::string,
34 CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> * = nullptr>
35 StringType toString() const;
36
37private:
38 std::int32_t m_position;
39 std::int32_t m_total;
40};
41
48template <typename StringType, CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> *>
49PositionInSet::PositionInSet(const StringType &numericString)
50 : m_position(0)
51 , m_total(0)
52{
53 const auto separator = numericString.find('/');
54 if (separator == StringType::npos || separator == numericString.length() - 1) {
55 m_position = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString);
56 } else if (separator == 0) {
57 m_total = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(1));
58 } else {
59 m_position = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(0, separator));
60 m_total = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(separator + 1));
61 }
62}
63
69constexpr inline PositionInSet::PositionInSet(std::int32_t position, std::int32_t total)
70 : m_position(position)
71 , m_total(total)
72{
73}
74
78constexpr inline std::int32_t PositionInSet::position() const
79{
80 return m_position;
81}
82
86constexpr inline std::int32_t PositionInSet::total() const
87{
88 return m_total;
89}
90
94constexpr inline bool PositionInSet::isNull() const
95{
96 return m_position == 0 && m_total == 0;
97}
98
102constexpr inline bool PositionInSet::operator==(const PositionInSet &other) const
103{
104 return m_position == other.m_position && m_total == other.m_total;
105}
106
110template <typename StringType, CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> *>
111StringType PositionInSet::toString() const
112{
113 std::basic_stringstream<typename StringType::value_type> ss;
114 if (m_position) {
115 ss << m_position;
116 }
117 if (m_total) {
118 ss << '/' << m_total;
119 }
120 return ss.str();
121}
122
123} // namespace TagParser
124
125#endif // TAG_PARSER_POSITIONINSET_H
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
constexpr bool operator==(const PositionInSet &other) const
Returns whether this instance equals other.
constexpr std::int32_t position() const
Returns the element position of the current instance.
Definition: positioninset.h:78
constexpr std::int32_t total() const
Returns the total element count of the current instance.
Definition: positioninset.h:86
constexpr PositionInSet(std::int32_t position=0, std::int32_t total=0)
Constructs a new Position in set of the specified element position and total element count.
Definition: positioninset.h:69
StringType toString() const
Returns the string representation of the current PositionInSet.
constexpr bool isNull() const
Returns an indication whether both the element position and total element count is 0.
Definition: positioninset.h:94
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:18