Tag Parser: abstractcontainer.h 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.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_ABSTRACTCONTAINER_H
2#define TAG_PARSER_ABSTRACTCONTAINER_H
3
4#include "./exceptions.h"
5#include "./settings.h"
6#include "./tagtarget.h"
7
8#include <c++utilities/chrono/datetime.h>
9#include <c++utilities/chrono/timespan.h>
10#include <c++utilities/io/binaryreader.h>
11#include <c++utilities/io/binarywriter.h>
12
13#include <iostream>
14#include <memory>
15
16 namespace CppUtilities {
17class BinaryReader;
18class BinaryWriter;
19} // namespace CppUtilities
20
21namespace TagParser {
22
23class Tag;
24class AbstractTrack;
25class AbstractChapter;
26class AbstractAttachment;
27class Diagnostics;
28class AbortableProgressFeedback;
29struct AbstractContainerPrivate;
30
31 class TAG_PARSER_EXPORT AbstractContainer {
32public:
33 virtual ~AbstractContainer();
34
35 std::iostream &stream();
36 void setStream(std::iostream &stream);
37 std::uint64_t startOffset() const;
38 CppUtilities::BinaryReader &reader();
39 CppUtilities::BinaryWriter &writer();
40
41 void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
42 void parseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
43 void parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
44 void parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
45 void parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
46 void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
47
48 bool isHeaderParsed() const;
49 bool areTagsParsed() const;
50 bool areTracksParsed() const;
51 bool areChaptersParsed() const;
52 bool areAttachmentsParsed() const;
53
54 virtual Tag *createTag(const TagTarget &target = TagTarget());
55 virtual Tag *tag(std::size_t index);
56 virtual std::size_t tagCount() const;
57 virtual bool removeTag(Tag *tag);
58 virtual void removeAllTags();
59 virtual ElementPosition determineTagPosition(Diagnostics &diag) const;
60
61 virtual AbstractTrack *track(std::size_t index);
62 virtual std::size_t trackCount() const;
63 virtual bool removeTrack(AbstractTrack *track);
64 virtual void removeAllTracks();
65 virtual bool supportsTrackModifications() const;
66 virtual ElementPosition determineIndexPosition(Diagnostics &diag) const;
67
68 virtual AbstractChapter *chapter(std::size_t index);
69 virtual std::size_t chapterCount() const;
70
71 virtual AbstractAttachment *createAttachment();
72 virtual AbstractAttachment *attachment(std::size_t index);
73 virtual std::size_t attachmentCount() const;
74
75 std::uint64_t version() const;
76 std::uint64_t readVersion() const;
77 const std::string &documentType() const;
78 std::uint64_t doctypeVersion() const;
79 std::uint64_t doctypeReadVersion() const;
80 const std::vector<std::string> &titles() const;
81 void setTitle(std::string_view title, std::size_t segmentIndex = 0);
82 virtual bool supportsTitle() const;
83 const std::vector<std::string> &muxingApplications() const;
84 const std::vector<std::string> &writingApplications() const;
85 virtual std::size_t segmentCount() const;
86 CppUtilities::TimeSpan duration() const;
87 CppUtilities::DateTime creationTime() const;
88 CppUtilities::DateTime modificationTime() const;
89 std::uint32_t timeScale() const;
90
91 virtual void reset();
92
93protected:
94 AbstractContainer(std::iostream &stream, std::uint64_t startOffset);
95
96 virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
97 virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
98 virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
99 virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
100 virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
101 virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
102 std::vector<std::string> &muxingApplications();
103 std::vector<std::string> &writingApplications();
104
105 std::uint64_t m_version;
106 std::uint64_t m_readVersion;
107 std::string m_doctype;
108 std::uint64_t m_doctypeVersion;
109 std::uint64_t m_doctypeReadVersion;
110 std::vector<std::string> m_titles;
111 CppUtilities::TimeSpan m_duration;
112 CppUtilities::DateTime m_creationTime;
113 CppUtilities::DateTime m_modificationTime;
114 std::uint32_t m_timeScale;
115
116 bool m_headerParsed;
117 bool m_tagsParsed;
118 bool m_tracksParsed;
119 bool m_tracksAltered;
120 bool m_chaptersParsed;
121 bool m_attachmentsParsed;
122
123private:
124 std::unique_ptr<AbstractContainerPrivate> &p();
125
126 std::uint64_t m_startOffset;
127 std::iostream *m_stream;
128 CppUtilities::BinaryReader m_reader;
129 CppUtilities::BinaryWriter m_writer;
130 std::unique_ptr<AbstractContainerPrivate> m_p;
131};
132
136 inline std::iostream &AbstractContainer::stream()
137{
138 return *m_stream;
139}
140
144 inline void AbstractContainer::setStream(std::iostream &stream)
145{
146 m_stream = &stream;
147 m_reader.setStream(m_stream);
148 m_writer.setStream(m_stream);
149}
150
154 inline std::uint64_t AbstractContainer::startOffset() const
155{
156 return m_startOffset;
157}
158
162 inline CppUtilities::BinaryReader &AbstractContainer::reader()
163{
164 return m_reader;
165}
166
170 inline CppUtilities::BinaryWriter &AbstractContainer::writer()
171{
172 return m_writer;
173}
174
178 inline bool AbstractContainer::isHeaderParsed() const
179{
180 return m_headerParsed;
181}
182
186 inline bool AbstractContainer::areTagsParsed() const
187{
188 return m_tagsParsed;
189}
190
194 inline bool AbstractContainer::areChaptersParsed() const
195{
196 return m_chaptersParsed;
197}
198
202 inline bool AbstractContainer::areAttachmentsParsed() const
203{
204 return m_attachmentsParsed;
205}
206
210 inline bool AbstractContainer::areTracksParsed() const
211{
212 return m_tracksParsed;
213}
214
218 inline std::uint64_t AbstractContainer::version() const
219{
220 return m_version;
221}
222
228 inline std::uint64_t AbstractContainer::readVersion() const
229{
230 return m_readVersion;
231}
232
236 inline const std::string &AbstractContainer::documentType() const
237{
238 return m_doctype;
239}
240
244 inline std::uint64_t AbstractContainer::doctypeVersion() const
245{
246 return m_doctypeVersion;
247}
248
254 inline std::uint64_t AbstractContainer::doctypeReadVersion() const
255{
256 return m_doctypeReadVersion;
257}
258
266 inline const std::vector<std::string> &AbstractContainer::titles() const
267{
268 return m_titles;
269}
270
277 inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
278{
279 m_titles.at(segmentIndex) = title;
280}
281
285 inline CppUtilities::TimeSpan AbstractContainer::duration() const
286{
287 return m_duration;
288}
289
293 inline CppUtilities::DateTime AbstractContainer::creationTime() const
294{
295 return m_creationTime;
296}
297
301 inline CppUtilities::DateTime AbstractContainer::modificationTime() const
302{
303 return m_modificationTime;
304}
305
309 inline std::uint32_t AbstractContainer::timeScale() const
310{
311 return m_timeScale;
312}
313
314} // namespace TagParser
315
316#endif // TAG_PARSER_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::modificationTime
CppUtilities::DateTime modificationTime() const
Returns the modification time of the file if known; otherwise the returned date time is null.
Definition abstractcontainer.h:301
TagParser::AbstractContainer::doctypeVersion
std::uint64_t doctypeVersion() const
Returns the document type version if known; otherwise returns 0.
Definition abstractcontainer.h:244
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::m_modificationTime
CppUtilities::DateTime m_modificationTime
Definition abstractcontainer.h:113
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::setTitle
void setTitle(std::string_view title, std::size_t segmentIndex=0)
Sets the title for the specified segment.
Definition abstractcontainer.h: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::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::doctypeReadVersion
std::uint64_t doctypeReadVersion() const
Returns the document type "read version" if known; otherwise returns 0.
Definition abstractcontainer.h:254
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::version
std::uint64_t version() const
Returns the version if known; otherwise returns 0.
Definition abstractcontainer.h:218
TagParser::AbstractContainer::creationTime
CppUtilities::DateTime creationTime() const
Returns the creation time of the file if known; otherwise the returned date time is null.
Definition abstractcontainer.h:293
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::setStream
void setStream(std::iostream &stream)
Sets the related stream.
Definition abstractcontainer.h:144
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::m_doctype
std::string m_doctype
Definition abstractcontainer.h:107
TagParser::AbstractContainer::timeScale
std::uint32_t timeScale() const
Returns the time scale of the file if known; otherwise returns 0.
Definition abstractcontainer.h:309
TagParser::AbstractContainer::internalParseChapters
virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress)
Internally called to parse the chapters.
Definition abstractcontainer.cpp:247
TagParser::AbstractContainer::writer
CppUtilities::BinaryWriter & writer()
Returns the related BinaryWriter.
Definition abstractcontainer.h:170
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::reader
CppUtilities::BinaryReader & reader()
Returns the related BinaryReader.
Definition abstractcontainer.h:162
TagParser::AbstractContainer::m_creationTime
CppUtilities::DateTime m_creationTime
Definition abstractcontainer.h:112
TagParser::AbstractContainer::documentType
const std::string & documentType() const
Returns a string that describes the document type if available; otherwise returns an empty string.
Definition abstractcontainer.h:236
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::titles
const std::vector< std::string > & titles() const
Returns the title(s) of the file.
Definition abstractcontainer.h:266
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::m_duration
CppUtilities::TimeSpan m_duration
Definition abstractcontainer.h:111
TagParser::AbstractContainer::duration
CppUtilities::TimeSpan duration() const
Returns the duration of the file if known; otherwise returns a time span of zero ticks.
Definition abstractcontainer.h:285
TagParser::AbstractContainer::readVersion
std::uint64_t readVersion() const
Returns the "read version" if known; otherwise returns 0.
Definition abstractcontainer.h:228
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::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
exceptions.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
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
settings.h
tagtarget.h