Tag Parser 12.1.0
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.
2#include "./diagnostics.h"
3
4using namespace std;
5using namespace CppUtilities;
6
7namespace TagParser {
8
11 std::vector<std::string> muxingApps, writingApps;
12};
13
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
50
61{
62 if (!isHeaderParsed()) {
65 internalParseHeader(diag, progress);
66 m_headerParsed = true;
67 }
68}
69
88{
89 if (!areTagsParsed()) {
90 parseHeader(diag, progress);
91 internalParseTags(diag, progress);
92 m_tagsParsed = true;
93 }
94}
95
112{
113 if (!areTracksParsed()) {
114 parseHeader(diag, progress);
115 internalParseTracks(diag, progress);
116 m_tracksParsed = true;
117 m_tracksAltered = false;
118 }
119}
120
132{
133 if (!areChaptersParsed()) {
134 parseHeader(diag, progress);
135 internalParseChapters(diag, progress);
136 m_chaptersParsed = true;
137 }
138}
139
151{
152 if (!areAttachmentsParsed()) {
153 parseHeader(diag, progress);
154 internalParseAttachments(diag, progress);
155 m_attachmentsParsed = true;
156 }
157}
158
167{
168 internalMakeFile(diag, progress);
169}
170
175{
176 return false;
177}
178
189{
190 CPP_UTILITIES_UNUSED(diag);
192}
193
203{
204 CPP_UTILITIES_UNUSED(diag);
205 CPP_UTILITIES_UNUSED(progress);
207}
208
218{
219 CPP_UTILITIES_UNUSED(diag);
220 CPP_UTILITIES_UNUSED(progress);
222}
223
233{
234 CPP_UTILITIES_UNUSED(diag);
235 CPP_UTILITIES_UNUSED(progress);
237}
238
248{
249 CPP_UTILITIES_UNUSED(diag);
250 CPP_UTILITIES_UNUSED(progress);
252}
253
263{
264 CPP_UTILITIES_UNUSED(diag);
265 CPP_UTILITIES_UNUSED(progress);
267}
268
278{
279 CPP_UTILITIES_UNUSED(diag);
280 CPP_UTILITIES_UNUSED(progress);
282}
283
295{
296 return nullptr;
297}
298
305{
306 CPP_UTILITIES_UNUSED(index);
307 return nullptr;
308}
309
316{
317 return 0;
318}
319
334{
335 CPP_UTILITIES_UNUSED(tag);
336 return false;
337}
338
352
363{
364 CPP_UTILITIES_UNUSED(diag);
366}
367
374{
375 CPP_UTILITIES_UNUSED(index);
376 return nullptr;
377}
378
383{
384 return 0;
385}
386
402{
403 CPP_UTILITIES_UNUSED(track);
404 return false;
405}
406
423
430{
431 CPP_UTILITIES_UNUSED(index);
432 return nullptr;
433}
434
439{
440 return 0;
441}
442
452
459{
460 CPP_UTILITIES_UNUSED(index);
461 return nullptr;
462}
463
468{
469 return 0;
470}
471
476{
477 return false;
478}
479
483const 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
500const 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
518{
519 return 1;
520}
521
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;
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
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The AbstractAttachment class parses and stores attachment information.
The AbstractChapter class parses chapter information.
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
virtual void removeAllTags()
Removes all tags attached to the container.
virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to make the file.
virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the attachments.
std::vector< std::string > m_titles
void parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the tracks of the file if not parsed yet.
virtual Tag * tag(std::size_t index)
Returns the tag with the specified index.
virtual ~AbstractContainer()
Destroys the container.
bool areTracksParsed() const
Returns an indication whether the tracks have been parsed yet.
virtual std::size_t segmentCount() const
Returns the number of segments.
virtual std::size_t attachmentCount() const
Returns the number of attachments the container holds.
virtual bool supportsTrackModifications() const
Returns whether the implementation supports adding or removing of tracks.
const std::vector< std::string > & writingApplications() const
Returns the writing applications specified as meta-data.
virtual AbstractChapter * chapter(std::size_t index)
Returns the chapter with the specified index.
const std::vector< std::string > & muxingApplications() const
Returns the muxing applications specified as meta-data.
bool isHeaderParsed() const
Returns an indication whether the header has been parsed yet.
virtual void reset()
Discards all parsing results.
void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Rewrites the file to apply changed tag information.
void parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the chapters of the file if not parsed yet.
virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the chapters.
virtual AbstractAttachment * createAttachment()
Creates and returns a new attachment.
virtual bool removeTag(Tag *tag)
Removes the specified tag from the container.
void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the header if not parsed yet.
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
virtual Tag * createTag(const TagTarget &target=TagTarget())
Creates and returns a tag for the specified target.
virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the tags.
virtual std::size_t tagCount() const
Returns the number of tags attached to the container.
bool areTagsParsed() const
Returns an indication whether the tags have been parsed yet.
bool areChaptersParsed() const
Returns an indication whether the chapters have been parsed yet.
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
virtual bool supportsTitle() const
Returns whether the title property is supported.
void parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the attachments of the file if not parsed yet.
virtual std::size_t chapterCount() const
Returns the number of chapters the container holds.
AbstractContainer(std::iostream &stream, std::uint64_t startOffset)
Constructs a new container for the specified file stream at the specified startOffset.
virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the header.
void parseTags(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the tag information if not parsed yet.
virtual AbstractAttachment * attachment(std::size_t index)
Returns the attachment with the specified index.
virtual void removeAllTracks()
Removes all tracks from the container.
virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the tracks.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
The Diagnostics class is a container for DiagMessage.
This exception is thrown when the an operation is invoked that has not been implemented yet.
Definition exceptions.h:60
The TagTarget class specifies the target of a tag.
Definition tagtarget.h:20
The Tag class is used to store, read and write tag information.
Definition tag.h:166
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
ElementPosition
Definition settings.h:13
The AbstractContainerPrivate struct contains private fields of the AbstractContainer class.
std::vector< std::string > muxingApps
std::vector< std::string > writingApps