mp4itemfactory.h
Go to the documentation of this file.
/***************************************************************************
copyright : (C) 2023 by Urs Fleisch
email : ufleisch@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifndef TAGLIB_MP4ITEMFACTORY_H
#define TAGLIB_MP4ITEMFACTORY_H
#include <memory>
#include "taglib_export.h"
#include "mp4item.h"
namespace TagLib {
namespace MP4 {
class TAGLIB_EXPORT ItemFactory
{
public:
ItemFactory(const ItemFactory &) = delete;
ItemFactory &operator=(const ItemFactory &) = delete;
static ItemFactory *instance();
virtual std::pair<String, Item> parseItem(
const Atom *atom, const ByteVector &data) const;
virtual ByteVector renderItem(
const String &itemName, const Item &item) const;
virtual std::pair<ByteVector, Item> itemFromProperty(
const String &key, const StringList &values) const;
virtual std::pair<String, StringList> itemToProperty(
const ByteVector &itemName, const Item &item) const;
virtual String propertyKeyForName(const ByteVector &name) const;
virtual ByteVector nameForPropertyKey(const String &key) const;
protected:
enum class ItemHandlerType {
Unknown,
FreeForm,
IntPair,
IntPairNoTrailing,
Bool,
Int,
TextOrInt,
UInt,
LongLong,
Byte,
Gnre,
Covr,
Stem,
TextImplicit,
Text
};
using NameHandlerMap = Map<ByteVector, ItemHandlerType>;
ItemFactory();
~ItemFactory();
virtual NameHandlerMap nameHandlerMap() const;
virtual ItemHandlerType handlerTypeForName(const ByteVector &name) const;
virtual Map<ByteVector, String> namePropertyMap() const;
// Functions used by parseItem() to create items from atom data.
static MP4::AtomDataList parseData2(
const MP4::Atom *atom, const ByteVector &data, int expectedFlags = -1,
bool freeForm = false);
static ByteVectorList parseData(
const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = -1,
bool freeForm = false);
static std::pair<String, Item> parseText(
const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags = 1);
static std::pair<String, Item> parseFreeForm(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseInt(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseByte(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseTextOrInt(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseUInt(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseLongLong(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseGnre(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseIntPair(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseBool(
const MP4::Atom *atom, const ByteVector &bytes);
static std::pair<String, Item> parseCovr(
const MP4::Atom *atom, const ByteVector &data);
static std::pair<String, Item> parseStem(
const MP4::Atom *atom, const ByteVector &data);
// Functions used by renderItem() to render atom data for items.
static ByteVector renderAtom(
const ByteVector &name, const ByteVector &data);
static ByteVector renderData(
const ByteVector &name, int flags, const ByteVectorList &data);
static ByteVector renderText(
const ByteVector &name, const MP4::Item &item, int flags = TypeUTF8);
static ByteVector renderFreeForm(
const String &name, const MP4::Item &item);
static ByteVector renderBool(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderInt(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderTextOrInt(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderByte(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderUInt(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderLongLong(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderIntPair(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderIntPairNoTrailing(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderCovr(
const ByteVector &name, const MP4::Item &item);
static ByteVector renderStem(
const ByteVector &name, const MP4::Item &item);
private:
static ItemFactory factory;
class ItemFactoryPrivate;
TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
std::unique_ptr<ItemFactoryPrivate> d;
};
} // namespace MP4
} // namespace TagLib
#endif
TagLib::ByteVectorList
A list of ByteVectors.
Definition tbytevectorlist.h:42
TagLib::ByteVector
A byte vector.
Definition tbytevector.h:46
TagLib::MP4::ItemFactory::renderText
static ByteVector renderText(const ByteVector &name, const MP4::Item &item, int flags=TypeUTF8)
TagLib::MP4::ItemFactory::instance
static ItemFactory * instance()
TagLib::MP4::ItemFactory::parseUInt
static std::pair< String, Item > parseUInt(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::~ItemFactory
~ItemFactory()
TagLib::MP4::ItemFactory::itemToProperty
virtual std::pair< String, StringList > itemToProperty(const ByteVector &itemName, const Item &item) const
TagLib::MP4::ItemFactory::parseTextOrInt
static std::pair< String, Item > parseTextOrInt(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::operator=
ItemFactory & operator=(const ItemFactory &)=delete
TagLib::MP4::ItemFactory::parseGnre
static std::pair< String, Item > parseGnre(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::renderIntPairNoTrailing
static ByteVector renderIntPairNoTrailing(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderInt
static ByteVector renderInt(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderByte
static ByteVector renderByte(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::parseFreeForm
static std::pair< String, Item > parseFreeForm(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::parseIntPair
static std::pair< String, Item > parseIntPair(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::renderItem
virtual ByteVector renderItem(const String &itemName, const Item &item) const
TagLib::MP4::ItemFactory::renderLongLong
static ByteVector renderLongLong(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::parseData
static ByteVectorList parseData(const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags=-1, bool freeForm=false)
TagLib::MP4::ItemFactory::nameForPropertyKey
virtual ByteVector nameForPropertyKey(const String &key) const
TagLib::MP4::ItemFactory::renderBool
static ByteVector renderBool(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderAtom
static ByteVector renderAtom(const ByteVector &name, const ByteVector &data)
TagLib::MP4::ItemFactory::NameHandlerMap
Map< ByteVector, ItemHandlerType > NameHandlerMap
Definition mp4itemfactory.h:151
TagLib::MP4::ItemFactory::parseLongLong
static std::pair< String, Item > parseLongLong(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::renderStem
static ByteVector renderStem(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::parseData2
static MP4::AtomDataList parseData2(const MP4::Atom *atom, const ByteVector &data, int expectedFlags=-1, bool freeForm=false)
TagLib::MP4::ItemFactory::ItemFactory
ItemFactory()
TagLib::MP4::ItemFactory::renderCovr
static ByteVector renderCovr(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderTextOrInt
static ByteVector renderTextOrInt(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::handlerTypeForName
virtual ItemHandlerType handlerTypeForName(const ByteVector &name) const
TagLib::MP4::ItemFactory::itemFromProperty
virtual std::pair< ByteVector, Item > itemFromProperty(const String &key, const StringList &values) const
TagLib::MP4::ItemFactory::parseInt
static std::pair< String, Item > parseInt(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::ItemHandlerType
ItemHandlerType
Definition mp4itemfactory.h:132
TagLib::MP4::ItemFactory::renderData
static ByteVector renderData(const ByteVector &name, int flags, const ByteVectorList &data)
TagLib::MP4::ItemFactory::propertyKeyForName
virtual String propertyKeyForName(const ByteVector &name) const
TagLib::MP4::ItemFactory::parseBool
static std::pair< String, Item > parseBool(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::parseCovr
static std::pair< String, Item > parseCovr(const MP4::Atom *atom, const ByteVector &data)
TagLib::MP4::ItemFactory::parseByte
static std::pair< String, Item > parseByte(const MP4::Atom *atom, const ByteVector &bytes)
TagLib::MP4::ItemFactory::namePropertyMap
virtual Map< ByteVector, String > namePropertyMap() const
TagLib::MP4::ItemFactory::ItemFactory
ItemFactory(const ItemFactory &)=delete
TagLib::MP4::ItemFactory::parseText
static std::pair< String, Item > parseText(const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags=1)
TagLib::MP4::ItemFactory::nameHandlerMap
virtual NameHandlerMap nameHandlerMap() const
TagLib::MP4::ItemFactory::renderIntPair
static ByteVector renderIntPair(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderFreeForm
static ByteVector renderFreeForm(const String &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::renderUInt
static ByteVector renderUInt(const ByteVector &name, const MP4::Item &item)
TagLib::MP4::ItemFactory::parseStem
static std::pair< String, Item > parseStem(const MP4::Atom *atom, const ByteVector &data)
TagLib::MP4::ItemFactory::parseItem
virtual std::pair< String, Item > parseItem(const Atom *atom, const ByteVector &data) const
TagLib::MP4::Item
MP4 item.
Definition mp4item.h:38
TagLib::MP4::Stem
Definition mp4stem.h:41
TagLib::Map
A generic, implicitly shared map.
Definition tmap.h:45
TagLib::StringList
A list of strings.
Definition tstringlist.h:44
TagLib::String
A wide string class suitable for unicode.
Definition tstring.h:83
mp4item.h
TagLib::MP4
An implementation of MP4 (AAC, ALAC, ...) metadata.
Definition mp4atom.h:35
TagLib::MP4::TypeUTF8
@ TypeUTF8
Definition mp4atom.h:39
TagLib
A namespace for all TagLib related classes and functions.
Definition apefile.h:41
taglib_export.h
TAGLIB_EXPORT
#define TAGLIB_EXPORT
Definition taglib_export.h:40
TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition taglib_export.h:55