Tag Parser  6.5.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 MEDIA_ABSTRACTCONTAINER_H
2 #define MEDIA_ABSTRACTCONTAINER_H
3 
4 #include "./statusprovider.h"
5 #include "./exceptions.h"
6 #include "./tagtarget.h"
7 
8 #include <c++utilities/io/binaryreader.h>
9 #include <c++utilities/io/binarywriter.h>
10 #include <c++utilities/chrono/timespan.h>
11 #include <c++utilities/chrono/datetime.h>
12 
13 #include <iostream>
14 
15 namespace IoUtilities {
16 class BinaryReader;
17 class BinaryWriter;
18 }
19 
20 namespace Media {
21 
22 class Tag;
23 class AbstractTrack;
24 class AbstractChapter;
25 class AbstractAttachment;
26 
27 enum class ElementPosition
28 {
29  BeforeData,
30  AfterData,
31  Keep
32 };
33 
35 {
36 public:
37  virtual ~AbstractContainer();
38 
39  std::iostream &stream();
40  void setStream(std::iostream &stream);
41  uint64 startOffset() const;
42  IoUtilities::BinaryReader &reader();
43  IoUtilities::BinaryWriter &writer();
44 
45  void parseHeader();
46  void parseTags();
47  void parseTracks();
48  void parseChapters();
49  void parseAttachments();
50  void makeFile();
51 
52  bool isHeaderParsed() const;
53  bool areTagsParsed() const;
54  bool areTracksParsed() const;
55  bool areChaptersParsed() const;
56  bool areAttachmentsParsed() const;
57 
58  virtual Tag *createTag(const TagTarget &target = TagTarget());
59  virtual Tag *tag(std::size_t index);
60  virtual std::size_t tagCount() const;
61  virtual bool removeTag(Tag *tag);
62  virtual void removeAllTags();
63  virtual ElementPosition determineTagPosition() const;
64 
65  virtual AbstractTrack *track(std::size_t index);
66  virtual std::size_t trackCount() const;
67  virtual bool removeTrack(AbstractTrack *track);
68  virtual void removeAllTracks();
69  virtual bool supportsTrackModifications() const;
70  virtual ElementPosition determineIndexPosition() const;
71 
72  virtual AbstractChapter *chapter(std::size_t index);
73  virtual std::size_t chapterCount() const;
74 
75  virtual AbstractAttachment *createAttachment();
76  virtual AbstractAttachment *attachment(std::size_t index);
77  virtual std::size_t attachmentCount() const;
78 
79  uint64 version() const;
80  uint64 readVersion() const;
81  const std::string &documentType() const;
82  uint64 doctypeVersion() const;
83  uint64 doctypeReadVersion() const;
84  const std::vector<std::string> &titles() const;
85  void setTitle(const std::string &title, std::size_t segmentIndex = 0);
86  virtual bool supportsTitle() const;
87  virtual std::size_t segmentCount() const;
89  ChronoUtilities::DateTime creationTime() const;
90  ChronoUtilities::DateTime modificationTime() const;
91  uint32 timeScale() const;
92 
93  virtual void reset();
94 
95 protected:
96  AbstractContainer(std::iostream &stream, uint64 startOffset);
97 
98  virtual void internalParseHeader();
99  virtual void internalParseTags();
100  virtual void internalParseTracks();
101  virtual void internalParseChapters();
102  virtual void internalParseAttachments();
103  virtual void internalMakeFile();
104 
105  uint64 m_version;
107  std::string m_doctype;
110  std::vector<std::string> m_titles;
114  uint32 m_timeScale;
115 
122 
123 private:
124  uint64 m_startOffset;
125  std::iostream *m_stream;
126  IoUtilities::BinaryReader m_reader;
127  IoUtilities::BinaryWriter m_writer;
128 };
129 
133 inline std::iostream &AbstractContainer::stream()
134 {
135  return *m_stream;
136 }
137 
141 inline void AbstractContainer::setStream(std::iostream &stream)
142 {
143  m_stream = &stream;
144  m_reader.setStream(m_stream);
145  m_writer.setStream(m_stream);
146 }
147 
151 inline uint64 AbstractContainer::startOffset() const
152 {
153  return m_startOffset;
154 }
155 
159 inline IoUtilities::BinaryReader &AbstractContainer::reader()
160 {
161  return m_reader;
162 }
163 
167 inline IoUtilities::BinaryWriter &AbstractContainer::writer()
168 {
169  return m_writer;
170 }
171 
176 {
177  return m_headerParsed;
178 }
179 
184 {
185  return m_tagsParsed;
186 }
187 
192 {
193  return m_chaptersParsed;
194 }
195 
200 {
201  return m_attachmentsParsed;
202 }
203 
208 {
209  return m_tracksParsed;
210 }
211 
215 inline uint64 AbstractContainer::version() const
216 {
217  return m_version;
218 }
219 
225 inline uint64 AbstractContainer::readVersion() const
226 {
227  return m_readVersion;
228 }
229 
233 inline const std::string &AbstractContainer::documentType() const
234 {
235  return m_doctype;
236 }
237 
242 {
243  return m_doctypeVersion;
244 }
245 
252 {
253  return m_doctypeReadVersion;
254 }
255 
256 
264 inline const std::vector<std::string> &AbstractContainer::titles() const
265 {
266  return m_titles;
267 }
268 
275 inline void AbstractContainer::setTitle(const std::string &title, std::size_t segmentIndex)
276 {
277  m_titles.at(segmentIndex) = title;
278 }
279 
284 {
285  return m_duration;
286 }
287 
292 {
293  return m_creationTime;
294 }
295 
300 {
301  return m_modificationTime;
302 }
303 
307 inline uint32 AbstractContainer::timeScale() const
308 {
309  return m_timeScale;
310 }
311 
312 }
313 
314 #endif // MEDIA_ABSTRACTCONTAINER_H
IoUtilities::BinaryWriter & writer()
Returns the related BinaryWriter.
TAG_PARSER_EXPORT const char * duration()
The AbstractChapter class parses chapter information.
ChronoUtilities::TimeSpan m_duration
uint64 version() const
Returns the version if known; otherwise returns 0.
uint64 doctypeVersion() const
Returns the document type version if known; otherwise returns 0.
uint64 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:40
const std::string & documentType() const
Returns a string that describes the document type if available; otherwise returns an empty string...
ChronoUtilities::DateTime modificationTime() const
Returns the modification time of the file if known; otherwise the returned date time is null...
ChronoUtilities::DateTime m_creationTime
bool areChaptersParsed() const
Returns an indication whether the chapters have been parsed yet.
ChronoUtilities::DateTime m_modificationTime
void setStream(std::iostream &stream)
Sets the related stream.
void setTitle(const std::string &title, std::size_t segmentIndex=0)
Sets the title for the specified segment.
bool areTracksParsed() const
Returns an indication whether the tracks have been parsed yet.
TAG_PARSER_EXPORT const char * title()
Contains utility classes helping to read and write streams.
uint64 startOffset() const
Returns the start offset in the related stream.
The AbstractAttachment class parses and stores attachment information.
uint32 timeScale() const
Returns the time scale of the file if known; otherwise returns 0.
bool isHeaderParsed() const
Returns an indication whether the header has been parsed yet.
bool areAttachmentsParsed() const
Returns an indication whether the attachments have been parsed yet.
The Tag class is used to store, read and write tag information.
Definition: tag.h:98
bool areTagsParsed() const
Returns an indication whether the tags have been parsed yet.
The AbstractContainer class provides an interface and common functionality to parse and make a certai...
std::vector< std::string > m_titles
IoUtilities::BinaryReader & reader()
Returns the related BinaryReader.
ChronoUtilities::DateTime creationTime() const
Returns the creation time of the file if known; otherwise the returned date time is null...
uint64 doctypeReadVersion() const
Returns the document type "read version" if known; otherwise returns 0.
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:31
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The StatusProvider class acts as a base class for objects providing status information.
std::iostream & stream()
Returns the related stream.
ChronoUtilities::TimeSpan duration() const
Returns the duration of the file if known; otherwise returns a time span of zero ticks.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
const std::vector< std::string > & titles() const
Returns the title(s) of the file.
TAG_PARSER_EXPORT const char * version()