2018-03-06 23:09:15 +01:00
|
|
|
#ifndef TAG_PARSER_MATROSKATAG_H
|
|
|
|
#define TAG_PARSER_MATROSKATAG_H
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "./matroskatagfield.h"
|
2016-05-26 01:59:22 +02:00
|
|
|
#include "./matroskatagid.h"
|
2015-09-06 15:42:18 +02:00
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "../fieldbasedtag.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
namespace TagParser {
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
class EbmlElement;
|
|
|
|
class MatroskaTag;
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
class TAG_PARSER_EXPORT MatroskaTagMaker {
|
2015-04-22 19:22:01 +02:00
|
|
|
friend class MatroskaTag;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void make(std::ostream &stream) const;
|
|
|
|
const MatroskaTag &tag() const;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t requiredSize() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
private:
|
2018-03-05 17:49:29 +01:00
|
|
|
MatroskaTagMaker(MatroskaTag &tag, Diagnostics &diag);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
MatroskaTag &m_tag;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t m_targetsSize;
|
|
|
|
std::uint64_t m_simpleTagsSize;
|
2015-12-22 23:54:35 +01:00
|
|
|
std::vector<MatroskaTagFieldMaker> m_maker;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t m_tagSize;
|
|
|
|
std::uint64_t m_totalSize;
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the associated tag.
|
|
|
|
*/
|
|
|
|
inline const MatroskaTag &MatroskaTagMaker::tag() const
|
|
|
|
{
|
|
|
|
return m_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the number of bytes which will be written when making the tag.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t MatroskaTagMaker::requiredSize() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_totalSize;
|
|
|
|
}
|
|
|
|
|
2017-03-07 00:02:59 +01:00
|
|
|
/*!
|
|
|
|
* \brief Defines traits for the TagField implementation of the MatroskaTag class.
|
|
|
|
*/
|
2018-03-07 01:17:50 +01:00
|
|
|
template <> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<MatroskaTag> {
|
2017-03-07 00:02:59 +01:00
|
|
|
public:
|
2018-07-11 13:19:43 +02:00
|
|
|
using FieldType = MatroskaTagField;
|
|
|
|
using Compare = std::less<typename FieldType::IdentifierType>;
|
2017-03-07 00:02:59 +01:00
|
|
|
};
|
|
|
|
|
2020-12-18 21:13:52 +01:00
|
|
|
class TAG_PARSER_EXPORT MatroskaTag final : public FieldMapBasedTag<MatroskaTag> {
|
2017-03-07 01:52:26 +01:00
|
|
|
friend class FieldMapBasedTag<MatroskaTag>;
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
public:
|
|
|
|
MatroskaTag();
|
|
|
|
|
2017-01-23 00:25:53 +01:00
|
|
|
static constexpr TagType tagType = TagType::MatroskaTag;
|
2017-03-07 00:02:59 +01:00
|
|
|
static constexpr const char *tagName = "Matroska tag";
|
|
|
|
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
|
2018-07-13 12:25:00 +02:00
|
|
|
bool canEncodingBeUsed(TagTextEncoding encoding) const override;
|
|
|
|
bool supportsTarget() const override;
|
|
|
|
bool supportsMultipleValues(KnownField field) const override;
|
|
|
|
TagTargetLevel targetLevel() const override;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-05 17:49:29 +01:00
|
|
|
void parse(EbmlElement &tagElement, Diagnostics &diag);
|
|
|
|
MatroskaTagMaker prepareMaking(Diagnostics &diag);
|
|
|
|
void make(std::ostream &stream, Diagnostics &diag);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2017-03-07 01:52:26 +01:00
|
|
|
protected:
|
2017-03-07 17:16:17 +01:00
|
|
|
IdentifierType internallyGetFieldId(KnownField field) const;
|
|
|
|
KnownField internallyGetKnownField(const IdentifierType &id) const;
|
2017-03-07 01:52:26 +01:00
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
private:
|
2018-03-05 17:49:29 +01:00
|
|
|
void parseTargets(EbmlElement &targetsElement, Diagnostics &diag);
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Constructs a new tag.
|
|
|
|
*/
|
|
|
|
inline MatroskaTag::MatroskaTag()
|
2018-03-07 01:17:50 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2016-05-26 01:59:22 +02:00
|
|
|
inline bool MatroskaTag::supportsTarget() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:25:00 +02:00
|
|
|
/*!
|
|
|
|
* \brief Allows multiple values for all fields.
|
|
|
|
* \remarks "Multiple items should never be stored as a list in a single TagString. If there is
|
|
|
|
* more than one tag of a certain type to be stored, then more than one SimpleTag should be used."
|
|
|
|
*/
|
|
|
|
inline bool MatroskaTag::supportsMultipleValues(KnownField) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-26 01:59:22 +02:00
|
|
|
inline TagTargetLevel MatroskaTag::targetLevel() const
|
|
|
|
{
|
|
|
|
return matroskaTagTargetLevel(m_target.level());
|
|
|
|
}
|
|
|
|
|
2018-07-10 17:07:34 +02:00
|
|
|
/*!
|
|
|
|
* \brief Prepares making.
|
|
|
|
* \returns Returns a MatroskaTagMaker object which can be used to actually make the tag.
|
|
|
|
* \remarks The tag must NOT be mutated after making is prepared when it is intended to actually
|
|
|
|
* make the tag using the make() method of the returned object.
|
|
|
|
* \throws Throws TagParser::Failure or a derived exception when a making error occurs.
|
|
|
|
*
|
|
|
|
* This method might be useful when it is necessary to know the size of the tag before making it.
|
|
|
|
* \sa make()
|
|
|
|
*/
|
|
|
|
inline MatroskaTagMaker MatroskaTag::prepareMaking(Diagnostics &diag)
|
|
|
|
{
|
|
|
|
return MatroskaTagMaker(*this, diag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Writes tag information to the specified \a stream (makes a "Tag"-element).
|
|
|
|
* \throws Throws std::ios_base::failure when an IO error occurs.
|
|
|
|
* \throws Throws TagParser::Failure or a derived exception when a making
|
|
|
|
* error occurs.
|
|
|
|
* \sa prepareMaking()
|
|
|
|
*/
|
|
|
|
inline void MatroskaTag::make(std::ostream &stream, Diagnostics &diag)
|
|
|
|
{
|
|
|
|
prepareMaking(diag).make(stream);
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
inline bool MatroskaTag::canEncodingBeUsed(TagTextEncoding encoding) const
|
|
|
|
{
|
|
|
|
return encoding == TagTextEncoding::Utf8;
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
} // namespace TagParser
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
#endif // TAG_PARSER_MATROSKATAG_H
|