Tag Parser  6.5.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 <c++utilities/conversion/stringbuilder.h>
6 
7 #include <memory>
8 
9 using namespace std;
10 using namespace ChronoUtilities;
11 using namespace ConversionUtilities;
12 
13 namespace Media {
14 
23 MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement) :
24  m_chapterAtomElement(chapterAtomElement)
25 {}
26 
31 {}
32 
40 {
41  // clear previous values and status
42  static const string context("parsing \"ChapterAtom\"-element");
44  clear();
45  // iterate through childs of "ChapterAtom"-element
46  for(EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
47  chapterAtomChild->parse();
48  switch(chapterAtomChild->id()) {
50  m_id = chapterAtomChild->readUInteger();
51  break;
53  break;
55  m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
56  break;
58  m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
59  break;
61  m_hidden = chapterAtomChild->readUInteger() == 1;
62  break;
64  m_enabled = chapterAtomChild->readUInteger() == 1;
65  break;
69  break;
71  for(EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement; chapterTrackElement = chapterTrackElement->nextSibling()) {
72  chapterTrackElement->parse();
73  switch(chapterTrackElement->id()) {
75  m_tracks.emplace_back(chapterTrackElement->readUInteger());
76  break;
77  default:
78  addNotification(NotificationType::Warning, "\"ChapterTrack\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
79  }
80  }
81  break;
83  m_names.emplace_back();
84  for(EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement; chapterDisplayElement = chapterDisplayElement->nextSibling()) {
85  chapterDisplayElement->parse();
86  switch(chapterDisplayElement->id()) {
88  if(m_names.back().empty()) {
89  m_names.back().assign(chapterDisplayElement->readString());
90  } else {
91  addNotification(NotificationType::Warning, "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
92  }
93  break;
95  m_names.back().languages().emplace_back(chapterDisplayElement->readString());
96  break;
98  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
99  break;
100  }
101  }
102  break;
104  break;
106  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
107  default:
108  addNotification(NotificationType::Warning, "\"ChapterAtom\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
109  }
110  }
111  // "eng" is default language
112  for(LocaleAwareString &name : m_names) {
113  if(name.languages().empty()) {
114  name.languages().emplace_back("eng");
115  }
116  }
117 }
118 
120 {
122  m_nestedChapters.clear();
123 }
124 
125 } // namespace Media
126 
void invalidateStatus()
Invalidates the current status.
void internalParse()
Parses the "ChapterAtom"-element which has been specified when constructing the object.
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:50
std::vector< uint64 > m_tracks
ChronoUtilities::TimeSpan m_startTime
STL namespace.
void addNotification(const Notification &notification)
This method is meant to be called by the derived class to add a notification.
The LocaleAwareString class is a standard string with locale information (languages, countries).
void clear()
Resets the object to its initial state.
ChronoUtilities::TimeSpan m_endTime
~MatroskaChapter()
Destroys the chapter.
implementationType * firstChild()
Returns the first child of the element.
virtual void clear()
Resets the object to its initial state.
std::vector< LocaleAwareString > m_names
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9