Tag Parser  6.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
ebmlelement.h
Go to the documentation of this file.
1 #ifndef EBMLELEMENT_H
2 #define EBMLELEMENT_H
3 
4 #include "./ebmlid.h"
5 #include "./matroskaid.h"
6 
7 #include "../statusprovider.h"
8 #include "../genericfileelement.h"
9 
10 #include <c++utilities/conversion/types.h>
11 #include <c++utilities/conversion/stringbuilder.h>
12 #include <c++utilities/conversion/stringconversion.h>
13 
14 #include <iostream>
15 #include <memory>
16 
17 namespace Media {
18 
19 class EbmlElement;
20 class MatroskaContainer;
21 
25 template <>
27 {
28 public:
33 
37  typedef uint32 identifierType;
38 
42  typedef uint64 dataSizeType;
43 
48 };
49 
51 {
53 
54 public:
55  EbmlElement(MatroskaContainer &container, uint64 startOffset);
56 
57  std::string idToString() const;
58  bool isParent() const;
59  bool isPadding() const;
60  uint64 firstChildOffset() const;
61  std::string readString();
62  uint64 readUInteger();
63  float64 readFloat();
64 
65  static byte calculateIdLength(identifierType id);
66  static byte calculateSizeDenotationLength(uint64 size);
67  static byte makeId(identifierType id, char *buff);
68  static byte makeSizeDenotation(uint64 size, char *buff);
69  static byte makeSizeDenotation(uint64 size, char *buff, byte minBytes);
70  static byte calculateUIntegerLength(uint64 integer);
71  static byte makeUInteger(uint64 value, char *buff);
72  static byte makeUInteger(uint64 value, char *buff, byte minBytes);
73  static void makeSimpleElement(std::ostream &stream, identifierType id, uint64 content);
74  static void makeSimpleElement(std::ostream &stream, identifierType id, const std::string &content);
75  static void makeSimpleElement(std::ostream &stream, GenericFileElement::identifierType id, const char *data, std::size_t dataSize);
76  static uint64 bytesToBeSkipped;
77 
78 protected:
79  EbmlElement(EbmlElement &parent, uint64 startOffset);
80  EbmlElement(MatroskaContainer &container, uint64 startOffset, uint64 maxSize);
81 
82  void internalParse();
83 
84 private:
85  std::string parsingContext() const;
86 };
87 
91 inline std::string EbmlElement::idToString() const
92 {
93  using namespace ConversionUtilities;
94  const char *const name = matroskaIdName(id());
95  if(*name) {
96  return argsToString('0', 'x', numberToString(id(), 16), ' ', '\"', name, '\"');
97  } else {
98  return "0x" + numberToString(id(), 16);
99  }
100 }
101 
108 inline bool EbmlElement::isParent() const
109 {
110  using namespace EbmlIds;
111  using namespace MatroskaIds;
112  switch(id()) {
113  case Header:
115  case Segment: case SeekHead: case Seek:
116  case SegmentInfo: case ChapterTranslate:
117  case Cluster: case SilentTracks: case BlockGroup: case BlockAdditions: case BlockMore: case Slices: case TimeSlice: case ReferenceFrame:
120  case Cues: case CuePoint: case CueTrackPositions: case CueReference:
121  case Attachments: case AttachedFile:
123  case Tags: case MatroskaIds::Tag: case Targets: case SimpleTag:
124  return true;
125  default:
126  return false;
127  }
128 }
129 
133 inline bool EbmlElement::isPadding() const
134 {
135  return id() == EbmlIds::Void;
136 }
137 
142 inline uint64 EbmlElement::firstChildOffset() const
143 {
144  return isParent() ? (idLength() + sizeLength()) : 0;
145 }
146 
147 }
148 
149 
150 #endif // EBMLELEMENT_H
FileElementTraits< ImplementationType >::identifierType identifierType
Specifies the type used to store identifiers.
uint32 identifierType
The type used to store element IDs is an unsigned 32-bit integer.
Definition: ebmlelement.h:37
Implementation of GenericContainer<MediaFileInfo, MatroskaTag, MatroskaTrack, EbmlElement>.
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:50
uint64 dataSizeType
The type used to store element sizes is an unsigned 64-bit integer.
Definition: ebmlelement.h:42
MatroskaContainer containerType
The container type used to store such elements is MatroskaContainer.
Definition: ebmlelement.h:32
EbmlElement implementationType
The implementation type is EbmlElement.
Definition: ebmlelement.h:47
static uint64 bytesToBeSkipped
Specifies the number of bytes to be skipped till a valid EBML element is found in the stream...
Definition: ebmlelement.h:76
The GenericFileElement class helps to parse binary files which consist of an arboreal element strucut...
std::string idToString() const
Converts the specified EBML ID to a printable string.
Definition: ebmlelement.h:91
uint32 idLength() const
Returns the length of the id denotation in byte.
const identifierType & id() const
Returns the element ID.
TAG_PARSER_EXPORT const char * matroskaIdName(uint32 matroskaId)
Returns a string for the specified matroskaId if known; otherwise returns an empty string...
Definition: matroskaid.cpp:24
uint64 firstChildOffset() const
Returns the offset of the first child of the element.
Definition: ebmlelement.h:142
Defines traits for the specified ImplementationType.
bool isParent() const
Returns an indication whether the element is a parent element.
Definition: ebmlelement.h:108
bool isPadding() const
Returns an indication whether the element is considered as padding.
Definition: ebmlelement.h:133
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
uint32 sizeLength() const
Returns the length of the size denotation of the element in byte.