Tag Parser: abstractcontainer.cpp Source File

Tag Parser 12.5.2 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
abstractcontainer.cpp
Go to the documentation of this file.
1#include "./abstractcontainer.h"
2#include "./diagnostics.h"
3
4using namespace std;
5using namespace CppUtilities;
6
7namespace TagParser {
8
10 struct AbstractContainerPrivate {
11 std::vector<std::string> muxingApps, writingApps;
12};
13
18
22AbstractContainer::AbstractContainer(iostream &stream, std::uint64_t startOffset)
23 : m_version(0)
24 , m_readVersion(0)
25 , m_doctypeVersion(0)
26 , m_doctypeReadVersion(0)
27 , m_timeScale(0)
28 , m_headerParsed(false)
29 , m_tagsParsed(false)
30 , m_tracksParsed(false)
31 , m_tracksAltered(false)
32 , m_chaptersParsed(false)
33 , m_attachmentsParsed(false)
34 , m_startOffset(startOffset)
35 , m_stream(&stream)
36 , m_reader(BinaryReader(m_stream))
37 , m_writer(BinaryWriter(m_stream))
38{
39}
40
47AbstractContainer::~AbstractContainer()
48{
49}
50
60 void AbstractContainer::parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
61{
62 if (!isHeaderParsed()) {
63 removeAllTags();
64 removeAllTracks();
65 internalParseHeader(diag, progress);
66 m_headerParsed = true;
67 }
68}
69
87 void AbstractContainer::parseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
88{
89 if (!areTagsParsed()) {
90 parseHeader(diag, progress);
91 internalParseTags(diag, progress);
92 m_tagsParsed = true;
93 }
94}
95
111 void AbstractContainer::parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
112{
113 if (!areTracksParsed()) {
114 parseHeader(diag, progress);
115 internalParseTracks(diag, progress);
116 m_tracksParsed = true;
117 m_tracksAltered = false;
118 }
119}
120
131 void AbstractContainer::parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
132{
133 if (!areChaptersParsed()) {
134 parseHeader(diag, progress);
135 internalParseChapters(diag, progress);
136 m_chaptersParsed = true;
137 }
138}
139
150 void AbstractContainer::parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
151{
152 if (!areAttachmentsParsed()) {
153 parseHeader(diag, progress);
154 internalParseAttachments(diag, progress);
155 m_attachmentsParsed = true;
156 }
157}
158
166 void AbstractContainer::makeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
167{
168 internalMakeFile(diag, progress);
169}
170
174 bool AbstractContainer::supportsTrackModifications() const
175{
176 return false;
177}
178
188 ElementPosition AbstractContainer::determineIndexPosition(Diagnostics &diag) const
189{
190 CPP_UTILITIES_UNUSED(diag);
191 return ElementPosition::Keep;
192}
193
202 void AbstractContainer::internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
203{
204 CPP_UTILITIES_UNUSED(diag);
205 CPP_UTILITIES_UNUSED(progress);
206 throw NotImplementedException();
207}
208
217 void AbstractContainer::internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
218{
219 CPP_UTILITIES_UNUSED(diag);
220 CPP_UTILITIES_UNUSED(progress);
221 throw NotImplementedException();
222}
223
232 void AbstractContainer::internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
233{
234 CPP_UTILITIES_UNUSED(diag);
235 CPP_UTILITIES_UNUSED(progress);
236 throw NotImplementedException();
237}
238
247 void AbstractContainer::internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
248{
249 CPP_UTILITIES_UNUSED(diag);
250 CPP_UTILITIES_UNUSED(progress);
251 throw NotImplementedException();
252}
253
262 void AbstractContainer::internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
263{
264 CPP_UTILITIES_UNUSED(diag);
265 CPP_UTILITIES_UNUSED(progress);
266 throw NotImplementedException();
267}
268
277 void AbstractContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
278{
279 CPP_UTILITIES_UNUSED(diag);
280 CPP_UTILITIES_UNUSED(progress);
281 throw NotImplementedException();
282}
283
294 Tag *AbstractContainer::createTag(const TagTarget &)
295{
296 return nullptr;
297}
298
304 Tag *AbstractContainer::tag(size_t index)
305{
306 CPP_UTILITIES_UNUSED(index);
307 return nullptr;
308}
309
315 size_t AbstractContainer::tagCount() const
316{
317 return 0;
318}
319
333 bool AbstractContainer::removeTag(Tag *tag)
334{
335 CPP_UTILITIES_UNUSED(tag);
336 return false;
337}
338
349 void AbstractContainer::removeAllTags()
350{
351}
352
362 ElementPosition AbstractContainer::determineTagPosition(Diagnostics &diag) const
363{
364 CPP_UTILITIES_UNUSED(diag);
365 return ElementPosition::Keep;
366}
367
373 AbstractTrack *AbstractContainer::track(size_t index)
374{
375 CPP_UTILITIES_UNUSED(index);
376 return nullptr;
377}
378
382 size_t AbstractContainer::trackCount() const
383{
384 return 0;
385}
386
401 bool AbstractContainer::removeTrack(AbstractTrack *track)
402{
403 CPP_UTILITIES_UNUSED(track);
404 return false;
405}
406
420 void AbstractContainer::removeAllTracks()
421{
422}
423
429 AbstractChapter *AbstractContainer::chapter(size_t index)
430{
431 CPP_UTILITIES_UNUSED(index);
432 return nullptr;
433}
434
438 size_t AbstractContainer::chapterCount() const
439{
440 return 0;
441}
442
448 AbstractAttachment *AbstractContainer::createAttachment()
449{
450 return nullptr;
451}
452
458 AbstractAttachment *AbstractContainer::attachment(size_t index)
459{
460 CPP_UTILITIES_UNUSED(index);
461 return nullptr;
462}
463
467 size_t AbstractContainer::attachmentCount() const
468{
469 return 0;
470}
471
475 bool AbstractContainer::supportsTitle() const
476{
477 return false;
478}
479
483 const std::vector<std::string> &AbstractContainer::muxingApplications() const
484{
485 static const auto empty = std::vector<std::string>();
486 return m_p ? m_p->muxingApps : empty;
487}
488
492std::vector<std::string> &AbstractContainer::muxingApplications()
493{
494 return p()->muxingApps;
495}
496
500 const std::vector<std::string> &AbstractContainer::writingApplications() const
501{
502 static const auto empty = std::vector<std::string>();
503 return m_p ? m_p->writingApps : empty;
504}
505
509std::vector<std::string> &AbstractContainer::writingApplications()
510{
511 return p()->writingApps;
512}
513
517 size_t AbstractContainer::segmentCount() const
518{
519 return 1;
520}
521
525 void AbstractContainer::reset()
526{
527 m_headerParsed = false;
528 m_tagsParsed = false;
529 m_tracksParsed = false;
530 m_tracksAltered = false;
531 m_chaptersParsed = false;
532 m_attachmentsParsed = false;
533 m_version = 0;
534 m_readVersion = 0;
535 m_doctypeVersion = 0;
536 m_doctypeReadVersion = 0;
537 m_timeScale = 0;
538 m_titles.clear();
539}
540
544std::unique_ptr<AbstractContainerPrivate> &AbstractContainer::p()
545{
546 if (!m_p) {
547 m_p = std::make_unique<AbstractContainerPrivate>();
548 }
549 return m_p;
550}
551
552} // namespace TagParser
abstractcontainer.h
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
Definition progressfeedback.h:186
TagParser::AbstractAttachment
The AbstractAttachment class parses and stores attachment information.
Definition abstractattachment.h:107
TagParser::AbstractChapter
The AbstractChapter class parses chapter information.
Definition abstractchapter.h:18
TagParser::AbstractContainer::removeTrack
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
Definition abstractcontainer.cpp:401
TagParser::AbstractContainer::areAttachmentsParsed
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
Definition abstractcontainer.h:202
TagParser::AbstractContainer::stream
std::iostream & stream()
Returns the related stream.
Definition abstractcontainer.h:136
TagParser::AbstractContainer::removeAllTags
virtual void removeAllTags()
Removes all tags attached to the container.
Definition abstractcontainer.cpp:349
TagParser::AbstractContainer::startOffset
std::uint64_t startOffset() const
Returns the start offset in the related stream.
Definition abstractcontainer.h:154
TagParser::AbstractContainer::m_tagsParsed
bool m_tagsParsed
Definition abstractcontainer.h:117
TagParser::AbstractContainer::internalMakeFile
virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to make the file.
Definition abstractcontainer.cpp:277
TagParser::AbstractContainer::m_attachmentsParsed
bool m_attachmentsParsed
Definition abstractcontainer.h:121
TagParser::AbstractContainer::internalParseAttachments
virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the attachments.
Definition abstractcontainer.cpp:262
TagParser::AbstractContainer::m_titles
std::vector< std::string > m_titles
Definition abstractcontainer.h:110
TagParser::AbstractContainer::parseTracks
void parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the tracks of the file if not parsed yet.
Definition abstractcontainer.cpp:111
TagParser::AbstractContainer::tag
virtual Tag * tag(std::size_t index)
Returns the tag with the specified index.
Definition abstractcontainer.cpp:304
TagParser::AbstractContainer::~AbstractContainer
virtual ~AbstractContainer()
Destroys the container.
Definition abstractcontainer.cpp:47
TagParser::AbstractContainer::areTracksParsed
bool areTracksParsed() const
Returns an indication whether the tracks have been parsed yet.
Definition abstractcontainer.h:210
TagParser::AbstractContainer::segmentCount
virtual std::size_t segmentCount() const
Returns the number of segments.
Definition abstractcontainer.cpp:517
TagParser::AbstractContainer::attachmentCount
virtual std::size_t attachmentCount() const
Returns the number of attachments the container holds.
Definition abstractcontainer.cpp:467
TagParser::AbstractContainer::supportsTrackModifications
virtual bool supportsTrackModifications() const
Returns whether the implementation supports adding or removing of tracks.
Definition abstractcontainer.cpp:174
TagParser::AbstractContainer::writingApplications
const std::vector< std::string > & writingApplications() const
Returns the writing applications specified as meta-data.
Definition abstractcontainer.cpp:500
TagParser::AbstractContainer::chapter
virtual AbstractChapter * chapter(std::size_t index)
Returns the chapter with the specified index.
Definition abstractcontainer.cpp:429
TagParser::AbstractContainer::muxingApplications
const std::vector< std::string > & muxingApplications() const
Returns the muxing applications specified as meta-data.
Definition abstractcontainer.cpp:483
TagParser::AbstractContainer::isHeaderParsed
bool isHeaderParsed() const
Returns an indication whether the header has been parsed yet.
Definition abstractcontainer.h:178
TagParser::AbstractContainer::reset
virtual void reset()
Discards all parsing results.
Definition abstractcontainer.cpp:525
TagParser::AbstractContainer::makeFile
void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Rewrites the file to apply changed tag information.
Definition abstractcontainer.cpp:166
TagParser::AbstractContainer::parseChapters
void parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the chapters of the file if not parsed yet.
Definition abstractcontainer.cpp:131
TagParser::AbstractContainer::internalParseChapters
virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the chapters.
Definition abstractcontainer.cpp:247
TagParser::AbstractContainer::m_chaptersParsed
bool m_chaptersParsed
Definition abstractcontainer.h:120
TagParser::AbstractContainer::createAttachment
virtual AbstractAttachment * createAttachment()
Creates and returns a new attachment.
Definition abstractcontainer.cpp:448
TagParser::AbstractContainer::removeTag
virtual bool removeTag(Tag *tag)
Removes the specified tag from the container.
Definition abstractcontainer.cpp:333
TagParser::AbstractContainer::parseHeader
void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the header if not parsed yet.
Definition abstractcontainer.cpp:60
TagParser::AbstractContainer::determineTagPosition
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
Definition abstractcontainer.cpp:362
TagParser::AbstractContainer::m_doctypeReadVersion
std::uint64_t m_doctypeReadVersion
Definition abstractcontainer.h:109
TagParser::AbstractContainer::track
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
Definition abstractcontainer.cpp:373
TagParser::AbstractContainer::m_readVersion
std::uint64_t m_readVersion
Definition abstractcontainer.h:106
TagParser::AbstractContainer::m_headerParsed
bool m_headerParsed
Definition abstractcontainer.h:116
TagParser::AbstractContainer::determineIndexPosition
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
Definition abstractcontainer.cpp:188
TagParser::AbstractContainer::m_tracksParsed
bool m_tracksParsed
Definition abstractcontainer.h:118
TagParser::AbstractContainer::createTag
virtual Tag * createTag(const TagTarget &target=TagTarget())
Creates and returns a tag for the specified target.
Definition abstractcontainer.cpp:294
TagParser::AbstractContainer::internalParseTags
virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the tags.
Definition abstractcontainer.cpp:217
TagParser::AbstractContainer::tagCount
virtual std::size_t tagCount() const
Returns the number of tags attached to the container.
Definition abstractcontainer.cpp:315
TagParser::AbstractContainer::areTagsParsed
bool areTagsParsed() const
Returns an indication whether the tags have been parsed yet.
Definition abstractcontainer.h:186
TagParser::AbstractContainer::areChaptersParsed
bool areChaptersParsed() const
Returns an indication whether the chapters have been parsed yet.
Definition abstractcontainer.h:194
TagParser::AbstractContainer::trackCount
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
Definition abstractcontainer.cpp:382
TagParser::AbstractContainer::supportsTitle
virtual bool supportsTitle() const
Returns whether the title property is supported.
Definition abstractcontainer.cpp:475
TagParser::AbstractContainer::parseAttachments
void parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the attachments of the file if not parsed yet.
Definition abstractcontainer.cpp:150
TagParser::AbstractContainer::m_doctypeVersion
std::uint64_t m_doctypeVersion
Definition abstractcontainer.h:108
TagParser::AbstractContainer::chapterCount
virtual std::size_t chapterCount() const
Returns the number of chapters the container holds.
Definition abstractcontainer.cpp:438
TagParser::AbstractContainer::AbstractContainer
AbstractContainer(std::iostream &stream, std::uint64_t startOffset)
Constructs a new container for the specified file stream at the specified startOffset.
Definition abstractcontainer.cpp:22
TagParser::AbstractContainer::m_tracksAltered
bool m_tracksAltered
Definition abstractcontainer.h:119
TagParser::AbstractContainer::internalParseHeader
virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the header.
Definition abstractcontainer.cpp:202
TagParser::AbstractContainer::parseTags
void parseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the tag information if not parsed yet.
Definition abstractcontainer.cpp:87
TagParser::AbstractContainer::m_timeScale
std::uint32_t m_timeScale
Definition abstractcontainer.h:114
TagParser::AbstractContainer::m_version
std::uint64_t m_version
Definition abstractcontainer.h:105
TagParser::AbstractContainer::attachment
virtual AbstractAttachment * attachment(std::size_t index)
Returns the attachment with the specified index.
Definition abstractcontainer.cpp:458
TagParser::AbstractContainer::removeAllTracks
virtual void removeAllTracks()
Removes all tracks from the container.
Definition abstractcontainer.cpp:420
TagParser::AbstractContainer::internalParseTracks
virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the tracks.
Definition abstractcontainer.cpp:232
TagParser::AbstractTrack
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition abstracttrack.h:110
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::NotImplementedException
This exception is thrown when the an operation is invoked that has not been implemented yet.
Definition exceptions.h:60
TagParser::TagTarget
The TagTarget class specifies the target of a tag.
Definition tagtarget.h:20
TagParser::Tag
The Tag class is used to store, read and write tag information.
Definition tag.h:179
diagnostics.h
CppUtilities
Definition abstractcontainer.h:16
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::ElementPosition
ElementPosition
Definition settings.h:13
TagParser::ElementPosition::Keep
@ Keep
Definition settings.h:16
TagParser::AbstractContainerPrivate
The AbstractContainerPrivate struct contains private fields of the AbstractContainer class.
Definition abstractcontainer.cpp:10
TagParser::AbstractContainerPrivate::muxingApps
std::vector< std::string > muxingApps
Definition abstractcontainer.cpp:11
TagParser::AbstractContainerPrivate::writingApps
std::vector< std::string > writingApps
Definition abstractcontainer.cpp:11