Tag Parser 12.0.0
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
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 virtual std::size_t segmentCount() const;
84 CppUtilities::TimeSpan duration() const;
85 CppUtilities::DateTime creationTime() const;
86 CppUtilities::DateTime modificationTime() const;
87 std::uint32_t timeScale() const;
88
89 virtual void reset();
90
91protected:
92 AbstractContainer(std::iostream &stream, std::uint64_t startOffset);
93
94 virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
95 virtual void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress);
96 virtual void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress);
97 virtual void internalParseChapters(Diagnostics &diag, AbortableProgressFeedback &progress);
98 virtual void internalParseAttachments(Diagnostics &diag, AbortableProgressFeedback &progress);
99 virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
100
101 std::uint64_t m_version;
102 std::uint64_t m_readVersion;
103 std::string m_doctype;
104 std::uint64_t m_doctypeVersion;
105 std::uint64_t m_doctypeReadVersion;
106 std::vector<std::string> m_titles;
107 CppUtilities::TimeSpan m_duration;
108 CppUtilities::DateTime m_creationTime;
109 CppUtilities::DateTime m_modificationTime;
110 std::uint32_t m_timeScale;
111
118
119private:
120 std::uint64_t m_startOffset;
121 std::iostream *m_stream;
122 CppUtilities::BinaryReader m_reader;
123 CppUtilities::BinaryWriter m_writer;
124 std::unique_ptr<AbstractContainerPrivate> m_p;
125};
126
130inline std::iostream &AbstractContainer::stream()
131{
132 return *m_stream;
133}
134
138inline void AbstractContainer::setStream(std::iostream &stream)
139{
140 m_stream = &stream;
141 m_reader.setStream(m_stream);
142 m_writer.setStream(m_stream);
143}
144
148inline std::uint64_t AbstractContainer::startOffset() const
149{
150 return m_startOffset;
151}
152
156inline CppUtilities::BinaryReader &AbstractContainer::reader()
157{
158 return m_reader;
159}
160
164inline CppUtilities::BinaryWriter &AbstractContainer::writer()
165{
166 return m_writer;
167}
168
173{
174 return m_headerParsed;
175}
176
181{
182 return m_tagsParsed;
183}
184
189{
190 return m_chaptersParsed;
191}
192
197{
198 return m_attachmentsParsed;
199}
200
205{
206 return m_tracksParsed;
207}
208
212inline std::uint64_t AbstractContainer::version() const
213{
214 return m_version;
215}
216
222inline std::uint64_t AbstractContainer::readVersion() const
223{
224 return m_readVersion;
225}
226
230inline const std::string &AbstractContainer::documentType() const
231{
232 return m_doctype;
233}
234
238inline std::uint64_t AbstractContainer::doctypeVersion() const
239{
240 return m_doctypeVersion;
241}
242
248inline std::uint64_t AbstractContainer::doctypeReadVersion() const
249{
251}
252
260inline const std::vector<std::string> &AbstractContainer::titles() const
261{
262 return m_titles;
263}
264
271inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
272{
273 m_titles.at(segmentIndex) = title;
274}
275
279inline CppUtilities::TimeSpan AbstractContainer::duration() const
280{
281 return m_duration;
282}
283
287inline CppUtilities::DateTime AbstractContainer::creationTime() const
288{
289 return m_creationTime;
290}
291
295inline CppUtilities::DateTime AbstractContainer::modificationTime() const
296{
297 return m_modificationTime;
298}
299
303inline std::uint32_t AbstractContainer::timeScale() const
304{
305 return m_timeScale;
306}
307
308} // namespace TagParser
309
310#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...
The Diagnostics class is a container for DiagMessage.
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:166
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:13
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
ElementPosition
Definition settings.h:13