Unify File constructors with ID3v2::FrameFactory parameter (#1196)

Make constructors consistent so that the FrameFactory is at the
end and optional. Mark the alternative constructors as deprecated.
This commit is contained in:
Urs Fleisch
2023-12-20 23:22:26 +01:00
parent 0dff3150c1
commit 56fa36934e
8 changed files with 117 additions and 25 deletions

View File

@ -25,6 +25,7 @@
#include "mpegfile.h"
#include "id3v2framefactory.h"
#include "tdebug.h"
#include "tpropertymap.h"
#include "apefooter.h"
@ -122,9 +123,12 @@ bool MPEG::File::isSupported(IOStream *stream)
// public members
////////////////////////////////////////////////////////////////////////////////
MPEG::File::File(FileName file, bool readProperties, Properties::ReadStyle readStyle) :
MPEG::File::File(FileName file, bool readProperties,
Properties::ReadStyle readStyle,
ID3v2::FrameFactory *frameFactory) :
TagLib::File(file),
d(std::make_unique<FilePrivate>())
d(std::make_unique<FilePrivate>(
frameFactory ? frameFactory : ID3v2::FrameFactory::instance()))
{
if(isOpen())
read(readProperties, readStyle);
@ -139,6 +143,17 @@ MPEG::File::File(FileName file, ID3v2::FrameFactory *frameFactory,
read(readProperties, readStyle);
}
MPEG::File::File(IOStream *stream, bool readProperties,
Properties::ReadStyle readStyle,
ID3v2::FrameFactory *frameFactory) :
TagLib::File(stream),
d(std::make_unique<FilePrivate>(
frameFactory ? frameFactory : ID3v2::FrameFactory::instance()))
{
if(isOpen())
read(readProperties, readStyle);
}
MPEG::File::File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
bool readProperties, Properties::ReadStyle readStyle) :
TagLib::File(stream),

View File

@ -77,11 +77,12 @@ namespace TagLib {
* If \a propertiesStyle is not Fast, the file will be scanned
* completely if no ID3v2 tag or MPEG sync code is found at the start.
*
* \deprecated This constructor will be dropped in favor of the one below
* in a future version.
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(FileName file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average,
ID3v2::FrameFactory *frameFactory = nullptr);
/*!
* Constructs an MPEG file from \a file. If \a readProperties is true the
@ -93,7 +94,7 @@ namespace TagLib {
* If \a propertiesStyle is not Fast, the file will be scanned
* completely if no ID3v2 tag or MPEG sync code is found at the start.
*/
// BIC: merge with the above constructor, kept for source compatibility
TAGLIB_DEPRECATED
File(FileName file, ID3v2::FrameFactory *frameFactory,
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
@ -110,7 +111,28 @@ namespace TagLib {
*
* If \a propertiesStyle is not Fast, the file will be scanned
* completely if no ID3v2 tag or MPEG sync code is found at the start.
*
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(IOStream *stream, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average,
ID3v2::FrameFactory *frameFactory = nullptr);
/*!
* Constructs an MPEG file from \a stream. If \a readProperties is true the
* file's audio properties will also be read.
*
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* If \a propertiesStyle is not Fast, the file will be scanned
* completely if no ID3v2 tag or MPEG sync code is found at the start.
*/
TAGLIB_DEPRECATED
File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);