Tag Parser  8.0.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
matroskatag.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_MATROSKATAG_H
2 #define TAG_PARSER_MATROSKATAG_H
3 
4 #include "./matroskatagfield.h"
5 #include "./matroskatagid.h"
6 
7 #include "../fieldbasedtag.h"
8 
9 namespace TagParser {
10 
11 class EbmlElement;
12 class MatroskaTag;
13 
15  friend class MatroskaTag;
16 
17 public:
18  void make(std::ostream &stream) const;
19  const MatroskaTag &tag() const;
20  uint64 requiredSize() const;
21 
22 private:
24 
25  MatroskaTag &m_tag;
26  uint64 m_targetsSize;
27  uint64 m_simpleTagsSize;
28  std::vector<MatroskaTagFieldMaker> m_maker;
29  uint64 m_tagSize;
30  uint64 m_totalSize;
31 };
32 
36 inline const MatroskaTag &MatroskaTagMaker::tag() const
37 {
38  return m_tag;
39 }
40 
44 inline uint64 MatroskaTagMaker::requiredSize() const
45 {
46  return m_totalSize;
47 }
48 
53 public:
55  using Compare = std::less<typename FieldType::IdentifierType>;
56 };
57 
58 class TAG_PARSER_EXPORT MatroskaTag : public FieldMapBasedTag<MatroskaTag> {
60 
61 public:
62  MatroskaTag();
63 
64  static constexpr TagType tagType = TagType::MatroskaTag;
65  static constexpr const char *tagName = "Matroska tag";
66  static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
67  bool canEncodingBeUsed(TagTextEncoding encoding) const override;
68  bool supportsTarget() const override;
69  bool supportsMultipleValues(KnownField field) const override;
70  TagTargetLevel targetLevel() const override;
71 
72  void parse(EbmlElement &tagElement, Diagnostics &diag);
73  MatroskaTagMaker prepareMaking(Diagnostics &diag);
74  void make(std::ostream &stream, Diagnostics &diag);
75 
76 protected:
77  IdentifierType internallyGetFieldId(KnownField field) const;
78  KnownField internallyGetKnownField(const IdentifierType &id) const;
79 
80 private:
81  void parseTargets(EbmlElement &targetsElement, Diagnostics &diag);
82 };
83 
88 {
89 }
90 
91 inline bool MatroskaTag::supportsTarget() const
92 {
93  return true;
94 }
95 
102 {
103  return true;
104 }
105 
107 {
109 }
110 
122 {
123  return MatroskaTagMaker(*this, diag);
124 }
125 
133 inline void MatroskaTag::make(std::ostream &stream, Diagnostics &diag)
134 {
135  prepareMaking(diag).make(stream);
136 }
137 
139 {
140  return encoding == TagTextEncoding::Utf8;
141 }
142 
143 } // namespace TagParser
144 
145 #endif // TAG_PARSER_MATROSKATAG_H
constexpr TAG_PARSER_EXPORT TagTargetLevel matroskaTagTargetLevel(uint64 targetLevelValue)
Returns the general TagTargetLevel for the Matroska specific targetLevelValue.
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
Definition: fieldbasedtag.h:31
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition: tagtarget.h:17
bool supportsMultipleValues(KnownField field) const override
Allows multiple values for all fields.
Definition: matroskatag.h:101
MatroskaTagMaker prepareMaking(Diagnostics &diag)
Prepares making.
Definition: matroskatag.h:121
uint64 requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition: matroskatag.h:44
uint64 level() const
Returns the level.
Definition: tagtarget.h:72
std::less< typename FieldType::IdentifierType > Compare
Definition: matroskatag.h:55
The MatroskaTagMaker class helps writing Matroska "Tag"-elements storing tag information.
Definition: matroskatag.h:14
KnownField
Specifies the field.
Definition: tag.h:40
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:31
The MatroskaTagField class is used by MatroskaTag to store the fields.
Defines traits for the specified ImplementationType.
Definition: fieldbasedtag.h:17
void make(std::ostream &stream, Diagnostics &diag)
Writes tag information to the specified stream (makes a "Tag"-element).
Definition: matroskatag.h:133
bool canEncodingBeUsed(TagTextEncoding encoding) const override
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition: matroskatag.h:138
Implementation of TagParser::Tag for the Matroska container.
Definition: matroskatag.h:58
MatroskaTag()
Constructs a new tag.
Definition: matroskatag.h:87
void make(std::ostream &stream) const
Saves the tag (specified when constructing the object) to the specified stream (makes a "Tag"-element...
TagTarget m_target
Definition: tag.h:133
const MatroskaTag & tag() const
Returns the associated tag.
Definition: matroskatag.h:36
TagType
Specifies the tag type.
Definition: tag.h:20
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:24
bool supportsTarget() const override
Returns an indication whether a target is supported by the tag.
Definition: matroskatag.h:91
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.
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagTargetLevel targetLevel() const override
Returns the name of the current tag target level.
Definition: matroskatag.h:106