Tag Parser 12.1.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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 void setPosition(std::int32_t position);
30 constexpr std::int32_t total() const;
31 void setTotal(std::int32_t total);
32 constexpr bool isNull() const;
33 constexpr bool operator==(const PositionInSet &other) const;
34
35 template <typename StringType = std::string,
36 CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> * = nullptr>
37 StringType toString() const;
38
39private:
40 std::int32_t m_position;
41 std::int32_t m_total;
42};
43
50template <typename StringType, CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> *>
51PositionInSet::PositionInSet(const StringType &numericString)
52 : m_position(0)
53 , m_total(0)
54{
55 const auto separator = numericString.find('/');
56 if (separator == StringType::npos || separator == numericString.length() - 1) {
57 m_position = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString);
58 } else if (separator == 0) {
59 m_total = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(1));
60 } else {
61 m_position = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(0, separator));
62 m_total = CppUtilities::stringToNumber<std::int32_t, StringType>(numericString.substr(separator + 1));
63 }
64}
65
71constexpr inline PositionInSet::PositionInSet(std::int32_t position, std::int32_t total)
72 : m_position(position)
73 , m_total(total)
74{
75}
76
80constexpr inline std::int32_t PositionInSet::position() const
81{
82 return m_position;
83}
84
88inline void PositionInSet::setPosition(int32_t position)
89{
90 m_position = position;
91}
92
96constexpr inline std::int32_t PositionInSet::total() const
97{
98 return m_total;
99}
100
104inline void PositionInSet::setTotal(int32_t total)
105{
106 m_total = total;
107}
108
112constexpr inline bool PositionInSet::isNull() const
113{
114 return m_position == 0 && m_total == 0;
115}
116
120constexpr inline bool PositionInSet::operator==(const PositionInSet &other) const
121{
122 return m_position == other.m_position && m_total == other.m_total;
123}
124
128template <typename StringType, CppUtilities::Traits::EnableIfAny<CppUtilities::Traits::IsSpecializationOf<StringType, std::basic_string>> *>
129StringType PositionInSet::toString() const
130{
131 std::basic_stringstream<typename StringType::value_type> ss;
132 if (m_position) {
133 ss << m_position;
134 }
135 if (m_total) {
136 ss << '/' << m_total;
137 }
138 return ss.str();
139}
140
141} // namespace TagParser
142
143#endif // TAG_PARSER_POSITIONINSET_H
The PositionInSet class describes the position of an element in a set which consists of a certain num...
constexpr bool operator==(const PositionInSet &other) const
Returns whether this instance equals other.
void setTotal(std::int32_t total)
Sets the total element count of the current instance.
constexpr std::int32_t position() const
Returns the element position of the current instance.
void setPosition(std::int32_t position)
Sets the element position of the current instance.
constexpr std::int32_t total() const
Returns the total element count of the current instance.
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.
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.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:13
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)