libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
FileFormatFactory< Product > Class Template Reference

Generic factory template for file-format-specific product creation. More...

#include <fileformatfactory.h>

Collaboration diagram for FileFormatFactory< Product >:

Classes

struct  Context
 Context passed to factory methods for lookup and creation. More...
 

Public Member Functions

 FileFormatFactory ()=default
 Default constructor.
 
virtual ~FileFormatFactory ()
 Virtual destructor.
 
String name () const
 Returns the human-readable name of this factory.
 
const StringListextensions () const
 Returns the list of supported file extensions.
 
bool isExtensionSupported (const String &filename) const
 Returns true if the filename has a supported extension.
 
bool isHintSupported (const String &hint) const
 Returns true if the hint matches a supported extension.
 
virtual bool canDoOperation (const Context &ctx) const
 Returns true if this factory can handle the given context.
 
virtual Result< ProductcreateForOperation (const Context &ctx) const
 Creates a Product configured for the given context.
 

Static Public Member Functions

static int registerFactory (FileFormatFactory *factory)
 Registers a factory instance in the global registry.
 
static const FileFormatFactorylookup (const Context &ctx)
 Looks up a factory that can handle the given context.
 

Protected Attributes

String _name
 Human-readable factory name.
 
StringList _exts
 List of supported file extensions (no dots).
 

Detailed Description

template<typename Product>
class FileFormatFactory< Product >

Generic factory template for file-format-specific product creation.

FileFormatFactory captures the registry/lookup pattern used by audio and image file backends. Subclasses register themselves at static init time via PROMEKI_REGISTER_FILE_FORMAT_FACTORY and override canDoOperation() and createForOperation() to handle specific file formats.

Template Parameters
ProductThe type that factories create (e.g. AudioFile).
// Define a factory registration macro for your product type:
#define PROMEKI_REGISTER_MYFILE_FACTORY(name) \
PROMEKI_REGISTER_FILE_FORMAT_FACTORY(MyFile, name)
// Subclass and register:
class MyFileFactory_Foo : public FileFormatFactory<MyFile> {
MyFileFactory_Foo() { _name = "foo"; _exts = {"foo", "bar"}; }
bool canDoOperation(const Context &ctx) const override { ... }
Result<MyFile> createForOperation(const Context &ctx) const override { ... }
};
Generic factory template for file-format-specific product creation.
Definition fileformatfactory.h:48
Dynamic array container wrapping std::vector.
Definition list.h:40

Member Function Documentation

◆ canDoOperation()

template<typename Product >
virtual bool FileFormatFactory< Product >::canDoOperation ( const Context ctx) const
inlinevirtual

Returns true if this factory can handle the given context.

Subclasses override this to inspect the context and decide whether they can perform the requested operation.

Parameters
ctxThe context describing the requested operation.
Returns
true if the operation is supported.

◆ createForOperation()

template<typename Product >
virtual Result< Product > FileFormatFactory< Product >::createForOperation ( const Context ctx) const
inlinevirtual

Creates a Product configured for the given context.

Subclasses override this to instantiate their backend.

Parameters
ctxThe context describing the requested operation.
Returns
A Result containing the product on success, or an error.

◆ extensions()

template<typename Product >
const StringList & FileFormatFactory< Product >::extensions ( ) const
inline

Returns the list of supported file extensions.

Returns
A const reference to the extension list.

◆ isExtensionSupported()

template<typename Product >
bool FileFormatFactory< Product >::isExtensionSupported ( const String filename) const
inline

Returns true if the filename has a supported extension.

Parameters
filenameThe path to check.
Returns
true if the file extension matches one of this factory's extensions.

◆ isHintSupported()

template<typename Product >
bool FileFormatFactory< Product >::isHintSupported ( const String hint) const
inline

Returns true if the hint matches a supported extension.

Parameters
hintThe format hint string (e.g. "wav"), no dot.
Returns
true if the hint matches one of this factory's extensions.

◆ lookup()

template<typename Product >
static const FileFormatFactory * FileFormatFactory< Product >::lookup ( const Context ctx)
inlinestatic

Looks up a factory that can handle the given context.

Iterates registered factories, calling canDoOperation() on each. Returns the first match or nullptr if none found.

Parameters
ctxThe context describing the requested operation.
Returns
A pointer to a matching factory, or nullptr.

◆ name()

template<typename Product >
String FileFormatFactory< Product >::name ( ) const
inline

Returns the human-readable name of this factory.

Returns
The factory name as a String.

◆ registerFactory()

template<typename Product >
static int FileFormatFactory< Product >::registerFactory ( FileFormatFactory< Product > *  factory)
inlinestatic

Registers a factory instance in the global registry.

Parameters
factoryPointer to the factory to register. Ownership is taken.
Returns
A non-zero value (used for static initialization).

The documentation for this class was generated from the following file: