Tag Parser  7.1.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 
11 namespace TagParser {
12 
22 public:
23  constexpr PositionInSet(int32 position = 0, int32 total = 0);
24  template <typename StringType = std::string, Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>> * = nullptr>
25  PositionInSet(const StringType &numericString);
26 
27  constexpr int32 position() const;
28  constexpr int32 total() const;
29  constexpr bool isNull() const;
30  constexpr bool operator==(const PositionInSet &other) const;
31 
32  template <typename StringType = std::string, Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>> * = nullptr>
33  StringType toString() const;
34 
35 private:
36  int32 m_position;
37  int32 m_total;
38 };
39 
46 template <typename StringType, Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>> *>
47 PositionInSet::PositionInSet(const StringType &numericString)
48  : m_position(0)
49  , m_total(0)
50 {
51  const auto separator = numericString.find('/');
52  if (separator == StringType::npos || separator == numericString.length() - 1) {
53  m_position = ConversionUtilities::stringToNumber<int32, StringType>(numericString);
54  } else if (separator == 0) {
55  m_total = ConversionUtilities::stringToNumber<int32, StringType>(numericString.substr(1));
56  } else {
57  m_position = ConversionUtilities::stringToNumber<int32, StringType>(numericString.substr(0, separator));
58  m_total = ConversionUtilities::stringToNumber<int32, StringType>(numericString.substr(separator + 1));
59  }
60 }
61 
67 constexpr inline PositionInSet::PositionInSet(int32 position, int32 total)
68  : m_position(position)
69  , m_total(total)
70 {
71 }
72 
76 constexpr inline int32 PositionInSet::position() const
77 {
78  return m_position;
79 }
80 
84 constexpr inline int32 PositionInSet::total() const
85 {
86  return m_total;
87 }
88 
92 constexpr inline bool PositionInSet::isNull() const
93 {
94  return m_position == 0 && m_total == 0;
95 }
96 
100 constexpr inline bool PositionInSet::operator==(const PositionInSet &other) const
101 {
102  return m_position == other.m_position && m_total == other.m_total;
103 }
104 
108 template <typename StringType, Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>> *>
109 StringType PositionInSet::toString() const
110 {
111  std::basic_stringstream<typename StringType::value_type> ss;
112  if (m_position) {
113  ss << m_position;
114  }
115  if (m_total) {
116  ss << '/' << m_total;
117  }
118  return ss.str();
119 }
120 
121 } // namespace TagParser
122 
123 #endif // TAG_PARSER_POSITIONINSET_H
StringType toString() const
Returns the string representation of the current PositionInSet.
constexpr int32 position() const
Returns the element position of the current instance.
Definition: positioninset.h:76
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==(byte lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:19
constexpr int32 total() const
Returns the total element count of the current instance.
Definition: positioninset.h:84
constexpr PositionInSet(int32 position=0, int32 total=0)
Constructs a new Position in set of the specified element position and total element count...
Definition: positioninset.h:67
constexpr bool isNull() const
Returns an indication whether both the element position and total element count is 0...
Definition: positioninset.h:92
constexpr bool operator==(const PositionInSet &other) const
Returns whether this instance equals other.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.