A factory for creating ID3v2 frames during parsing. More...
#include <id3v2framefactory.h>
Public Member Functions | |
FrameFactory (const FrameFactory &)=delete | |
FrameFactory & | operator= (const FrameFactory &)=delete |
virtual Frame * | createFrame (const ByteVector &origData, const Header *tagHeader) const |
virtual Frame * | createFrameForProperty (const String &key, const StringList &values) const |
virtual void | rebuildAggregateFrames (ID3v2::Tag *tag) const |
String::Type | defaultTextEncoding () const |
void | setDefaultTextEncoding (String::Type encoding) |
bool | isUsingDefaultTextEncoding () const |
Static Public Member Functions | |
static FrameFactory * | instance () |
Protected Member Functions | |
FrameFactory () | |
~FrameFactory () | |
virtual bool | updateFrame (Frame::Header *header) const |
std::pair< Frame::Header *, bool > | prepareFrameHeader (ByteVector &data, const Header *tagHeader) const |
virtual Frame * | createFrame (const ByteVector &data, Frame::Header *header, const Header *tagHeader) const |
A factory for creating ID3v2 frames during parsing.
This factory abstracts away the frame creation process and instantiates the appropriate ID3v2::Frame subclasses based on the contents of the data.
Reimplementing this factory is the key to adding support for frame types not directly supported by TagLib to your application. To do so you would subclass this factory and reimplement createFrame(). Then by setting your factory to be the default factory in ID3v2::Tag constructor you can implement behavior that will allow for new ID3v2::Frame subclasses (also provided by you) to be used. See tests/test_id3v2framefactory.cpp for an example.
This implements both abstract factory and singleton patterns of which more information is available on the web and in software design textbooks (notably Design Patterns).
new
) and add them to a tag using ID3v2::Tag::addFrame()
|
delete |
|
protected |
Constructs a frame factory. Because this is a singleton this method is protected, but may be used for subclasses.
|
protected |
Destroys the frame factory.
|
protectedvirtual |
Create a frame based on data. header should be a valid frame header and tagHeader a valid ID3v2::Header instance.
This method is called by the public overloaded method createFrame(const ByteVector &, const Header *) after creating header from verified data using prepareFrameHeader(), so this method is provided to be reimplemented in derived classes.
|
virtual |
Create a frame based on origData. tagHeader should be a valid ID3v2::Header instance.
|
virtual |
Creates a textual frame which corresponds to a single key in the PropertyMap interface. TIPL and TMCL do not belong to this category and are thus handled explicitly in the Frame class.
String::Type TagLib::ID3v2::FrameFactory::defaultTextEncoding | ( | ) | const |
Returns the default text encoding for text frames. If setTextEncoding() has not been explicitly called this will only be used for new text frames. However, if this value has been set explicitly all frames will be converted to this type (unless it's explicitly set differently for the individual frame) when being rendered.
|
static |
bool TagLib::ID3v2::FrameFactory::isUsingDefaultTextEncoding | ( | ) | const |
Returns true
if defaultTextEncoding() is used. The default text encoding is used when setDefaultTextEncoding() has been called. In this case, reimplementations of FrameFactory should use defaultTextEncoding() on the frames (having a text encoding field) they create.
|
delete |
|
protected |
Creates and prepares the frame header for createFrame().
data | data of the frame (might be modified) |
tagHeader | the tag header |
true
if the frame is supported.
|
virtual |
After a tag has been read, this tries to rebuild some of them information, most notably the recording date, from frames that have been deprecated and can't be upgraded directly.
void TagLib::ID3v2::FrameFactory::setDefaultTextEncoding | ( | String::Type | encoding | ) |
Set the default text encoding for all text frames that are created to encoding. If no value is set the frames with either default to the encoding type that was parsed and new frames default to Latin1.
Valid string types for ID3v2 tags are Latin1, UTF8, UTF16 and UTF16BE.
|
protectedvirtual |
This method checks for compliance to the current ID3v2 standard (2.4) and does nothing in the common case. However if a frame is found that is not compatible with the current standard, this method either updates the frame or indicates that it should be discarded.
This method with return true
(with or without changes to the frame) if this frame should be kept or false
if it should be discarded.
See the id3v2.4.0-changes.txt document for further information.