Tag Parser  7.0.3
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
matroskachapter.cpp
Go to the documentation of this file.
1 #include "./matroskachapter.h"
2 #include "./ebmlelement.h"
3 #include "./matroskaid.h"
4 
5 #include "../diagnostics.h"
6 
7 #include <c++utilities/conversion/stringbuilder.h>
8 
9 #include <memory>
10 
11 using namespace std;
12 using namespace ChronoUtilities;
13 using namespace ConversionUtilities;
14 
15 namespace TagParser {
16 
25 MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement)
26  : m_chapterAtomElement(chapterAtomElement)
27 {
28 }
29 
34 {
35 }
36 
44 {
45  // clear previous values and status
46  static const string context("parsing \"ChapterAtom\"-element");
47  clear();
48  // iterate through childs of "ChapterAtom"-element
49  for (EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
50  chapterAtomChild->parse(diag);
51  switch (chapterAtomChild->id()) {
53  m_id = chapterAtomChild->readUInteger();
54  break;
56  break;
58  m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
59  break;
61  m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
62  break;
64  m_hidden = chapterAtomChild->readUInteger() == 1;
65  break;
67  m_enabled = chapterAtomChild->readUInteger() == 1;
68  break;
72  break;
74  for (EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement;
75  chapterTrackElement = chapterTrackElement->nextSibling()) {
76  chapterTrackElement->parse(diag);
77  switch (chapterTrackElement->id()) {
79  m_tracks.emplace_back(chapterTrackElement->readUInteger());
80  break;
81  default:
82  diag.emplace_back(DiagLevel::Warning,
83  "\"ChapterTrack\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.",
84  context);
85  }
86  }
87  break;
89  m_names.emplace_back();
90  for (EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement;
91  chapterDisplayElement = chapterDisplayElement->nextSibling()) {
92  chapterDisplayElement->parse(diag);
93  switch (chapterDisplayElement->id()) {
95  if (m_names.back().empty()) {
96  m_names.back().assign(chapterDisplayElement->readString());
97  } else {
98  diag.emplace_back(DiagLevel::Warning,
99  "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
100  }
101  break;
103  m_names.back().languages().emplace_back(chapterDisplayElement->readString());
104  break;
106  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
107  break;
108  }
109  }
110  break;
112  break;
114  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
115  default:
116  diag.emplace_back(DiagLevel::Warning,
117  "\"ChapterAtom\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
118  }
119  }
120  // "eng" is default language
121  for (LocaleAwareString &name : m_names) {
122  if (name.languages().empty()) {
123  name.languages().emplace_back("eng");
124  }
125  }
126 }
127 
129 {
131  m_nestedChapters.clear();
132 }
133 
134 } // namespace TagParser
ChronoUtilities::TimeSpan m_startTime
ImplementationType * firstChild()
Returns the first child of the element.
std::vector< LocaleAwareString > m_names
~MatroskaChapter() override
Destroys the chapter.
STL namespace.
void clear() override
Resets the object to its initial state.
ChronoUtilities::TimeSpan m_endTime
The LocaleAwareString class is a standard string with locale information (languages, countries).
virtual void clear()
Resets the object to its initial state.
std::vector< uint64 > m_tracks
void internalParse(Diagnostics &diag) override
Parses the "ChapterAtom"-element which has been specified when constructing the object.