tagparser/abstractchapter.cpp

106 lines
2.2 KiB
C++
Raw Permalink Normal View History

2015-09-06 19:57:33 +02:00
#include "./abstractchapter.h"
#include "./progressfeedback.h"
2015-04-22 19:22:01 +02:00
#include <sstream>
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
/// \brief The AbstractChapterPrivate struct contains private fields of the AbstractChapter class.
struct AbstractChapterPrivate {};
2015-04-22 19:22:01 +02:00
/*!
* \class TagParser::AbstractChapter
2015-04-22 19:22:01 +02:00
* \brief The AbstractChapter class parses chapter information.
*/
/*!
* \brief Constructs a new chapter.
*/
2018-03-07 01:17:50 +01:00
AbstractChapter::AbstractChapter()
: m_id(0)
, m_startTime(-1)
, m_endTime(-1)
, m_hidden(false)
, m_enabled(true)
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Destroys the chapter.
*/
AbstractChapter::~AbstractChapter()
2018-03-07 01:17:50 +01:00
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns a label for the chapter.
*/
string AbstractChapter::label() const
{
stringstream ss;
ss << "ID: " << id();
2018-03-07 01:17:50 +01:00
if (!names().empty()) {
2015-04-22 19:22:01 +02:00
ss << ", name: \"" << names().front() << "\"";
}
2018-03-07 01:17:50 +01:00
if (!startTime().isNegative()) {
2015-04-22 19:22:01 +02:00
ss << ", start: " << startTime().toString(TimeSpanOutputFormat::WithMeasures);
}
return ss.str();
}
/*!
* \brief Resets the object to its initial state.
*/
void AbstractChapter::clear()
{
m_id = 0;
m_names.clear();
m_startTime = m_endTime = TimeSpan(-1);
m_tracks.clear();
m_hidden = false;
m_enabled = true;
}
/*!
* \brief Parses the chapter.
*
* Fetches nested chapters but does not parse them.
*
* Clears all previous parsing results.
*/
void AbstractChapter::parse(Diagnostics &diag, AbortableProgressFeedback &progress)
2015-04-22 19:22:01 +02:00
{
clear();
internalParse(diag, progress);
2015-04-22 19:22:01 +02:00
}
/*!
* \brief Parses the chapter and nested chapters recursively.
*
* Clears all previous parsing results.
*/
void AbstractChapter::parseNested(Diagnostics &diag, AbortableProgressFeedback &progress)
2015-04-22 19:22:01 +02:00
{
progress.stopIfAborted();
2015-04-22 19:22:01 +02:00
clear();
internalParse(diag, progress);
2018-03-07 01:17:50 +01:00
for (size_t i = 0, count = nestedChapterCount(); i < count; ++i) {
nestedChapter(i)->parseNested(diag, progress);
2015-04-22 19:22:01 +02:00
}
}
/*!
* \fn AbstractChapter::internalParse()
* \brief Internally called to parse the chapter.
*
* Must be implemented when subclassing.
*
* \throws Throws Failure or a derived class when a parsing error occurs.
* \throws Throws std::ios_base::failure when an IO error occurs.
*/
2018-03-07 01:17:50 +01:00
} // namespace TagParser