Tag Parser 10.3.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
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
15namespace CppUtilities {
16class BinaryReader;
17class BinaryWriter;
18} // namespace CppUtilities
19
20namespace TagParser {
21
22class Tag;
23class AbstractTrack;
24class AbstractChapter;
25class AbstractAttachment;
26class Diagnostics;
27class AbortableProgressFeedback;
28
30public:
31 virtual ~AbstractContainer();
32
33 std::iostream &stream();
34 void setStream(std::iostream &stream);
35 std::uint64_t startOffset() const;
36 CppUtilities::BinaryReader &reader();
37 CppUtilities::BinaryWriter &writer();
38
39 void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
40 void parseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
41 void parseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
42 void parseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
43 void parseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
44 void makeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
45
46 bool isHeaderParsed() const;
47 bool areTagsParsed() const;
48 bool areTracksParsed() const;
49 bool areChaptersParsed() const;
50 bool areAttachmentsParsed() const;
51
52 virtual Tag *createTag(const TagTarget &target = TagTarget());
53 virtual Tag *tag(std::size_t index);
54 virtual std::size_t tagCount() const;
55 virtual bool removeTag(Tag *tag);
56 virtual void removeAllTags();
57 virtual ElementPosition determineTagPosition(Diagnostics &diag) const;
58
59 virtual AbstractTrack *track(std::size_t index);
60 virtual std::size_t trackCount() const;
61 virtual bool removeTrack(AbstractTrack *track);
62 virtual void removeAllTracks();
63 virtual bool supportsTrackModifications() const;
64 virtual ElementPosition determineIndexPosition(Diagnostics &diag) const;
65
66 virtual AbstractChapter *chapter(std::size_t index);
67 virtual std::size_t chapterCount() const;
68
69 virtual AbstractAttachment *createAttachment();
70 virtual AbstractAttachment *attachment(std::size_t index);
71 virtual std::size_t attachmentCount() const;
72
73 std::uint64_t version() const;
74 std::uint64_t readVersion() const;
75 const std::string &documentType() const;
76 std::uint64_t doctypeVersion() const;
77 std::uint64_t doctypeReadVersion() const;
78 const std::vector<std::string> &titles() const;
79 void setTitle(std::string_view title, std::size_t segmentIndex = 0);
80 virtual bool supportsTitle() const;
81 virtual std::size_t segmentCount() const;
82 CppUtilities::TimeSpan duration() const;
83 CppUtilities::DateTime creationTime() const;
84 CppUtilities::DateTime modificationTime() const;
85 std::uint32_t timeScale() const;
86
87 virtual void reset();
88
89protected:
90 AbstractContainer(std::iostream &stream, std::uint64_t startOffset);
91
92 virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
93 virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
94 virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
95 virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
96 virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
97 virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
98
99 std::uint64_t m_version;
100 std::uint64_t m_readVersion;
101 std::string m_doctype;
102 std::uint64_t m_doctypeVersion;
103 std::uint64_t m_doctypeReadVersion;
104 std::vector<std::string> m_titles;
105 CppUtilities::TimeSpan m_duration;
106 CppUtilities::DateTime m_creationTime;
107 CppUtilities::DateTime m_modificationTime;
108 std::uint32_t m_timeScale;
109
116
117private:
118 std::uint64_t m_startOffset;
119 std::iostream *m_stream;
120 CppUtilities::BinaryReader m_reader;
121 CppUtilities::BinaryWriter m_writer;
122};
123
127inline std::iostream &AbstractContainer::stream()
128{
129 return *m_stream;
130}
131
135inline void AbstractContainer::setStream(std::iostream &stream)
136{
137 m_stream = &stream;
138 m_reader.setStream(m_stream);
139 m_writer.setStream(m_stream);
140}
141
145inline std::uint64_t AbstractContainer::startOffset() const
146{
147 return m_startOffset;
148}
149
153inline CppUtilities::BinaryReader &AbstractContainer::reader()
154{
155 return m_reader;
156}
157
161inline CppUtilities::BinaryWriter &AbstractContainer::writer()
162{
163 return m_writer;
164}
165
170{
171 return m_headerParsed;
172}
173
178{
179 return m_tagsParsed;
180}
181
186{
187 return m_chaptersParsed;
188}
189
194{
195 return m_attachmentsParsed;
196}
197
202{
203 return m_tracksParsed;
204}
205
209inline std::uint64_t AbstractContainer::version() const
210{
211 return m_version;
212}
213
219inline std::uint64_t AbstractContainer::readVersion() const
220{
221 return m_readVersion;
222}
223
227inline const std::string &AbstractContainer::documentType() const
228{
229 return m_doctype;
230}
231
235inline std::uint64_t AbstractContainer::doctypeVersion() const
236{
237 return m_doctypeVersion;
238}
239
245inline std::uint64_t AbstractContainer::doctypeReadVersion() const
246{
248}
249
257inline const std::vector<std::string> &AbstractContainer::titles() const
258{
259 return m_titles;
260}
261
268inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
269{
270 m_titles.at(segmentIndex) = title;
271}
272
276inline CppUtilities::TimeSpan AbstractContainer::duration() const
277{
278 return m_duration;
279}
280
284inline CppUtilities::DateTime AbstractContainer::creationTime() const
285{
286 return m_creationTime;
287}
288
292inline CppUtilities::DateTime AbstractContainer::modificationTime() const
293{
294 return m_modificationTime;
295}
296
300inline std::uint32_t AbstractContainer::timeScale() const
301{
302 return m_timeScale;
303}
304
305} // namespace TagParser
306
307#endif // TAG_PARSER_ABSTRACTCONTAINER_H
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.
The AbstractContainer class provides an interface and common functionality to parse and make a certai...
CppUtilities::DateTime modificationTime() const
Returns the modification time of the file if known; otherwise the returned date time is null.
std::uint64_t doctypeVersion() const
Returns the document type version if known; otherwise returns 0.
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
CppUtilities::DateTime m_modificationTime
std::iostream & stream()
Returns the related stream.
std::uint64_t startOffset() const
Returns the start offset in the related stream.
void setTitle(std::string_view title, std::size_t segmentIndex=0)
Sets the title for the specified segment.
std::vector< std::string > m_titles
bool areTracksParsed() const
Returns an indication whether the tracks have been parsed yet.
std::uint64_t doctypeReadVersion() const
Returns the document type "read version" if known; otherwise returns 0.
std::uint64_t version() const
Returns the version if known; otherwise returns 0.
CppUtilities::DateTime creationTime() const
Returns the creation time of the file if known; otherwise the returned date time is null.
bool isHeaderParsed() const
Returns an indication whether the header has been parsed yet.
void setStream(std::iostream &stream)
Sets the related stream.
std::uint32_t timeScale() const
Returns the time scale of the file if known; otherwise returns 0.
CppUtilities::BinaryWriter & writer()
Returns the related BinaryWriter.
CppUtilities::BinaryReader & reader()
Returns the related BinaryReader.
CppUtilities::DateTime m_creationTime
const std::string & documentType() const
Returns a string that describes the document type if available; otherwise returns an empty string.
const std::vector< std::string > & titles() const
Returns the title(s) of the file.
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.
CppUtilities::TimeSpan m_duration
CppUtilities::TimeSpan duration() const
Returns the duration of the file if known; otherwise returns a time span of zero ticks.
std::uint64_t readVersion() const
Returns the "read version" if known; otherwise returns 0.
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
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
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr TAG_PARSER_EXPORT std::string_view title()
Definition: matroskatagid.h:38
constexpr TAG_PARSER_EXPORT std::string_view duration()
constexpr TAG_PARSER_EXPORT std::string_view version()
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
ElementPosition
Definition: settings.h:13