2018-03-06 23:09:15 +01:00
|
|
|
#ifndef TAG_PARSER_ABSTRACTCONTAINER_H
|
|
|
|
#define TAG_PARSER_ABSTRACTCONTAINER_H
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "./exceptions.h"
|
2018-03-11 18:57:22 +01:00
|
|
|
#include "./settings.h"
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "./tagtarget.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
#include <c++utilities/chrono/datetime.h>
|
|
|
|
#include <c++utilities/chrono/timespan.h>
|
2015-04-22 19:22:01 +02:00
|
|
|
#include <c++utilities/io/binaryreader.h>
|
|
|
|
#include <c++utilities/io/binarywriter.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
2023-05-11 22:54:24 +02:00
|
|
|
#include <memory>
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2019-06-10 22:49:11 +02:00
|
|
|
namespace CppUtilities {
|
2015-04-22 19:22:01 +02:00
|
|
|
class BinaryReader;
|
|
|
|
class BinaryWriter;
|
2019-06-10 22:49:11 +02:00
|
|
|
} // namespace CppUtilities
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
namespace TagParser {
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
class Tag;
|
|
|
|
class AbstractTrack;
|
|
|
|
class AbstractChapter;
|
|
|
|
class AbstractAttachment;
|
2018-03-05 17:49:29 +01:00
|
|
|
class Diagnostics;
|
|
|
|
class AbortableProgressFeedback;
|
2023-05-11 22:54:24 +02:00
|
|
|
struct AbstractContainerPrivate;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
class TAG_PARSER_EXPORT AbstractContainer {
|
2015-04-22 19:22:01 +02:00
|
|
|
public:
|
|
|
|
virtual ~AbstractContainer();
|
|
|
|
|
|
|
|
std::iostream &stream();
|
|
|
|
void setStream(std::iostream &stream);
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t startOffset() const;
|
2019-06-10 22:49:11 +02:00
|
|
|
CppUtilities::BinaryReader &reader();
|
|
|
|
CppUtilities::BinaryWriter &writer();
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2021-02-04 23:21:50 +01:00
|
|
|
void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
void parseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
void parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
void parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
void parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
|
2018-03-05 17:49:29 +01:00
|
|
|
void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
bool isHeaderParsed() const;
|
|
|
|
bool areTagsParsed() const;
|
|
|
|
bool areTracksParsed() const;
|
|
|
|
bool areChaptersParsed() const;
|
|
|
|
bool areAttachmentsParsed() const;
|
|
|
|
|
|
|
|
virtual Tag *createTag(const TagTarget &target = TagTarget());
|
|
|
|
virtual Tag *tag(std::size_t index);
|
|
|
|
virtual std::size_t tagCount() const;
|
|
|
|
virtual bool removeTag(Tag *tag);
|
|
|
|
virtual void removeAllTags();
|
2018-03-05 17:49:29 +01:00
|
|
|
virtual ElementPosition determineTagPosition(Diagnostics &diag) const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
virtual AbstractTrack *track(std::size_t index);
|
|
|
|
virtual std::size_t trackCount() const;
|
|
|
|
virtual bool removeTrack(AbstractTrack *track);
|
|
|
|
virtual void removeAllTracks();
|
|
|
|
virtual bool supportsTrackModifications() const;
|
2018-03-05 17:49:29 +01:00
|
|
|
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
virtual AbstractChapter *chapter(std::size_t index);
|
|
|
|
virtual std::size_t chapterCount() const;
|
|
|
|
|
|
|
|
virtual AbstractAttachment *createAttachment();
|
|
|
|
virtual AbstractAttachment *attachment(std::size_t index);
|
|
|
|
virtual std::size_t attachmentCount() const;
|
|
|
|
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t version() const;
|
|
|
|
std::uint64_t readVersion() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
const std::string &documentType() const;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t doctypeVersion() const;
|
|
|
|
std::uint64_t doctypeReadVersion() const;
|
2015-10-14 19:42:48 +02:00
|
|
|
const std::vector<std::string> &titles() const;
|
2021-01-30 21:53:06 +01:00
|
|
|
void setTitle(std::string_view title, std::size_t segmentIndex = 0);
|
2015-12-27 19:51:57 +01:00
|
|
|
virtual bool supportsTitle() const;
|
|
|
|
virtual std::size_t segmentCount() const;
|
2019-06-10 22:49:11 +02:00
|
|
|
CppUtilities::TimeSpan duration() const;
|
|
|
|
CppUtilities::DateTime creationTime() const;
|
|
|
|
CppUtilities::DateTime modificationTime() const;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint32_t timeScale() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
protected:
|
2019-03-13 19:06:42 +01:00
|
|
|
AbstractContainer(std::iostream &stream, std::uint64_t startOffset);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2021-02-04 23:21:50 +01:00
|
|
|
virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
|
|
|
|
virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
|
2018-03-05 17:49:29 +01:00
|
|
|
virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t m_version;
|
|
|
|
std::uint64_t m_readVersion;
|
2015-04-22 19:22:01 +02:00
|
|
|
std::string m_doctype;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t m_doctypeVersion;
|
|
|
|
std::uint64_t m_doctypeReadVersion;
|
2015-10-14 19:42:48 +02:00
|
|
|
std::vector<std::string> m_titles;
|
2019-06-10 22:49:11 +02:00
|
|
|
CppUtilities::TimeSpan m_duration;
|
|
|
|
CppUtilities::DateTime m_creationTime;
|
|
|
|
CppUtilities::DateTime m_modificationTime;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint32_t m_timeScale;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
bool m_headerParsed;
|
|
|
|
bool m_tagsParsed;
|
|
|
|
bool m_tracksParsed;
|
|
|
|
bool m_tracksAltered;
|
|
|
|
bool m_chaptersParsed;
|
|
|
|
bool m_attachmentsParsed;
|
|
|
|
|
|
|
|
private:
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t m_startOffset;
|
2015-04-22 19:22:01 +02:00
|
|
|
std::iostream *m_stream;
|
2019-06-10 22:49:11 +02:00
|
|
|
CppUtilities::BinaryReader m_reader;
|
|
|
|
CppUtilities::BinaryWriter m_writer;
|
2023-05-11 22:54:24 +02:00
|
|
|
std::unique_ptr<AbstractContainerPrivate> m_p;
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the related stream.
|
|
|
|
*/
|
|
|
|
inline std::iostream &AbstractContainer::stream()
|
|
|
|
{
|
|
|
|
return *m_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the related stream.
|
|
|
|
*/
|
|
|
|
inline void AbstractContainer::setStream(std::iostream &stream)
|
|
|
|
{
|
|
|
|
m_stream = &stream;
|
|
|
|
m_reader.setStream(m_stream);
|
|
|
|
m_writer.setStream(m_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the start offset in the related stream.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t AbstractContainer::startOffset() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_startOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the related BinaryReader.
|
|
|
|
*/
|
2019-06-10 22:49:11 +02:00
|
|
|
inline CppUtilities::BinaryReader &AbstractContainer::reader()
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_reader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the related BinaryWriter.
|
|
|
|
*/
|
2019-06-10 22:49:11 +02:00
|
|
|
inline CppUtilities::BinaryWriter &AbstractContainer::writer()
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_writer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the header has been parsed yet.
|
|
|
|
*/
|
|
|
|
inline bool AbstractContainer::isHeaderParsed() const
|
|
|
|
{
|
|
|
|
return m_headerParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the tags have been parsed yet.
|
|
|
|
*/
|
|
|
|
inline bool AbstractContainer::areTagsParsed() const
|
|
|
|
{
|
|
|
|
return m_tagsParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the chapters have been parsed yet.
|
|
|
|
*/
|
|
|
|
inline bool AbstractContainer::areChaptersParsed() const
|
|
|
|
{
|
|
|
|
return m_chaptersParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the attachments have been parsed yet.
|
|
|
|
*/
|
|
|
|
inline bool AbstractContainer::areAttachmentsParsed() const
|
|
|
|
{
|
|
|
|
return m_attachmentsParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the tracks have been parsed yet.
|
|
|
|
*/
|
|
|
|
inline bool AbstractContainer::areTracksParsed() const
|
|
|
|
{
|
|
|
|
return m_tracksParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the version if known; otherwise returns 0.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t AbstractContainer::version() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the "read version" if known; otherwise returns 0.
|
|
|
|
*
|
|
|
|
* This is the minimum version a parser has to support to read the file.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t AbstractContainer::readVersion() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_readVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns a string that describes the document type if available; otherwise returns an empty string.
|
|
|
|
*/
|
|
|
|
inline const std::string &AbstractContainer::documentType() const
|
|
|
|
{
|
|
|
|
return m_doctype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the document type version if known; otherwise returns 0.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t AbstractContainer::doctypeVersion() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_doctypeVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the document type "read version" if known; otherwise returns 0.
|
|
|
|
*
|
|
|
|
* This is the minimum version an interpreter has to support to read the file.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t AbstractContainer::doctypeReadVersion() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_doctypeReadVersion;
|
|
|
|
}
|
|
|
|
|
2015-10-14 19:42:48 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns the title(s) of the file.
|
|
|
|
* \remarks
|
|
|
|
* - If the container does not support titles an empty vector will be returned.
|
|
|
|
* - If there are multiple segments, the title of each segment is returned.
|
|
|
|
* \sa setTitle()
|
|
|
|
*/
|
|
|
|
inline const std::vector<std::string> &AbstractContainer::titles() const
|
|
|
|
{
|
|
|
|
return m_titles;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
/*!
|
2015-10-14 19:42:48 +02:00
|
|
|
* \brief Sets the title for the specified segment.
|
|
|
|
* \remarks The title is ignored if it is not supported by the concrete container format.
|
|
|
|
* \throws Throws out_of_range if the segment does not exist.
|
|
|
|
* \sa titles()
|
2015-04-22 19:22:01 +02:00
|
|
|
*/
|
2021-01-30 21:53:06 +01:00
|
|
|
inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
2015-10-14 19:42:48 +02:00
|
|
|
m_titles.at(segmentIndex) = title;
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the duration of the file if known; otherwise returns a time span of zero ticks.
|
|
|
|
*/
|
2019-06-10 22:49:11 +02:00
|
|
|
inline CppUtilities::TimeSpan AbstractContainer::duration() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the creation time of the file if known; otherwise the returned date time is null.
|
|
|
|
*/
|
2019-06-10 22:49:11 +02:00
|
|
|
inline CppUtilities::DateTime AbstractContainer::creationTime() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_creationTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the modification time of the file if known; otherwise the returned date time is null.
|
|
|
|
*/
|
2019-06-10 22:49:11 +02:00
|
|
|
inline CppUtilities::DateTime AbstractContainer::modificationTime() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_modificationTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the time scale of the file if known; otherwise returns 0.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint32_t AbstractContainer::timeScale() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_timeScale;
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
} // namespace TagParser
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
#endif // TAG_PARSER_ABSTRACTCONTAINER_H
|