Tag Parser  9.4.0
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 CppUtilities;
13 
14 namespace TagParser {
15 
24 MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement)
25  : m_chapterAtomElement(chapterAtomElement)
26 {
27 }
28 
33 {
34 }
35 
43 {
44  // clear previous values and status
45  static const string context("parsing \"ChapterAtom\"-element");
46  clear();
47  // iterate through children of "ChapterAtom"-element
48  for (EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
49  chapterAtomChild->parse(diag);
50  switch (chapterAtomChild->id()) {
52  m_id = chapterAtomChild->readUInteger();
53  break;
55  break;
57  m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
58  break;
60  m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
61  break;
63  m_hidden = chapterAtomChild->readUInteger() == 1;
64  break;
66  m_enabled = chapterAtomChild->readUInteger() == 1;
67  break;
71  break;
73  for (EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement;
74  chapterTrackElement = chapterTrackElement->nextSibling()) {
75  chapterTrackElement->parse(diag);
76  switch (chapterTrackElement->id()) {
78  m_tracks.emplace_back(chapterTrackElement->readUInteger());
79  break;
80  default:
81  diag.emplace_back(DiagLevel::Warning,
82  "\"ChapterTrack\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.",
83  context);
84  }
85  }
86  break;
88  m_names.emplace_back();
89  for (EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement;
90  chapterDisplayElement = chapterDisplayElement->nextSibling()) {
91  chapterDisplayElement->parse(diag);
92  switch (chapterDisplayElement->id()) {
94  if (m_names.back().empty()) {
95  m_names.back().assign(chapterDisplayElement->readString());
96  } else {
97  diag.emplace_back(DiagLevel::Warning,
98  "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
99  }
100  break;
102  m_names.back().languages().emplace_back(chapterDisplayElement->readString());
103  break;
105  diag.emplace_back(DiagLevel::Warning,
106  "\"ChapterDisplay\"-element contains a \"ChapLanguageIETF\"-element which is not supported yet. It will be ignored.",
107  context);
108  break;
110  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
111  break;
112  }
113  }
114  break;
116  break;
118  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
119  break;
120  default:
121  diag.emplace_back(DiagLevel::Warning,
122  "\"ChapterAtom\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
123  }
124  }
125  // "eng" is default language
126  for (LocaleAwareString &name : m_names) {
127  if (name.languages().empty()) {
128  name.languages().emplace_back("eng");
129  }
130  }
131 }
132 
134 {
136  m_nestedChapters.clear();
137 }
138 
139 } // namespace TagParser
TagParser::AbstractChapter::clear
virtual void clear()
Resets the object to its initial state.
Definition: abstractchapter.cpp:53
TagParser::MatroskaChapter::internalParse
void internalParse(Diagnostics &diag) override
Parses the "ChapterAtom"-element which has been specified when constructing the object.
Definition: matroskachapter.cpp:42
TagParser::AbstractChapter::m_enabled
bool m_enabled
Definition: abstractchapter.h:44
TagParser::MatroskaIds::ChapterTimeStart
@ ChapterTimeStart
Definition: matroskaid.h:309
TagParser::MatroskaIds::ChapString
@ ChapString
Definition: matroskaid.h:329
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser::LocaleAwareString
The LocaleAwareString class is a standard string with locale information (languages,...
Definition: localeawarestring.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::MatroskaIds::ChapterFlagEnabled
@ ChapterFlagEnabled
Definition: matroskaid.h:312
TagParser::AbstractChapter::m_startTime
CppUtilities::TimeSpan m_startTime
Definition: abstractchapter.h:40
TagParser::AbstractChapter::m_names
std::vector< LocaleAwareString > m_names
Definition: abstractchapter.h:39
TagParser::MatroskaIds::ChapterUID
@ ChapterUID
Definition: matroskaid.h:307
TagParser::GenericFileElement::firstChild
ImplementationType * firstChild()
Returns the first child of the element.
Definition: genericfileelement.h:460
matroskaid.h
TagParser::MatroskaIds::ChapterPhysicalEquiv
@ ChapterPhysicalEquiv
Definition: matroskaid.h:315
TagParser::AbstractChapter::m_tracks
std::vector< std::uint64_t > m_tracks
Definition: abstractchapter.h:42
TagParser::MatroskaIds::ChapterSegmentUID
@ ChapterSegmentUID
Definition: matroskaid.h:313
TagParser::EbmlElement
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:31
TagParser::MatroskaIds::ChapterTrack
@ ChapterTrack
Definition: matroskaid.h:316
TagParser::MatroskaIds::ChapterDisplay
@ ChapterDisplay
Definition: matroskaid.h:317
CppUtilities
Definition: abstractcontainer.h:15
TagParser::AbstractChapter::m_endTime
CppUtilities::TimeSpan m_endTime
Definition: abstractchapter.h:41
TagParser::MatroskaIds::ChapLanguageIETF
@ ChapLanguageIETF
Definition: matroskaid.h:329
TagParser::MatroskaIds::ChapCountry
@ ChapCountry
Definition: matroskaid.h:329
TagParser::AbstractChapter::m_id
std::uint64_t m_id
Definition: abstractchapter.h:38
matroskachapter.h
TagParser::MatroskaChapter::clear
void clear() override
Resets the object to its initial state.
Definition: matroskachapter.cpp:133
TagParser::MatroskaIds::ChapLanguage
@ ChapLanguage
Definition: matroskaid.h:329
ebmlelement.h
TagParser::MatroskaIds::ChapterSegmentEditionUID
@ ChapterSegmentEditionUID
Definition: matroskaid.h:314
TagParser::MatroskaIds::ChapProcess
@ ChapProcess
Definition: matroskaid.h:318
TagParser::MatroskaChapter::~MatroskaChapter
~MatroskaChapter() override
Destroys the chapter.
Definition: matroskachapter.cpp:32
TagParser::MatroskaIds::ChapterTimeEnd
@ ChapterTimeEnd
Definition: matroskaid.h:310
TagParser::MatroskaIds::ChapterFlagHidden
@ ChapterFlagHidden
Definition: matroskaid.h:311
TagParser::MatroskaIds::ChapterAtom
@ ChapterAtom
Definition: matroskaid.h:300
TagParser::MatroskaIds::ChapterStringUID
@ ChapterStringUID
Definition: matroskaid.h:308
TagParser::AbstractChapter::m_hidden
bool m_hidden
Definition: abstractchapter.h:43