Tag Parser  9.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
abstractcontainer.cpp
Go to the documentation of this file.
1 #include "./abstractcontainer.h"
2 #include "./diagnostics.h"
3 
4 using namespace std;
5 using namespace CppUtilities;
6 
7 namespace TagParser {
8 
17 AbstractContainer::AbstractContainer(iostream &stream, std::uint64_t startOffset)
18  : m_version(0)
19  , m_readVersion(0)
20  , m_doctypeVersion(0)
21  , m_doctypeReadVersion(0)
22  , m_timeScale(0)
23  , m_headerParsed(false)
24  , m_tagsParsed(false)
25  , m_tracksParsed(false)
26  , m_tracksAltered(false)
27  , m_chaptersParsed(false)
28  , m_attachmentsParsed(false)
29  , m_startOffset(startOffset)
30  , m_stream(&stream)
31  , m_reader(BinaryReader(m_stream))
32  , m_writer(BinaryWriter(m_stream))
33 {
34 }
35 
43 {
44 }
45 
56 {
57  if (!isHeaderParsed()) {
58  removeAllTags();
60  internalParseHeader(diag);
61  m_headerParsed = true;
62  }
63 }
64 
83 {
84  if (!areTagsParsed()) {
85  parseHeader(diag);
86  internalParseTags(diag);
87  m_tagsParsed = true;
88  }
89 }
90 
107 {
108  if (!areTracksParsed()) {
109  parseHeader(diag);
110  internalParseTracks(diag);
111  m_tracksParsed = true;
112  m_tracksAltered = false;
113  }
114 }
115 
127 {
128  if (!areChaptersParsed()) {
129  parseHeader(diag);
130  internalParseChapters(diag);
131  m_chaptersParsed = true;
132  }
133 }
134 
146 {
147  if (!areAttachmentsParsed()) {
148  parseHeader(diag);
150  m_attachmentsParsed = true;
151  }
152 }
153 
162 {
163  internalMakeFile(diag, progress);
164 }
165 
170 {
171  return false;
172 }
173 
184 {
185  CPP_UTILITIES_UNUSED(diag);
186  return ElementPosition::Keep;
187 }
188 
198 {
199  CPP_UTILITIES_UNUSED(diag);
200  throw NotImplementedException();
201 }
202 
212 {
213  CPP_UTILITIES_UNUSED(diag);
214  throw NotImplementedException();
215 }
216 
226 {
227  CPP_UTILITIES_UNUSED(diag);
228  throw NotImplementedException();
229 }
230 
240 {
241  CPP_UTILITIES_UNUSED(diag);
242  throw NotImplementedException();
243 }
244 
254 {
255  CPP_UTILITIES_UNUSED(diag);
256  throw NotImplementedException();
257 }
258 
268 {
269  CPP_UTILITIES_UNUSED(diag);
270  CPP_UTILITIES_UNUSED(progress);
271  throw NotImplementedException();
272 }
273 
285 {
286  return nullptr;
287 }
288 
295 {
296  CPP_UTILITIES_UNUSED(index);
297  return nullptr;
298 }
299 
306 {
307  return 0;
308 }
309 
324 {
325  CPP_UTILITIES_UNUSED(tag);
326  return false;
327 }
328 
340 {
341 }
342 
353 {
354  CPP_UTILITIES_UNUSED(diag);
355  return ElementPosition::Keep;
356 }
357 
364 {
365  CPP_UTILITIES_UNUSED(index);
366  return nullptr;
367 }
368 
373 {
374  return 0;
375 }
376 
392 {
393  CPP_UTILITIES_UNUSED(track);
394  return false;
395 }
396 
411 {
412 }
413 
420 {
421  CPP_UTILITIES_UNUSED(index);
422  return nullptr;
423 }
424 
429 {
430  return 0;
431 }
432 
439 {
440  return nullptr;
441 }
442 
449 {
450  CPP_UTILITIES_UNUSED(index);
451  return nullptr;
452 }
453 
458 {
459  return 0;
460 }
461 
466 {
467  return false;
468 }
469 
474 {
475  return 1;
476 }
477 
482 {
483  m_headerParsed = false;
484  m_tagsParsed = false;
485  m_tracksParsed = false;
486  m_tracksAltered = false;
487  m_chaptersParsed = false;
488  m_attachmentsParsed = false;
489  m_version = 0;
490  m_readVersion = 0;
491  m_doctypeVersion = 0;
493  m_timeScale = 0;
494  m_titles.clear();
495 }
496 
497 } // namespace TagParser
TagParser::AbstractChapter
The AbstractChapter class parses chapter information.
Definition: abstractchapter.h:15
TagParser::AbstractAttachment
The AbstractAttachment class parses and stores attachment information.
Definition: abstractattachment.h:105
TagParser::AbstractContainer::removeTag
virtual bool removeTag(Tag *tag)
Removes the specified tag from the container.
Definition: abstractcontainer.cpp:323
TagParser::AbstractContainer::determineTagPosition
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
Definition: abstractcontainer.cpp:352
TagParser::AbstractContainer::parseTags
void parseTags(Diagnostics &diag)
Parses the tag information if not parsed yet.
Definition: abstractcontainer.cpp:82
TagParser::AbstractContainer::parseTracks
void parseTracks(Diagnostics &diag)
Parses the tracks of the file if not parsed yet.
Definition: abstractcontainer.cpp:106
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
Definition: progressfeedback.h:186
TagParser::AbstractContainer::m_version
std::uint64_t m_version
Definition: abstractcontainer.h:99
TagParser::AbstractContainer::m_doctypeReadVersion
std::uint64_t m_doctypeReadVersion
Definition: abstractcontainer.h:103
TagParser::AbstractContainer::chapter
virtual AbstractChapter * chapter(std::size_t index)
Returns the chapter with the specified index.
Definition: abstractcontainer.cpp:419
TagParser::AbstractContainer::tagCount
virtual std::size_t tagCount() const
Returns the number of tags attached to the container.
Definition: abstractcontainer.cpp:305
TagParser::AbstractContainer::areTracksParsed
bool areTracksParsed() const
Returns an indication whether the tracks have been parsed yet.
Definition: abstractcontainer.h:201
TagParser::AbstractContainer::isHeaderParsed
bool isHeaderParsed() const
Returns an indication whether the header has been parsed yet.
Definition: abstractcontainer.h:169
TagParser::Tag
The Tag class is used to store, read and write tag information.
Definition: tag.h:108
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser::AbstractContainer::chapterCount
virtual std::size_t chapterCount() const
Returns the number of chapters the container holds.
Definition: abstractcontainer.cpp:428
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::AbstractContainer::track
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
Definition: abstractcontainer.cpp:363
TagParser::AbstractContainer::m_doctypeVersion
std::uint64_t m_doctypeVersion
Definition: abstractcontainer.h:102
TagParser::AbstractContainer::m_tagsParsed
bool m_tagsParsed
Definition: abstractcontainer.h:111
TagParser::AbstractContainer::internalParseHeader
virtual void internalParseHeader(Diagnostics &diag)
Internally called to parse the header.
Definition: abstractcontainer.cpp:197
TagParser::AbstractContainer::removeAllTags
virtual void removeAllTags()
Removes all tags attached to the container.
Definition: abstractcontainer.cpp:339
TagParser::AbstractContainer::trackCount
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
Definition: abstractcontainer.cpp:372
TagParser::AbstractContainer::internalParseTracks
virtual void internalParseTracks(Diagnostics &diag)
Internally called to parse the tracks.
Definition: abstractcontainer.cpp:225
TagParser::AbstractContainer::internalParseAttachments
virtual void internalParseAttachments(Diagnostics &diag)
Internally called to parse the attachments.
Definition: abstractcontainer.cpp:253
TagParser::AbstractContainer::makeFile
void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Rewrites the file to apply changed tag information.
Definition: abstractcontainer.cpp:161
TagParser::AbstractContainer::m_tracksParsed
bool m_tracksParsed
Definition: abstractcontainer.h:112
TagParser::AbstractContainer::m_tracksAltered
bool m_tracksAltered
Definition: abstractcontainer.h:113
TagParser::ElementPosition::BeforeData
@ BeforeData
CppUtilities
Definition: abstractcontainer.h:15
diagnostics.h
TagParser::AbstractContainer::createAttachment
virtual AbstractAttachment * createAttachment()
Creates and returns a new attachment.
Definition: abstractcontainer.cpp:438
TagParser::AbstractContainer::m_attachmentsParsed
bool m_attachmentsParsed
Definition: abstractcontainer.h:115
TagParser::AbstractContainer::parseChapters
void parseChapters(Diagnostics &diag)
Parses the chapters of the file if not parsed yet.
Definition: abstractcontainer.cpp:126
TagParser::AbstractTrack
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:39
TagParser::AbstractContainer::areTagsParsed
bool areTagsParsed() const
Returns an indication whether the tags have been parsed yet.
Definition: abstractcontainer.h:177
TagParser::AbstractContainer::attachmentCount
virtual std::size_t attachmentCount() const
Returns the number of attachments the container holds.
Definition: abstractcontainer.cpp:457
TagParser::AbstractContainer::~AbstractContainer
virtual ~AbstractContainer()
Destroys the container.
Definition: abstractcontainer.cpp:42
TagParser::AbstractContainer::tag
virtual Tag * tag(std::size_t index)
Returns the tag with the specified index.
Definition: abstractcontainer.cpp:294
TagParser::AbstractContainer::areAttachmentsParsed
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
Definition: abstractcontainer.h:193
TagParser::AbstractContainer::supportsTitle
virtual bool supportsTitle() const
Returns whether the title property is supported.
Definition: abstractcontainer.cpp:465
TagParser::AbstractContainer::internalParseChapters
virtual void internalParseChapters(Diagnostics &diag)
Internally called to parse the chapters.
Definition: abstractcontainer.cpp:239
TagParser::AbstractContainer::segmentCount
virtual std::size_t segmentCount() const
Returns the number of segments.
Definition: abstractcontainer.cpp:473
TagParser::AbstractContainer::areChaptersParsed
bool areChaptersParsed() const
Returns an indication whether the chapters have been parsed yet.
Definition: abstractcontainer.h:185
TagParser::AbstractContainer::supportsTrackModifications
virtual bool supportsTrackModifications() const
Returns whether the implementation supports adding or removing of tracks.
Definition: abstractcontainer.cpp:169
TagParser::AbstractContainer::internalParseTags
virtual void internalParseTags(Diagnostics &diag)
Internally called to parse the tags.
Definition: abstractcontainer.cpp:211
TagParser::TagTarget
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:20
TagParser::ElementPosition
ElementPosition
Definition: settings.h:13
TagParser::AbstractContainer::removeAllTracks
virtual void removeAllTracks()
Removes all tracks from the container.
Definition: abstractcontainer.cpp:410
TagParser::AbstractContainer::m_timeScale
std::uint32_t m_timeScale
Definition: abstractcontainer.h:108
TagParser::AbstractContainer::m_headerParsed
bool m_headerParsed
Definition: abstractcontainer.h:110
abstractcontainer.h
TagParser::AbstractContainer::internalMakeFile
virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to make the file.
Definition: abstractcontainer.cpp:267
TagParser::AbstractContainer::removeTrack
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
Definition: abstractcontainer.cpp:391
TagParser::AbstractContainer::reset
virtual void reset()
Discards all parsing results.
Definition: abstractcontainer.cpp:481
TagParser::AbstractContainer::createTag
virtual Tag * createTag(const TagTarget &target=TagTarget())
Creates and returns a tag for the specified target.
Definition: abstractcontainer.cpp:284
TagParser::AbstractContainer::m_titles
std::vector< std::string > m_titles
Definition: abstractcontainer.h:104
TagParser::AbstractContainer::attachment
virtual AbstractAttachment * attachment(std::size_t index)
Returns the attachment with the specified index.
Definition: abstractcontainer.cpp:448
TagParser::AbstractContainer::m_chaptersParsed
bool m_chaptersParsed
Definition: abstractcontainer.h:114
TagParser::AbstractContainer::parseAttachments
void parseAttachments(Diagnostics &diag)
Parses the attachments of the file if not parsed yet.
Definition: abstractcontainer.cpp:145
TagParser::AbstractContainer::m_readVersion
std::uint64_t m_readVersion
Definition: abstractcontainer.h:100
TagParser::AbstractContainer::determineIndexPosition
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
Definition: abstractcontainer.cpp:183
TagParser::NotImplementedException
This exception is thrown when the an operation is invoked that has not been implemented yet.
Definition: exceptions.h:60
TagParser::AbstractContainer::parseHeader
void parseHeader(Diagnostics &diag)
Parses the header if not parsed yet.
Definition: abstractcontainer.cpp:55