tagparser/vorbis/vorbiscommentfield.h

105 lines
3.3 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_VORBISCOMMENTFIELD_H
#define TAG_PARSER_VORBISCOMMENTFIELD_H
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "../generictagfield.h"
2015-04-22 19:22:01 +02:00
2019-06-10 22:49:11 +02:00
namespace CppUtilities {
2015-04-22 19:22:01 +02:00
class BinaryReader;
class BinaryWriter;
2019-06-12 20:40:45 +02:00
} // namespace CppUtilities
2015-04-22 19:22:01 +02:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
2016-05-16 20:56:53 +02:00
/*!
* \brief The VorbisCommentFlags enum specifies flags which controls parsing and making of Vorbis comments.
*/
2019-03-13 19:06:42 +01:00
enum class VorbisCommentFlags : std::uint8_t {
2016-05-16 20:56:53 +02:00
None = 0x0, /**< Regular parsing/making. */
NoSignature = 0x1, /**< Skips the signature when parsing and making. */
NoFramingByte = 0x2, /**< Doesn't expect the framing bit to be present when parsing; does not make the framing bit when making. */
NoCovers = 0x4 /**< Skips all covers when making. */
};
constexpr bool operator&(VorbisCommentFlags lhs, VorbisCommentFlags rhs)
2016-05-16 20:56:53 +02:00
{
2019-03-13 19:06:42 +01:00
return static_cast<std::uint8_t>(lhs) & static_cast<std::uint8_t>(rhs);
2016-05-16 20:56:53 +02:00
}
constexpr VorbisCommentFlags operator|(VorbisCommentFlags lhs, VorbisCommentFlags rhs)
2016-05-16 20:56:53 +02:00
{
2019-03-13 19:06:42 +01:00
return static_cast<VorbisCommentFlags>(static_cast<std::uint8_t>(lhs) | static_cast<std::uint8_t>(rhs));
2016-05-16 20:56:53 +02:00
}
2015-04-22 19:22:01 +02:00
class VorbisCommentField;
class Diagnostics;
2015-04-22 19:22:01 +02:00
/*!
* \brief Defines traits for the TagField implementation of the VorbisCommentField class.
*/
2018-03-07 01:17:50 +01:00
template <> class TAG_PARSER_EXPORT TagFieldTraits<VorbisCommentField> {
2015-04-22 19:22:01 +02:00
public:
2018-07-11 13:19:43 +02:00
using IdentifierType = std::string;
2019-03-13 19:06:42 +01:00
using TypeInfoType = std::uint32_t;
2015-04-22 19:22:01 +02:00
};
class OggIterator;
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT VorbisCommentField : public TagField<VorbisCommentField> {
2015-04-22 19:22:01 +02:00
friend class TagField<VorbisCommentField>;
public:
VorbisCommentField();
VorbisCommentField(const IdentifierType &id, const TagValue &value);
2015-04-22 19:22:01 +02:00
void parse(OggIterator &iterator, Diagnostics &diag);
2019-03-13 19:06:42 +01:00
void parse(OggIterator &iterator, std::uint64_t &maxSize, Diagnostics &diag);
void parse(std::istream &stream, std::uint64_t &maxSize, Diagnostics &diag);
2019-06-10 22:49:11 +02:00
bool make(CppUtilities::BinaryWriter &writer, VorbisCommentFlags flags, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
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);
2016-05-16 20:56:53 +02:00
private:
2019-03-13 19:06:42 +01:00
template <class StreamType> void internalParse(StreamType &stream, std::uint64_t &maxSize, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
};
/*!
* \brief Returns whether the additional type info is used.
*/
inline bool VorbisCommentField::isAdditionalTypeInfoUsed() const
{
return false;
}
/*!
* \brief Returns whether nested fields are supported.
*/
inline bool VorbisCommentField::supportsNestedFields() const
{
return false;
}
/*!
* \brief Converts the specified ID string representation to an actual ID.
* \remarks As Vorbis field IDs are plain text the string is just passed.
*/
inline std::string VorbisCommentField::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 Vorbis field IDs are plain text the string is just passed.
*/
inline std::string VorbisCommentField::fieldIdToString(const std::string &id)
{
return id;
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
#endif // TAG_PARSER_VORBISCOMMENTFIELD_H