Tag Parser  10.0.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, progress);
61  m_headerParsed = true;
62  }
63 }
64 
83 {
84  if (!areTagsParsed()) {
85  parseHeader(diag, progress);
86  internalParseTags(diag, progress);
87  m_tagsParsed = true;
88  }
89 }
90 
107 {
108  if (!areTracksParsed()) {
109  parseHeader(diag, progress);
110  internalParseTracks(diag, progress);
111  m_tracksParsed = true;
112  m_tracksAltered = false;
113  }
114 }
115 
127 {
128  if (!areChaptersParsed()) {
129  parseHeader(diag, progress);
130  internalParseChapters(diag, progress);
131  m_chaptersParsed = true;
132  }
133 }
134 
146 {
147  if (!areAttachmentsParsed()) {
148  parseHeader(diag, progress);
149  internalParseAttachments(diag, progress);
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  CPP_UTILITIES_UNUSED(progress);
201  throw NotImplementedException();
202 }
203 
213 {
214  CPP_UTILITIES_UNUSED(diag);
215  CPP_UTILITIES_UNUSED(progress);
216  throw NotImplementedException();
217 }
218 
228 {
229  CPP_UTILITIES_UNUSED(diag);
230  CPP_UTILITIES_UNUSED(progress);
231  throw NotImplementedException();
232 }
233 
243 {
244  CPP_UTILITIES_UNUSED(diag);
245  CPP_UTILITIES_UNUSED(progress);
246  throw NotImplementedException();
247 }
248 
258 {
259  CPP_UTILITIES_UNUSED(diag);
260  CPP_UTILITIES_UNUSED(progress);
261  throw NotImplementedException();
262 }
263 
273 {
274  CPP_UTILITIES_UNUSED(diag);
275  CPP_UTILITIES_UNUSED(progress);
276  throw NotImplementedException();
277 }
278 
290 {
291  return nullptr;
292 }
293 
300 {
301  CPP_UTILITIES_UNUSED(index);
302  return nullptr;
303 }
304 
311 {
312  return 0;
313 }
314 
329 {
330  CPP_UTILITIES_UNUSED(tag);
331  return false;
332 }
333 
345 {
346 }
347 
358 {
359  CPP_UTILITIES_UNUSED(diag);
360  return ElementPosition::Keep;
361 }
362 
369 {
370  CPP_UTILITIES_UNUSED(index);
371  return nullptr;
372 }
373 
378 {
379  return 0;
380 }
381 
397 {
398  CPP_UTILITIES_UNUSED(track);
399  return false;
400 }
401 
416 {
417 }
418 
425 {
426  CPP_UTILITIES_UNUSED(index);
427  return nullptr;
428 }
429 
434 {
435  return 0;
436 }
437 
444 {
445  return nullptr;
446 }
447 
454 {
455  CPP_UTILITIES_UNUSED(index);
456  return nullptr;
457 }
458 
463 {
464  return 0;
465 }
466 
471 {
472  return false;
473 }
474 
479 {
480  return 1;
481 }
482 
487 {
488  m_headerParsed = false;
489  m_tagsParsed = false;
490  m_tracksParsed = false;
491  m_tracksAltered = false;
492  m_chaptersParsed = false;
493  m_attachmentsParsed = false;
494  m_version = 0;
495  m_readVersion = 0;
496  m_doctypeVersion = 0;
498  m_timeScale = 0;
499  m_titles.clear();
500 }
501 
502 } // 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.
virtual AbstractChapter * chapter(std::size_t index)
Returns the chapter with the specified index.
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.
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...
Definition: abstracttrack.h:65
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
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:108
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
ElementPosition
Definition: settings.h:13