Tag Parser  7.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
abstractattachment.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_ABSTRACTATTACHMENT_H
2 #define TAG_PARSER_ABSTRACTATTACHMENT_H
3 
4 #include "./diagnostics.h"
5 
6 #include <functional>
7 #include <iostream>
8 #include <memory>
9 #include <string>
10 
11 namespace TagParser {
12 
13 class MediaFileInfo;
14 
16 public:
17  StreamDataBlock(const std::function<std::istream &()> &stream, std::istream::off_type startOffset = 0,
18  std::ios_base::seekdir startDir = std::ios_base::beg, std::istream::off_type endOffset = 0,
19  std::ios_base::seekdir endDir = std::ios_base::end);
20 
21  std::istream &stream() const;
22  std::istream::pos_type startOffset() const;
23  std::istream::pos_type endOffset() const;
24  std::istream::pos_type size() const;
25  const std::unique_ptr<char[]> &buffer() const;
26  void makeBuffer() const;
27  void discardBuffer();
28  void copyTo(std::ostream &stream) const;
29 
30 protected:
32 
33  std::function<std::istream &()> m_stream;
34  std::istream::pos_type m_startOffset;
35  std::istream::pos_type m_endOffset;
36  mutable std::unique_ptr<char[]> m_buffer;
37 };
38 
44 inline std::istream &StreamDataBlock::stream() const
45 {
46  return m_stream();
47 }
48 
52 inline std::istream::pos_type StreamDataBlock::startOffset() const
53 {
54  return m_startOffset;
55 }
56 
60 inline std::istream::pos_type StreamDataBlock::endOffset() const
61 {
62  return m_endOffset;
63 }
64 
68 inline std::istream::pos_type StreamDataBlock::size() const
69 {
70  return m_endOffset - m_startOffset;
71 }
72 
76 inline const std::unique_ptr<char[]> &StreamDataBlock::buffer() const
77 {
78  return m_buffer;
79 }
80 
85 {
86  m_buffer.reset();
87 }
88 
90 public:
91  FileDataBlock(const std::string &path, Diagnostics &diag);
92  const MediaFileInfo *fileInfo() const;
93 
94 private:
95  std::unique_ptr<MediaFileInfo> m_fileInfo;
96 };
97 
99 {
100  return m_fileInfo.get();
101 }
102 
104 public:
105  const std::string &description() const;
106  void setDescription(const std::string &description);
107  const std::string &name() const;
108  void setName(const std::string &name);
109  const std::string &mimeType() const;
110  void setMimeType(const std::string &mimeType);
111  uint64 id() const;
112  void setId(const uint64 &id);
113  const StreamDataBlock *data() const;
114  void setData(std::unique_ptr<StreamDataBlock> &&data);
115  void setFile(const std::string &path, Diagnostics &diag);
116  bool isDataFromFile() const;
117  std::string label() const;
118  void clear();
119  bool isIgnored() const;
120  void setIgnored(bool ignored);
121  bool isEmpty() const;
122 
123 protected:
125 
126 private:
127  std::string m_description;
128  std::string m_name;
129  std::string m_mimeType;
130  uint64 m_id;
131  std::unique_ptr<StreamDataBlock> m_data;
132  bool m_isDataFromFile;
133  bool m_ignored;
134 };
135 
140  : m_id(0)
141  , m_isDataFromFile(false)
142  , m_ignored(false)
143 {
144 }
145 
149 inline const std::string &AbstractAttachment::description() const
150 {
151  return m_description;
152 }
153 
157 inline void AbstractAttachment::setDescription(const std::string &description)
158 {
159  m_description = description;
160 }
161 
165 inline const std::string &AbstractAttachment::name() const
166 {
167  return m_name;
168 }
169 
173 inline void AbstractAttachment::setName(const std::string &name)
174 {
175  m_name = name;
176 }
177 
181 inline const std::string &AbstractAttachment::mimeType() const
182 {
183  return m_mimeType;
184 }
185 
189 inline void AbstractAttachment::setMimeType(const std::string &mimeType)
190 {
191  m_mimeType = mimeType;
192 }
193 
197 inline uint64 AbstractAttachment::id() const
198 {
199  return m_id;
200 }
201 
205 inline void AbstractAttachment::setId(const uint64 &id)
206 {
207  m_id = id;
208 }
209 
218 {
219  return m_data.get();
220 }
221 
227 inline void AbstractAttachment::setData(std::unique_ptr<StreamDataBlock> &&data)
228 {
229  m_data = std::move(data);
230  m_isDataFromFile = false;
231 }
232 
237 {
238  return m_isDataFromFile;
239 }
240 
247 inline bool AbstractAttachment::isIgnored() const
248 {
249  return m_ignored;
250 }
251 
257 inline void AbstractAttachment::setIgnored(bool ignored)
258 {
259  m_ignored = ignored;
260 }
261 
266 inline bool AbstractAttachment::isEmpty() const
267 {
268  return m_description.empty() && m_name.empty() && !m_mimeType.empty() && !m_data;
269 }
270 
271 } // namespace TagParser
272 
273 #endif // TAG_PARSER_ABSTRACTATTACHMENT_H
const MediaFileInfo * fileInfo() const
TAG_PARSER_EXPORT const char * description()
const std::unique_ptr< char[]> & buffer() const
Returns the data buffered via makeBuffer().
void setDescription(const std::string &description)
Sets a description of the attachment.
std::unique_ptr< char[]> m_buffer
const std::string & description() const
Returns a description of the attachment.
bool isEmpty() const
Returns whether the attachment is empty (no data and no meta-data assigned).
AbstractAttachment()
Constructs a new attachment.
const StreamDataBlock * data() const
Returns a reference to the data of the attachment.
void setIgnored(bool ignored)
Sets whether the attachment is ignored/omitted when rewriting the container.
void setData(std::unique_ptr< StreamDataBlock > &&data)
Sets the data for the attachment.
uint64 id() const
Returns the ID of the attachment.
const std::string & name() const
Returns the (file) name of the attachment.
void setId(const uint64 &id)
Sets the ID of the attachment.
std::istream::pos_type endOffset() const
Returns the absolute end offset of the data block in the stream.
bool isDataFromFile() const
Returns whether the assigned data has been assigned using the setFile() method.
void discardBuffer()
Discards buffered data.
std::istream::pos_type m_endOffset
void setMimeType(const std::string &mimeType)
Sets the MIME-type of the attachment.
std::function< std::istream &()> m_stream
bool isIgnored() const
Returns whether the attachment is ignored/omitted when rewriting the container.
std::istream::pos_type startOffset() const
Returns the absolute start offset of the data block in the stream.
std::istream::pos_type size() const
Returns the size of the data block.
std::istream & stream() const
Returns the associated stream.
void setName(const std::string &name)
Sets the (file) name of the attachment.
const std::string & mimeType() const
Returns the MIME-type of the attachment.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
std::istream::pos_type m_startOffset