Tag Parser  9.1.0
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  virtual ~StreamDataBlock();
21 
22  std::istream &stream() const;
23  std::istream::pos_type startOffset() const;
24  std::istream::pos_type endOffset() const;
25  std::istream::pos_type size() const;
26  const std::unique_ptr<char[]> &buffer() const;
27  void makeBuffer() const;
28  void discardBuffer();
29  void copyTo(std::ostream &stream) const;
30 
31 protected:
33 
34  std::function<std::istream &()> m_stream;
35  std::istream::pos_type m_startOffset;
36  std::istream::pos_type m_endOffset;
37  mutable std::unique_ptr<char[]> m_buffer;
38 };
39 
45 inline std::istream &StreamDataBlock::stream() const
46 {
47  return m_stream();
48 }
49 
53 inline std::istream::pos_type StreamDataBlock::startOffset() const
54 {
55  return m_startOffset;
56 }
57 
61 inline std::istream::pos_type StreamDataBlock::endOffset() const
62 {
63  return m_endOffset;
64 }
65 
69 inline std::istream::pos_type StreamDataBlock::size() const
70 {
71  return m_endOffset - m_startOffset;
72 }
73 
77 inline const std::unique_ptr<char[]> &StreamDataBlock::buffer() const
78 {
79  return m_buffer;
80 }
81 
86 {
87  m_buffer.reset();
88 }
89 
91 public:
92  FileDataBlock(const std::string &path, Diagnostics &diag);
93  ~FileDataBlock();
94  const MediaFileInfo *fileInfo() const;
95 
96 private:
97  std::unique_ptr<MediaFileInfo> m_fileInfo;
98 };
99 
101 {
102  return m_fileInfo.get();
103 }
104 
106 public:
107  const std::string &description() const;
108  void setDescription(const std::string &description);
109  const std::string &name() const;
110  void setName(const std::string &name);
111  const std::string &mimeType() const;
112  void setMimeType(const std::string &mimeType);
113  std::uint64_t id() const;
114  void setId(const std::uint64_t &id);
115  const StreamDataBlock *data() const;
116  void setData(std::unique_ptr<StreamDataBlock> &&data);
117  void setFile(const std::string &path, Diagnostics &diag);
118  bool isDataFromFile() const;
119  std::string label() const;
120  void clear();
121  bool isIgnored() const;
122  void setIgnored(bool ignored);
123  bool isEmpty() const;
124 
125 protected:
127 
128 private:
129  std::string m_description;
130  std::string m_name;
131  std::string m_mimeType;
132  std::uint64_t m_id;
133  std::unique_ptr<StreamDataBlock> m_data;
134  bool m_isDataFromFile;
135  bool m_ignored;
136 };
137 
142  : m_id(0)
143  , m_isDataFromFile(false)
144  , m_ignored(false)
145 {
146 }
147 
151 inline const std::string &AbstractAttachment::description() const
152 {
153  return m_description;
154 }
155 
159 inline void AbstractAttachment::setDescription(const std::string &description)
160 {
161  m_description = description;
162 }
163 
167 inline const std::string &AbstractAttachment::name() const
168 {
169  return m_name;
170 }
171 
175 inline void AbstractAttachment::setName(const std::string &name)
176 {
177  m_name = name;
178 }
179 
183 inline const std::string &AbstractAttachment::mimeType() const
184 {
185  return m_mimeType;
186 }
187 
191 inline void AbstractAttachment::setMimeType(const std::string &mimeType)
192 {
193  m_mimeType = mimeType;
194 }
195 
199 inline std::uint64_t AbstractAttachment::id() const
200 {
201  return m_id;
202 }
203 
207 inline void AbstractAttachment::setId(const std::uint64_t &id)
208 {
209  m_id = id;
210 }
211 
220 {
221  return m_data.get();
222 }
223 
229 inline void AbstractAttachment::setData(std::unique_ptr<StreamDataBlock> &&data)
230 {
231  m_data = std::move(data);
232  m_isDataFromFile = false;
233 }
234 
239 {
240  return m_isDataFromFile;
241 }
242 
249 inline bool AbstractAttachment::isIgnored() const
250 {
251  return m_ignored;
252 }
253 
259 inline void AbstractAttachment::setIgnored(bool ignored)
260 {
261  m_ignored = ignored;
262 }
263 
268 inline bool AbstractAttachment::isEmpty() const
269 {
270  return m_description.empty() && m_name.empty() && !m_mimeType.empty() && !m_data;
271 }
272 
273 } // namespace TagParser
274 
275 #endif // TAG_PARSER_ABSTRACTATTACHMENT_H
TagParser::AbstractAttachment::setMimeType
void setMimeType(const std::string &mimeType)
Sets the MIME-type of the attachment.
Definition: abstractattachment.h:191
TagParser::AbstractAttachment::isIgnored
bool isIgnored() const
Returns whether the attachment is ignored/omitted when rewriting the container.
Definition: abstractattachment.h:249
TagParser::AbstractAttachment::setIgnored
void setIgnored(bool ignored)
Sets whether the attachment is ignored/omitted when rewriting the container.
Definition: abstractattachment.h:259
TagParser::AbstractAttachment
The AbstractAttachment class parses and stores attachment information.
Definition: abstractattachment.h:105
TagParser::StreamDataBlock::startOffset
std::istream::pos_type startOffset() const
Returns the absolute start offset of the data block in the stream.
Definition: abstractattachment.h:53
TagParser::StreamDataBlock::stream
std::istream & stream() const
Returns the associated stream.
Definition: abstractattachment.h:45
TagParser::StreamDataBlock::size
std::istream::pos_type size() const
Returns the size of the data block.
Definition: abstractattachment.h:69
TagParser::AbstractAttachment::name
const std::string & name() const
Returns the (file) name of the attachment.
Definition: abstractattachment.h:167
TagParser::AbstractAttachment::setName
void setName(const std::string &name)
Sets the (file) name of the attachment.
Definition: abstractattachment.h:175
TagParser::Mp4TagExtendedNameIds::label
const char * label
Definition: mp4ids.cpp:31
TagParser::AbstractAttachment::setId
void setId(const std::uint64_t &id)
Sets the ID of the attachment.
Definition: abstractattachment.h:207
TagParser::AbstractAttachment::setDescription
void setDescription(const std::string &description)
Sets a description of the attachment.
Definition: abstractattachment.h:159
TagParser::AbstractAttachment::mimeType
const std::string & mimeType() const
Returns the MIME-type of the attachment.
Definition: abstractattachment.h:183
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser::AbstractAttachment::isDataFromFile
bool isDataFromFile() const
Returns whether the assigned data has been assigned using the setFile() method.
Definition: abstractattachment.h:238
TagParser::AbstractAttachment::id
std::uint64_t id() const
Returns the ID of the attachment.
Definition: abstractattachment.h:199
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::StreamDataBlock::m_endOffset
std::istream::pos_type m_endOffset
Definition: abstractattachment.h:36
TagParser::AbstractAttachment::isEmpty
bool isEmpty() const
Returns whether the attachment is empty (no data and no meta-data assigned).
Definition: abstractattachment.h:268
TagParser::StreamDataBlock::m_startOffset
std::istream::pos_type m_startOffset
Definition: abstractattachment.h:35
TagParser::StreamDataBlock::buffer
const std::unique_ptr< char[]> & buffer() const
Returns the data buffered via makeBuffer().
Definition: abstractattachment.h:77
TagParser::StreamDataBlock::discardBuffer
void discardBuffer()
Discards buffered data.
Definition: abstractattachment.h:85
TagParser::StreamDataBlock::m_stream
std::function< std::istream &()> m_stream
Definition: abstractattachment.h:34
TagParser::StreamDataBlock
The StreamDataBlock class is a reference to a certain data block of a stream.
Definition: abstractattachment.h:15
diagnostics.h
TagParser::FileDataBlock
The FileDataBlock class is a reference to a certain data block of a file stream.
Definition: abstractattachment.h:90
TagParser::AbstractAttachment::setData
void setData(std::unique_ptr< StreamDataBlock > &&data)
Sets the data for the attachment.
Definition: abstractattachment.h:229
TagParser::AbstractAttachment::description
const std::string & description() const
Returns a description of the attachment.
Definition: abstractattachment.h:151
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagParser::AbstractAttachment::AbstractAttachment
AbstractAttachment()
Constructs a new attachment.
Definition: abstractattachment.h:141
TagParser::AbstractAttachment::data
const StreamDataBlock * data() const
Returns a reference to the data of the attachment.
Definition: abstractattachment.h:219
TagParser::StreamDataBlock::m_buffer
std::unique_ptr< char[]> m_buffer
Definition: abstractattachment.h:37
TagParser::StreamDataBlock::endOffset
std::istream::pos_type endOffset() const
Returns the absolute end offset of the data block in the stream.
Definition: abstractattachment.h:61
TagParser::MediaFileInfo
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition: mediafileinfo.h:45
TagParser::FileDataBlock::fileInfo
const MediaFileInfo * fileInfo() const
Definition: abstractattachment.h:100
TagParser::MatroskaTagIds::description
constexpr const TAG_PARSER_EXPORT char * description()
Definition: matroskatagid.h:234