Tag Parser  9.1.1
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 childs 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  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
106  break;
107  }
108  }
109  break;
111  break;
113  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
114  break;
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
TagParser::TagDataType::TimeSpan
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
Definition: matroskaid.h:307
TagParser::DiagLevel::Warning
TagParser::MatroskaIds::ChapString
Definition: matroskaid.h:327
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
Definition: matroskaid.h:310
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
Definition: matroskaid.h:305
TagParser::GenericFileElement::firstChild
ImplementationType * firstChild()
Returns the first child of the element.
Definition: genericfileelement.h:460
matroskaid.h
TagParser::MatroskaIds::ChapterPhysicalEquiv
Definition: matroskaid.h:313
TagParser::AbstractChapter::m_tracks
std::vector< std::uint64_t > m_tracks
Definition: abstractchapter.h:42
TagParser::MatroskaIds::ChapterSegmentUID
Definition: matroskaid.h:311
TagParser::EbmlElement
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:31
TagParser::MatroskaIds::ChapterTrack
Definition: matroskaid.h:314
TagParser::MatroskaIds::ChapterDisplay
Definition: matroskaid.h:315
CppUtilities
Definition: abstractcontainer.h:15
TagParser::AbstractChapter::m_endTime
CppUtilities::TimeSpan m_endTime
Definition: abstractchapter.h:41
TagParser::MatroskaIds::ChapCountry
Definition: matroskaid.h:327
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:128
TagParser::MatroskaIds::ChapLanguage
Definition: matroskaid.h:327
ebmlelement.h
TagParser::MatroskaIds::ChapterSegmentEditionUID
Definition: matroskaid.h:312
TagParser::MatroskaIds::ChapProcess
Definition: matroskaid.h:316
TagParser::MatroskaChapter::~MatroskaChapter
~MatroskaChapter() override
Destroys the chapter.
Definition: matroskachapter.cpp:32
TagParser::MatroskaIds::ChapterTimeEnd
Definition: matroskaid.h:308
TagParser::MatroskaIds::ChapterFlagHidden
Definition: matroskaid.h:309
TagParser::MatroskaIds::ChapterAtom
Definition: matroskaid.h:298
TagParser::MatroskaIds::ChapterStringUID
Definition: matroskaid.h:306
TagParser::AbstractChapter::m_hidden
bool m_hidden
Definition: abstractchapter.h:43