Tag Parser 12.3.1
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
16namespace 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
31class 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
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
136inline std::iostream &AbstractContainer::stream()
137{
138 return *m_stream;
139}
140
144inline 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
154inline std::uint64_t AbstractContainer::startOffset() const
155{
156 return m_startOffset;
157}
158
162inline CppUtilities::BinaryReader &AbstractContainer::reader()
163{
164 return m_reader;
165}
166
170inline CppUtilities::BinaryWriter &AbstractContainer::writer()
171{
172 return m_writer;
173}
174
179{
180 return m_headerParsed;
181}
182
187{
188 return m_tagsParsed;
189}
190
195{
196 return m_chaptersParsed;
197}
198
203{
204 return m_attachmentsParsed;
205}
206
211{
212 return m_tracksParsed;
213}
214
218inline std::uint64_t AbstractContainer::version() const
219{
220 return m_version;
221}
222
228inline std::uint64_t AbstractContainer::readVersion() const
229{
230 return m_readVersion;
231}
232
236inline const std::string &AbstractContainer::documentType() const
237{
238 return m_doctype;
239}
240
244inline std::uint64_t AbstractContainer::doctypeVersion() const
245{
246 return m_doctypeVersion;
247}
248
254inline std::uint64_t AbstractContainer::doctypeReadVersion() const
255{
257}
258
266inline const std::vector<std::string> &AbstractContainer::titles() const
267{
268 return m_titles;
269}
270
277inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
278{
279 m_titles.at(segmentIndex) = title;
280}
281
285inline CppUtilities::TimeSpan AbstractContainer::duration() const
286{
287 return m_duration;
288}
289
293inline CppUtilities::DateTime AbstractContainer::creationTime() const
294{
295 return m_creationTime;
296}
297
301inline CppUtilities::DateTime AbstractContainer::modificationTime() const
302{
303 return m_modificationTime;
304}
305
309inline std::uint32_t AbstractContainer::timeScale() const
310{
311 return m_timeScale;
312}
313
314} // namespace TagParser
315
316#endif // TAG_PARSER_ABSTRACTCONTAINER_H
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.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10