tagparser/matroska/matroskatag.h

135 lines
3.5 KiB
C
Raw Normal View History

#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
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;
uint64 requiredSize() const;
private:
MatroskaTagMaker(MatroskaTag &tag, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
MatroskaTag &m_tag;
uint64 m_targetsSize;
uint64 m_simpleTagsSize;
std::vector<MatroskaTagFieldMaker> m_maker;
2015-04-22 19:22:01 +02:00
uint64 m_tagSize;
uint64 m_totalSize;
};
/*!
* \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.
*/
inline uint64 MatroskaTagMaker::requiredSize() const
{
return m_totalSize;
}
/*!
* \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> {
public:
typedef MatroskaTagField FieldType;
typedef std::less<typename FieldType::IdentifierType> Compare;
};
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaTag : public FieldMapBasedTag<MatroskaTag> {
friend class FieldMapBasedTag<MatroskaTag>;
2015-04-22 19:22:01 +02:00
public:
MatroskaTag();
static constexpr TagType tagType = TagType::MatroskaTag;
static constexpr const char *tagName = "Matroska tag";
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
2015-04-22 19:22:01 +02:00
bool canEncodingBeUsed(TagTextEncoding encoding) const;
bool supportsTarget() const;
2016-05-26 01:59:22 +02:00
TagTargetLevel targetLevel() const;
2015-04-22 19:22:01 +02: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
protected:
IdentifierType internallyGetFieldId(KnownField field) const;
KnownField internallyGetKnownField(const IdentifierType &id) const;
2015-04-22 19:22:01 +02:00
private:
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;
}
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
#endif // TAG_PARSER_MATROSKATAG_H