tagparser/matroska/matroskaeditionentry.cpp

116 lines
3.1 KiB
C++
Raw Permalink Normal View History

2015-09-06 19:57:33 +02:00
#include "./matroskaeditionentry.h"
#include "./ebmlelement.h"
#include "./matroskaid.h"
2015-04-22 19:22:01 +02:00
#include "../diagnostics.h"
2017-01-27 18:59:22 +01:00
#include <c++utilities/conversion/stringbuilder.h>
#include <c++utilities/conversion/stringconversion.h>
2015-04-22 19:22:01 +02:00
2017-02-05 21:02:40 +01:00
#include <memory>
2018-03-07 01:17:50 +01:00
#include <string>
2015-04-22 19:22:01 +02:00
using namespace std;
2019-06-10 22:49:11 +02:00
using namespace CppUtilities;
2015-04-22 19:22:01 +02:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
2016-08-04 00:16:19 +02:00
/*!
* \class MatroskaEditionEntry
* \brief The MatroskaEditionEntry class provides a parser for edition entries in Matroska files.
*/
2015-04-22 19:22:01 +02:00
/*!
* \brief Constructs a new MatroskaEditionEntry for the specified \a editionEntryElement.
*/
2018-03-07 01:17:50 +01:00
MatroskaEditionEntry::MatroskaEditionEntry(EbmlElement *editionEntryElement)
: m_editionEntryElement(editionEntryElement)
, m_id(0)
, m_hidden(false)
, m_default(false)
, m_ordered(false)
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Destroys the MatroskaEditionEntry.
*/
MatroskaEditionEntry::~MatroskaEditionEntry()
2018-03-07 01:17:50 +01:00
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns a label for the entry.
*/
string MatroskaEditionEntry::label() const
{
return argsToString("ID: ", id());
2015-04-22 19:22:01 +02:00
}
/*!
* \brief Parses the "EditionEntry"-element specified when constructing the object.
*
* Fetches the chapters() but does not parse them.
*
* Clears all previous parsing results.
*/
void MatroskaEditionEntry::parse(Diagnostics &diag)
2015-04-22 19:22:01 +02:00
{
// clear previous values and status
static const string context("parsing \"EditionEntry\"-element");
clear();
// iterate through children of "EditionEntry"-element
EbmlElement *entryChild = m_editionEntryElement->firstChild();
2018-03-07 01:17:50 +01:00
while (entryChild) {
entryChild->parse(diag);
2018-03-07 01:17:50 +01:00
switch (entryChild->id()) {
2015-04-22 19:22:01 +02:00
case MatroskaIds::EditionUID:
m_id = entryChild->readUInteger();
break;
case MatroskaIds::EditionFlagHidden:
m_hidden = entryChild->readUInteger() == 1;
break;
case MatroskaIds::EditionFlagDefault:
m_default = entryChild->readUInteger() == 1;
break;
case MatroskaIds::EditionFlagOrdered:
m_ordered = entryChild->readUInteger() == 1;
break;
case MatroskaIds::ChapterAtom:
m_chapters.emplace_back(make_unique<MatroskaChapter>(entryChild));
break;
default:
2018-03-07 01:17:50 +01:00
diag.emplace_back(DiagLevel::Warning,
2021-07-02 03:00:50 +02:00
"\"EditionEntry\"-element contains unknown child element \"" % entryChild->idToString() + "\" which will be ignored.", context);
2015-04-22 19:22:01 +02:00
}
entryChild = entryChild->nextSibling();
}
}
/*!
* \brief Parses the "EditionEntry"-element specified when constructing the object.
2016-08-04 00:16:19 +02:00
* \remarks
* - Parses also fetched chapters and nested chapters.
* - Clears all previous parsing results.
2015-04-22 19:22:01 +02:00
*/
void MatroskaEditionEntry::parseNested(Diagnostics &diag, AbortableProgressFeedback &progress)
2015-04-22 19:22:01 +02:00
{
progress.stopIfAborted();
parse(diag);
2018-03-07 01:17:50 +01:00
for (auto &chapter : chapters()) {
chapter->parseNested(diag, progress);
2015-04-22 19:22:01 +02:00
}
}
/*!
* \brief Resets the object to its initial state.
*/
void MatroskaEditionEntry::clear()
{
m_id = 0;
m_hidden = m_default = m_ordered = false;
m_chapters.clear();
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser