Tag Parser  6.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 POSITIONINSET_H
2 #define POSITIONINSET_H
3 
4 #include "./global.h"
5 
6 #include <c++utilities/conversion/stringconversion.h>
7 
8 #include <string>
9 
10 namespace Media {
11 
21 {
22 public:
23  constexpr PositionInSet(int32 position = 0, int32 total = 0);
24  template <typename StringType = std::string>
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>
33  StringType toString() const;
34 
35 private:
36  int32 m_position;
37  int32 m_total;
38 };
39 
46 template <typename StringType>
47 PositionInSet::PositionInSet(const StringType &numericString) :
48  m_position(0),
49  m_total(0)
50 {
51  size_t 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 
75 constexpr inline int32 PositionInSet::position() const
76 {
77  return m_position;
78 }
79 
83 constexpr inline int32 PositionInSet::total() const
84 {
85  return m_total;
86 }
87 
91 constexpr inline bool PositionInSet::isNull() const
92 {
93  return m_position == 0 && m_total == 0;
94 }
95 
99 constexpr inline bool PositionInSet::operator==(const PositionInSet &other) const
100 {
101  return m_position == other.m_position && m_total == other.m_total;
102 }
103 
107 template <typename StringType>
108 StringType PositionInSet::toString() const
109 {
110  std::basic_stringstream<typename StringType::value_type> ss;
111  if(m_position) {
112  ss << m_position;
113  }
114  if(m_total) {
115  ss << '/' << m_total;
116  }
117  return ss.str();
118 }
119 
120 }
121 
122 #endif // POSITIONINSET_H
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:20
constexpr bool operator==(const PositionInSet &other) const
Returns whether this instance equals other.
Definition: positioninset.h:99
constexpr int32 total() const
Returns the total element count of the current instance.
Definition: positioninset.h:83
constexpr bool operator==(byte lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:28
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
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
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:75
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr bool isNull() const
Returns an indication whether both the element position and total element count is 0...
Definition: positioninset.h:91