Tag Parser  7.1.0
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 
15 namespace IoUtilities {
16 class BinaryReader;
17 class BinaryWriter;
18 } // namespace IoUtilities
19 
20 namespace TagParser {
21 
22 class Tag;
23 class AbstractTrack;
24 class AbstractChapter;
25 class AbstractAttachment;
26 class Diagnostics;
27 class AbortableProgressFeedback;
28 
30 public:
31  virtual ~AbstractContainer();
32 
33  std::iostream &stream();
34  void setStream(std::iostream &stream);
35  uint64 startOffset() const;
36  IoUtilities::BinaryReader &reader();
37  IoUtilities::BinaryWriter &writer();
38 
39  void parseHeader(Diagnostics &diag);
40  void parseTags(Diagnostics &diag);
41  void parseTracks(Diagnostics &diag);
42  void parseChapters(Diagnostics &diag);
43  void parseAttachments(Diagnostics &diag);
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  uint64 version() const;
74  uint64 readVersion() const;
75  const std::string &documentType() const;
76  uint64 doctypeVersion() const;
77  uint64 doctypeReadVersion() const;
78  const std::vector<std::string> &titles() const;
79  void setTitle(const std::string &title, std::size_t segmentIndex = 0);
80  virtual bool supportsTitle() const;
81  virtual std::size_t segmentCount() const;
83  ChronoUtilities::DateTime creationTime() const;
84  ChronoUtilities::DateTime modificationTime() const;
85  uint32 timeScale() const;
86 
87  virtual void reset();
88 
89 protected:
90  AbstractContainer(std::iostream &stream, uint64 startOffset);
91 
92  virtual void internalParseHeader(Diagnostics &diag);
93  virtual void internalParseTags(Diagnostics &diag);
94  virtual void internalParseTracks(Diagnostics &diag);
95  virtual void internalParseChapters(Diagnostics &diag);
96  virtual void internalParseAttachments(Diagnostics &diag);
97  virtual void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress);
98 
99  uint64 m_version;
101  std::string m_doctype;
104  std::vector<std::string> m_titles;
108  uint32 m_timeScale;
109 
116 
117 private:
118  uint64 m_startOffset;
119  std::iostream *m_stream;
120  IoUtilities::BinaryReader m_reader;
121  IoUtilities::BinaryWriter m_writer;
122 };
123 
127 inline std::iostream &AbstractContainer::stream()
128 {
129  return *m_stream;
130 }
131 
135 inline 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 
145 inline uint64 AbstractContainer::startOffset() const
146 {
147  return m_startOffset;
148 }
149 
153 inline IoUtilities::BinaryReader &AbstractContainer::reader()
154 {
155  return m_reader;
156 }
157 
161 inline IoUtilities::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 
209 inline uint64 AbstractContainer::version() const
210 {
211  return m_version;
212 }
213 
219 inline uint64 AbstractContainer::readVersion() const
220 {
221  return m_readVersion;
222 }
223 
227 inline const std::string &AbstractContainer::documentType() const
228 {
229  return m_doctype;
230 }
231 
236 {
237  return m_doctypeVersion;
238 }
239 
246 {
247  return m_doctypeReadVersion;
248 }
249 
257 inline const std::vector<std::string> &AbstractContainer::titles() const
258 {
259  return m_titles;
260 }
261 
268 inline void AbstractContainer::setTitle(const std::string &title, std::size_t segmentIndex)
269 {
270  m_titles.at(segmentIndex) = title;
271 }
272 
277 {
278  return m_duration;
279 }
280 
285 {
286  return m_creationTime;
287 }
288 
293 {
294  return m_modificationTime;
295 }
296 
300 inline uint32 AbstractContainer::timeScale() const
301 {
302  return m_timeScale;
303 }
304 
305 } // namespace TagParser
306 
307 #endif // TAG_PARSER_ABSTRACTCONTAINER_H
const std::vector< std::string > & titles() const
Returns the title(s) of the file.
The Tag class is used to store, read and write tag information.
Definition: tag.h:95
const std::string & documentType() const
Returns a string that describes the document type if available; otherwise returns an empty string...
uint64 readVersion() const
Returns the "read version" if known; otherwise returns 0.
TAG_PARSER_EXPORT const char * version()
ChronoUtilities::DateTime creationTime() const
Returns the creation time of the file if known; otherwise the returned date time is null...
std::iostream & stream()
Returns the related stream.
The AbstractContainer class provides an interface and common functionality to parse and make a certai...
ChronoUtilities::DateTime m_creationTime
bool areChaptersParsed() const
Returns an indication whether the chapters have been parsed yet.
uint32 timeScale() const
Returns the time scale of the file if known; otherwise returns 0.
ChronoUtilities::DateTime modificationTime() const
Returns the modification 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.
ChronoUtilities::TimeSpan m_duration
uint64 version() const
Returns the version if known; otherwise returns 0.
Contains utility classes helping to read and write streams.
void setStream(std::iostream &stream)
Sets the related stream.
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
IoUtilities::BinaryWriter & writer()
Returns the related BinaryWriter.
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:21
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks...
void setTitle(const std::string &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.
TAG_PARSER_EXPORT const char * duration()
ChronoUtilities::DateTime m_modificationTime
IoUtilities::BinaryReader & reader()
Returns the related BinaryReader.
uint64 startOffset() const
Returns the start offset in the related stream.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:39
uint64 doctypeVersion() const
Returns the document type version if known; otherwise returns 0.
The AbstractChapter class parses chapter information.
uint64 doctypeReadVersion() const
Returns the document type "read version" if known; otherwise returns 0.
bool areTagsParsed() const
Returns an indication whether the tags have been parsed yet.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
ChronoUtilities::TimeSpan duration() const
Returns the duration of the file if known; otherwise returns a time span of zero ticks.
The AbstractAttachment class parses and stores attachment information.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TAG_PARSER_EXPORT const char * title()
Definition: matroskatagid.h:39
ElementPosition
Definition: settings.h:10
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:154