2015-04-22 19:22:01 +02:00
|
|
|
#ifndef MEDIA_ABSTRACTATTACHMENT_H
|
|
|
|
#define MEDIA_ABSTRACTATTACHMENT_H
|
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "./statusprovider.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
class MediaFileInfo;
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT StreamDataBlock
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
StreamDataBlock(const std::function<std::istream & ()> &stream,
|
|
|
|
std::istream::off_type startOffset = 0, std::ios_base::seekdir startDir = std::ios_base::beg,
|
|
|
|
std::istream::off_type endOffset = 0, std::ios_base::seekdir endDir = std::ios_base::end);
|
|
|
|
|
|
|
|
std::istream &stream() const;
|
|
|
|
std::istream::pos_type startOffset() const;
|
|
|
|
std::istream::pos_type endOffset() const;
|
|
|
|
std::istream::pos_type size() const;
|
2015-11-26 14:22:44 +01:00
|
|
|
const std::unique_ptr<char[]> &buffer() const;
|
|
|
|
void makeBuffer() const;
|
2015-12-21 00:03:04 +01:00
|
|
|
void discardBuffer();
|
2016-08-04 00:16:19 +02:00
|
|
|
void copyTo(std::ostream &stream) const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
StreamDataBlock();
|
|
|
|
|
|
|
|
std::function<std::istream & ()> m_stream;
|
|
|
|
std::istream::pos_type m_startOffset;
|
|
|
|
std::istream::pos_type m_endOffset;
|
2015-11-26 14:22:44 +01:00
|
|
|
mutable std::unique_ptr<char[]> m_buffer;
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the associated stream.
|
|
|
|
*
|
|
|
|
* Calling this method on invalid objects causes undefined behaviour. See isValid().
|
|
|
|
*/
|
|
|
|
inline std::istream &StreamDataBlock::stream() const
|
|
|
|
{
|
|
|
|
return m_stream();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the absolute start offset of the data block in the stream.
|
|
|
|
*/
|
|
|
|
inline std::istream::pos_type StreamDataBlock::startOffset() const
|
|
|
|
{
|
|
|
|
return m_startOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the absolute end offset of the data block in the stream.
|
|
|
|
*/
|
|
|
|
inline std::istream::pos_type StreamDataBlock::endOffset() const
|
|
|
|
{
|
|
|
|
return m_endOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the size of the data block.
|
|
|
|
*/
|
|
|
|
inline std::istream::pos_type StreamDataBlock::size() const
|
|
|
|
{
|
|
|
|
return m_endOffset - m_startOffset;
|
|
|
|
}
|
|
|
|
|
2015-11-26 14:22:44 +01:00
|
|
|
/*!
|
|
|
|
* \brief Returns the data buffered via makeBuffer().
|
|
|
|
*/
|
|
|
|
inline const std::unique_ptr<char[]> &StreamDataBlock::buffer() const
|
|
|
|
{
|
|
|
|
return m_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2015-12-21 00:03:04 +01:00
|
|
|
* \brief Discards buffered data.
|
2015-11-26 14:22:44 +01:00
|
|
|
*/
|
2015-12-21 00:03:04 +01:00
|
|
|
inline void StreamDataBlock::discardBuffer()
|
2015-11-26 14:22:44 +01:00
|
|
|
{
|
2015-12-21 00:03:04 +01:00
|
|
|
m_buffer.reset();
|
2015-11-26 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT FileDataBlock : public StreamDataBlock
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileDataBlock(const std::string &path);
|
|
|
|
const MediaFileInfo *fileInfo() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<MediaFileInfo> m_fileInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const MediaFileInfo *FileDataBlock::fileInfo() const
|
|
|
|
{
|
|
|
|
return m_fileInfo.get();
|
|
|
|
}
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT AbstractAttachment : public StatusProvider
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
const std::string &description() const;
|
|
|
|
void setDescription(const std::string &description);
|
|
|
|
const std::string &name() const;
|
|
|
|
void setName(const std::string &name);
|
|
|
|
const std::string &mimeType() const;
|
|
|
|
void setMimeType(const std::string &mimeType);
|
|
|
|
uint64 id() const;
|
|
|
|
void setId(const uint64 &id);
|
|
|
|
const StreamDataBlock *data() const;
|
|
|
|
void setData(std::unique_ptr<StreamDataBlock> &&data);
|
|
|
|
void setFile(const std::string &path);
|
2015-11-26 14:22:44 +01:00
|
|
|
bool isDataFromFile() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
std::string label() const;
|
|
|
|
void clear();
|
|
|
|
bool isIgnored() const;
|
|
|
|
void setIgnored(bool ignored);
|
2015-10-06 22:29:29 +02:00
|
|
|
bool isEmpty() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AbstractAttachment();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_description;
|
|
|
|
std::string m_name;
|
|
|
|
std::string m_mimeType;
|
|
|
|
uint64 m_id;
|
|
|
|
std::unique_ptr<StreamDataBlock> m_data;
|
2015-11-26 14:22:44 +01:00
|
|
|
bool m_isDataFromFile;
|
2015-04-22 19:22:01 +02:00
|
|
|
bool m_ignored;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Constructs a new attachment.
|
|
|
|
*/
|
|
|
|
inline AbstractAttachment::AbstractAttachment() :
|
|
|
|
m_id(0),
|
2015-11-26 14:22:44 +01:00
|
|
|
m_isDataFromFile(false),
|
2015-04-22 19:22:01 +02:00
|
|
|
m_ignored(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns a description of the attachment.
|
|
|
|
*/
|
|
|
|
inline const std::string &AbstractAttachment::description() const
|
|
|
|
{
|
|
|
|
return m_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets a description of the attachment.
|
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setDescription(const std::string &description)
|
|
|
|
{
|
|
|
|
m_description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the (file) name of the attachment.
|
|
|
|
*/
|
|
|
|
inline const std::string &AbstractAttachment::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the (file) name of the attachment.
|
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setName(const std::string &name)
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the MIME-type of the attachment.
|
|
|
|
*/
|
|
|
|
inline const std::string &AbstractAttachment::mimeType() const
|
|
|
|
{
|
|
|
|
return m_mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the MIME-type of the attachment.
|
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setMimeType(const std::string &mimeType)
|
|
|
|
{
|
|
|
|
m_mimeType = mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the ID of the attachment.
|
|
|
|
*/
|
|
|
|
inline uint64 AbstractAttachment::id() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the ID of the attachment.
|
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setId(const uint64 &id)
|
|
|
|
{
|
|
|
|
m_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns a reference to the data of the attachment.
|
2016-08-04 00:16:19 +02:00
|
|
|
* \remarks
|
|
|
|
* - The reference might be nullptr if there is no data assigned.
|
|
|
|
* - The attachment keeps ownership over the reference.
|
|
|
|
* \sa setData(), setFile()
|
2015-04-22 19:22:01 +02:00
|
|
|
*/
|
|
|
|
inline const StreamDataBlock *AbstractAttachment::data() const
|
|
|
|
{
|
|
|
|
return m_data.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the \a data for the attachment.
|
2016-08-04 00:16:19 +02:00
|
|
|
* \remarks The specified \a data is moved to the attachment.
|
|
|
|
* \sa data(), setFile()
|
2015-04-22 19:22:01 +02:00
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setData(std::unique_ptr<StreamDataBlock> &&data)
|
|
|
|
{
|
|
|
|
m_data = std::move(data);
|
2015-11-26 14:22:44 +01:00
|
|
|
m_isDataFromFile = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns whether the assigned data has been assigned using the setFile() method.
|
|
|
|
*/
|
|
|
|
inline bool AbstractAttachment::isDataFromFile() const
|
|
|
|
{
|
|
|
|
return m_isDataFromFile;
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns whether the attachment is ignored/omitted when rewriting the container.
|
|
|
|
*
|
|
|
|
* The default value is false.
|
|
|
|
* \sa setIgnored()
|
|
|
|
*/
|
|
|
|
inline bool AbstractAttachment::isIgnored() const
|
|
|
|
{
|
|
|
|
return m_ignored;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets whether the attachment is ignored/omitted when rewriting the container.
|
|
|
|
*
|
|
|
|
* \sa isIgnored()
|
|
|
|
*/
|
|
|
|
inline void AbstractAttachment::setIgnored(bool ignored)
|
|
|
|
{
|
|
|
|
m_ignored = ignored;
|
|
|
|
}
|
|
|
|
|
2015-10-06 22:29:29 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns whether the attachment is empty (no data and no meta-data assigned).
|
|
|
|
* \remarks Does not take into account whether an ID is set.
|
|
|
|
*/
|
|
|
|
inline bool AbstractAttachment::isEmpty() const
|
|
|
|
{
|
|
|
|
return m_description.empty() && m_name.empty() && !m_mimeType.empty() && !m_data;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
} // namespace Media
|
|
|
|
|
|
|
|
#endif // MEDIA_ABSTRACTATTACHMENT_H
|