Tag Parser: abstractattachment.h Source File

Tag Parser 12.5.3 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
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
11namespace TagParser {
12
13class AbortableProgressFeedback;
14class MediaFileInfo;
15
16 class TAG_PARSER_EXPORT StreamDataBlock {
17public:
18 StreamDataBlock(const std::function<std::istream &()> &stream, uint64_t startOffset = 0, std::ios_base::seekdir startDir = std::ios_base::beg,
19 uint64_t endOffset = 0, std::ios_base::seekdir endDir = std::ios_base::end);
20 virtual ~StreamDataBlock();
21
22 std::istream &stream() const;
23 std::uint64_t startOffset() const;
24 std::uint64_t endOffset() const;
25 std::uint64_t 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
31protected:
32 StreamDataBlock();
33
34 std::function<std::istream &()> m_stream;
35 std::uint64_t m_startOffset;
36 std::uint64_t 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::uint64_t StreamDataBlock::startOffset() const
54{
55 return m_startOffset;
56}
57
61 inline std::uint64_t StreamDataBlock::endOffset() const
62{
63 return m_endOffset;
64}
65
69 inline std::uint64_t 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
85 inline void StreamDataBlock::discardBuffer()
86{
87 m_buffer.reset();
88}
89
90 class TAG_PARSER_EXPORT FileDataBlock : public StreamDataBlock {
91public:
92 FileDataBlock(std::string_view path, Diagnostics &diag, AbortableProgressFeedback &progress);
93 ~FileDataBlock();
94 const MediaFileInfo *fileInfo() const;
95
96private:
97 std::unique_ptr<MediaFileInfo> m_fileInfo;
98};
99
100 inline const MediaFileInfo *FileDataBlock::fileInfo() const
101{
102 return m_fileInfo.get();
103}
104
105struct AbstractAttachmentPrivate;
106
107 class TAG_PARSER_EXPORT AbstractAttachment {
108public:
109 const std::string &description() const;
110 void setDescription(std::string_view description);
111 const std::string &name() const;
112 void setName(std::string_view name);
113 const std::string &mimeType() const;
114 void setMimeType(std::string_view mimeType);
115 std::uint64_t id() const;
116 void setId(std::uint64_t id);
117 const StreamDataBlock *data() const;
118 void setData(std::unique_ptr<StreamDataBlock> &&data);
119 void setFile(std::string_view path, Diagnostics &diag, AbortableProgressFeedback &progress);
120 bool isDataFromFile() const;
121 std::string label() const;
122 void clear();
123 bool isIgnored() const;
124 void setIgnored(bool ignored);
125 bool isEmpty() const;
126
127protected:
128 explicit AbstractAttachment();
129 virtual ~AbstractAttachment();
130
131private:
132 std::string m_description;
133 std::string m_name;
134 std::string m_mimeType;
135 std::uint64_t m_id;
136 std::unique_ptr<StreamDataBlock> m_data;
137 std::unique_ptr<AbstractAttachmentPrivate> m_p;
138 bool m_isDataFromFile;
139 bool m_ignored;
140};
141
145 inline const std::string &AbstractAttachment::description() const
146{
147 return m_description;
148}
149
153 inline void AbstractAttachment::setDescription(std::string_view description)
154{
155 m_description = description;
156}
157
161 inline const std::string &AbstractAttachment::name() const
162{
163 return m_name;
164}
165
169 inline void AbstractAttachment::setName(std::string_view name)
170{
171 m_name = name;
172}
173
177 inline const std::string &AbstractAttachment::mimeType() const
178{
179 return m_mimeType;
180}
181
185 inline void AbstractAttachment::setMimeType(std::string_view mimeType)
186{
187 m_mimeType = mimeType;
188}
189
193 inline std::uint64_t AbstractAttachment::id() const
194{
195 return m_id;
196}
197
201 inline void AbstractAttachment::setId(uint64_t id)
202{
203 m_id = id;
204}
205
213 inline const StreamDataBlock *AbstractAttachment::data() const
214{
215 return m_data.get();
216}
217
223 inline void AbstractAttachment::setData(std::unique_ptr<StreamDataBlock> &&data)
224{
225 m_data = std::move(data);
226 m_isDataFromFile = false;
227}
228
232 inline bool AbstractAttachment::isDataFromFile() const
233{
234 return m_isDataFromFile;
235}
236
243 inline bool AbstractAttachment::isIgnored() const
244{
245 return m_ignored;
246}
247
253 inline void AbstractAttachment::setIgnored(bool ignored)
254{
255 m_ignored = ignored;
256}
257
262 inline bool AbstractAttachment::isEmpty() const
263{
264 return m_description.empty() && m_name.empty() && !m_mimeType.empty() && !m_data;
265}
266
267} // namespace TagParser
268
269#endif // TAG_PARSER_ABSTRACTATTACHMENT_H
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
Definition progressfeedback.h:186
TagParser::AbstractAttachment::isEmpty
bool isEmpty() const
Returns whether the attachment is empty (no data and no meta-data assigned).
Definition abstractattachment.h:262
TagParser::AbstractAttachment::setDescription
void setDescription(std::string_view description)
Sets a description of the attachment.
Definition abstractattachment.h:153
TagParser::AbstractAttachment::clear
void clear()
Resets the object to its initial state.
Definition abstractattachment.cpp:169
TagParser::AbstractAttachment::mimeType
const std::string & mimeType() const
Returns the MIME-type of the attachment.
Definition abstractattachment.h:177
TagParser::AbstractAttachment::description
const std::string & description() const
Returns a description of the attachment.
Definition abstractattachment.h:145
TagParser::AbstractAttachment::setData
void setData(std::unique_ptr< StreamDataBlock > &&data)
Sets the data for the attachment.
Definition abstractattachment.h:223
TagParser::AbstractAttachment::name
const std::string & name() const
Returns the (file) name of the attachment.
Definition abstractattachment.h:161
TagParser::AbstractAttachment::id
std::uint64_t id() const
Returns the ID of the attachment.
Definition abstractattachment.h:193
TagParser::AbstractAttachment::setFile
void setFile(std::string_view path, Diagnostics &diag, AbortableProgressFeedback &progress)
Sets the data, name and MIME-type for the specified path.
Definition abstractattachment.cpp:191
TagParser::AbstractAttachment::isDataFromFile
bool isDataFromFile() const
Returns whether the assigned data has been assigned using the setFile() method.
Definition abstractattachment.h:232
TagParser::AbstractAttachment::setName
void setName(std::string_view name)
Sets the (file) name of the attachment.
Definition abstractattachment.h:169
TagParser::AbstractAttachment::label
std::string label() const
Returns a label for the track.
Definition abstractattachment.cpp:153
TagParser::AbstractAttachment::setIgnored
void setIgnored(bool ignored)
Sets whether the attachment is ignored/omitted when rewriting the container.
Definition abstractattachment.h:253
TagParser::AbstractAttachment::isIgnored
bool isIgnored() const
Returns whether the attachment is ignored/omitted when rewriting the container.
Definition abstractattachment.h:243
TagParser::AbstractAttachment::AbstractAttachment
AbstractAttachment()
Constructs a new attachment.
Definition abstractattachment.cpp:136
TagParser::AbstractAttachment::setId
void setId(std::uint64_t id)
Sets the ID of the attachment.
Definition abstractattachment.h:201
TagParser::AbstractAttachment::data
const StreamDataBlock * data() const
Returns a reference to the data of the attachment.
Definition abstractattachment.h:213
TagParser::AbstractAttachment::setMimeType
void setMimeType(std::string_view mimeType)
Sets the MIME-type of the attachment.
Definition abstractattachment.h:185
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::FileDataBlock::fileInfo
const MediaFileInfo * fileInfo() const
Definition abstractattachment.h:100
TagParser::FileDataBlock::FileDataBlock
FileDataBlock(std::string_view path, Diagnostics &diag, AbortableProgressFeedback &progress)
Constructs a new FileDataBlock with the specified path.
Definition abstractattachment.cpp:107
TagParser::MediaFileInfo
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition mediafileinfo.h:83
TagParser::StreamDataBlock
The StreamDataBlock class is a reference to a certain data block of a stream.
Definition abstractattachment.h:16
TagParser::StreamDataBlock::m_startOffset
std::uint64_t m_startOffset
Definition abstractattachment.h:35
TagParser::StreamDataBlock::m_endOffset
std::uint64_t m_endOffset
Definition abstractattachment.h:36
TagParser::StreamDataBlock::m_buffer
std::unique_ptr< char[]> m_buffer
Definition abstractattachment.h:37
TagParser::StreamDataBlock::makeBuffer
void makeBuffer() const
Buffers the data block.
Definition abstractattachment.cpp:73
TagParser::StreamDataBlock::buffer
const std::unique_ptr< char[]> & buffer() const
Returns the data buffered via makeBuffer().
Definition abstractattachment.h:77
TagParser::StreamDataBlock::startOffset
std::uint64_t startOffset() const
Returns the absolute start offset of the data block in the stream.
Definition abstractattachment.h:53
TagParser::StreamDataBlock::size
std::uint64_t size() const
Returns the size of the data block.
Definition abstractattachment.h:69
TagParser::StreamDataBlock::StreamDataBlock
StreamDataBlock(const std::function< std::istream &()> &stream, uint64_t startOffset=0, std::ios_base::seekdir startDir=std::ios_base::beg, uint64_t endOffset=0, std::ios_base::seekdir endDir=std::ios_base::end)
TagParser::StreamDataBlock::stream
std::istream & stream() const
Returns the associated stream.
Definition abstractattachment.h:45
TagParser::StreamDataBlock::copyTo
void copyTo(std::ostream &stream) const
Copies the data to the specified stream.
Definition abstractattachment.cpp:84
TagParser::StreamDataBlock::discardBuffer
void discardBuffer()
Discards buffered data.
Definition abstractattachment.h:85
TagParser::StreamDataBlock::endOffset
std::uint64_t endOffset() const
Returns the absolute end offset of the data block in the stream.
Definition abstractattachment.h:61
TagParser::StreamDataBlock::m_stream
std::function< std::istream &()> m_stream
Definition abstractattachment.h:34
diagnostics.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::AbstractAttachmentPrivate
The AbstractAttachmentPrivate struct contains private fields of the AbstractAttachment class.
Definition abstractattachment.cpp:18