tagparser/matroska/matroskatagfield.h
Martchus 6b469f1c26 Add Locale class to deal with differently specified languages/countries
Different media/tag formats specify languages and countries
differently. This change introduces a Locale class to keep track
of the format being used. So far there are no automatic conversions
implemented so it is entirely up to the user to pass valid values using
a format which matches the one required by the media/tag format.

This change also adds support for Matroska's IETF elements so at least the
raw value can be read, written and is preserved.
2020-12-16 17:48:08 +01:00

131 lines
3.3 KiB
C++

#ifndef TAG_PARSER_MATROSKATAGFIELD_H
#define TAG_PARSER_MATROSKATAGFIELD_H
#include "../generictagfield.h"
namespace TagParser {
class EbmlElement;
class MatroskaTagField;
class Diagnostics;
/*!
* \brief Defines traits for the TagField implementation of the MatroskaTagField class.
*/
template <> class TAG_PARSER_EXPORT TagFieldTraits<MatroskaTagField> {
public:
using IdentifierType = std::string;
using TypeInfoType = std::string;
static bool supportsNestedFields();
};
/*!
* \brief The MatroskaTagField supports nested fields.
*/
inline bool TagFieldTraits<MatroskaTagField>::supportsNestedFields()
{
return true;
}
class TAG_PARSER_EXPORT MatroskaTagFieldMaker {
friend class MatroskaTagField;
public:
void make(std::ostream &stream) const;
const MatroskaTagField &field() const;
std::uint64_t requiredSize() const;
private:
MatroskaTagFieldMaker(MatroskaTagField &field, Diagnostics &diag);
MatroskaTagField &m_field;
std::string m_stringValue;
const std::string &m_language;
const std::string &m_languageIETF;
std::uint64_t m_simpleTagSize;
std::uint64_t m_totalSize;
std::vector<MatroskaTagFieldMaker> m_nestedMaker;
bool m_isBinary;
};
/*!
* \brief Returns the associated field.
*/
inline const MatroskaTagField &MatroskaTagFieldMaker::field() const
{
return m_field;
}
/*!
* \brief Returns number of bytes which will be written when making the field.
*/
inline std::uint64_t MatroskaTagFieldMaker::requiredSize() const
{
return m_totalSize;
}
class TAG_PARSER_EXPORT MatroskaTagField : public TagField<MatroskaTagField> {
friend class TagField<MatroskaTagField>;
public:
MatroskaTagField();
MatroskaTagField(const std::string &id, const TagValue &value);
void reparse(EbmlElement &simpleTagElement, Diagnostics &diag, bool parseNestedFields = true);
MatroskaTagFieldMaker prepareMaking(Diagnostics &diag);
void make(std::ostream &stream, Diagnostics &diag);
bool isAdditionalTypeInfoUsed() const;
bool supportsNestedFields() const;
static typename std::string fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
static std::string fieldIdToString(const std::string &id);
private:
void reset();
};
/*!
* \brief Returns whether the additional type info is used.
*/
inline bool MatroskaTagField::isAdditionalTypeInfoUsed() const
{
return false;
}
/*!
* \brief Returns whether nested fields are supported.
*/
inline bool MatroskaTagField::supportsNestedFields() const
{
return true;
}
/*!
* \brief Converts the specified ID string representation to an actual ID.
* \remarks As Matroska field IDs are text strings the string is just passed.
*/
inline std::string MatroskaTagField::fieldIdFromString(const char *idString, std::size_t idStringSize)
{
return idStringSize != std::string::npos ? std::string(idString, idStringSize) : std::string(idString);
}
/*!
* \brief Returns the string representation for the specified \a id.
* \remarks As Matroska field IDs are text strings the string is just passed.
*/
inline std::string MatroskaTagField::fieldIdToString(const std::string &id)
{
return id;
}
/*!
* \brief Resets Matroska-specific values. Called via clear().
*/
inline void MatroskaTagField::reset()
{
}
} // namespace TagParser
#endif // TAG_PARSER_MATROSKATAGFIELD_H