template<typename T, typename... ARGS>
class maxon::Factory< T(ARGS...)>
Reference class for factories which return an object of type T based on the arguments ARGS. Typically you declare a factory in a header file as in
namespace DataFormatBaseReader
{
MAXON_DECLARATION(Factory<DataFormatBaseReaderRef(
const Url&)>, FromUrl,
"net.maxon.dataformatbasereader.fromurl");
}
MAXON_DECLARATION(Class< AssetType >, AssetTypeBaseComponent, "net.maxon.component.assettypebase")
This base component can be used by implementations of AssetType.
The factory can then be used to create new DataFormatBaseReaderRef objects given an Url:
DataFormatBaseReaderRef
stream = DataFormatBaseReader::FromUrl().Create(url)
iferr_return;
PyObject * stream
Definition: codecs.h:186
#define iferr_return
Definition: resultbase.h:1524
The definition of a factory can be done with the help of one of the static Create*Factory
functions of Factory.
- Template Parameters
-
T | The type of objects created by the factory. |
ARGS | The arguments which the factory expects for object creation. |
|
static Result< NonConst > | CreateFactory (DelegateType &&delegate, const DataDictionary ¶ms=maxon::DefaultValue< const DataDictionary & >()) |
|
static Result< NonConst > | CreateCachedFactory (DelegateType &&delegate, Int cacheSize, const DataDictionary ¶ms=maxon::DefaultValue< const DataDictionary & >()) |
|
template<typename COMP , typename = typename COMP::_Wrapper> |
static Result< NonConst > | CreateObjectFactory (Result< void >(COMP::*initFunc)(FactoryInterface::ConstPtr, ARGS...), const DataDictionary ¶ms=maxon::DefaultValue< const DataDictionary & >()) |
|
template<typename COMP , typename = typename COMP::_Wrapper> |
static Result< NonConst > | CreateCachedObjectFactory (Result< void >(COMP::*initFunc)(FactoryInterface::ConstPtr, ARGS...), Int cacheSize, const DataDictionary ¶ms=maxon::DefaultValue< const DataDictionary & >()) |
|
static Result<NonConst> CreateObjectFactory |
( |
Result< void >(COMP::*)(FactoryInterface::ConstPtr, ARGS...) |
initFunc, |
|
|
const DataDictionary & |
params = maxon::DefaultValue<const DataDictionary&>() |
|
) |
| |
|
static |
Creates a factory which creates virtual objects from a component implementation COMP. If the factory's return type T is an interface reference class as in
MAXON_DECLARATION(Factory<DataFormatBaseReaderRef(
const Url&)>, FromUrl,
"net.maxon.dataformatbasereader.fromurl");
you can implement such a factory by a component which implements the interface and has an additional member function #initFunc which expects the factory as first parameter and then ARGS:
class DataFormatReaderUniCharImpl :
public Component<DataFormatReaderUniCharImpl, DataFormatBaseReaderInterface>
{
public:
Result<void> InitFromUrl(FactoryInterface::ConstPtr factory, const Url& url);
...
};
ComponentWithBase< C, ComponentRoot, INTERFACES... > Component
Definition: objectbase.h:2798
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
Then CreateObjectFactory takes #initFunc and creates a corresponding factory:
{
return decltype(DataFormatBaseReader::FromUrl)::Type::
CreateObjectFactory(&DataFormatReaderUniCharImpl::InitFromUrl);
}
static Result< NonConst > CreateObjectFactory(Result< void >(COMP::*initFunc)(FactoryInterface::ConstPtr, ARGS...), const DataDictionary ¶ms=maxon::DefaultValue< const DataDictionary & >())
Definition: factory.h:231
#define MAXON_DECLARATION_REGISTER(...)
Definition: module.h:1006
The returned factory doesn't use caching, so each call will return a new object. If you want to cache created objects, use CreateCachedObjectFactory.
- Template Parameters
-
- Parameters
-
[in] | initFunc | Member function of COMP which initializes the object with the arguments given to the factory. |
[in] | params | Parameters to store at the created factory itself. They can be accessed through the base interface DataDictionaryObject of the factory. |
- Returns
- Factory which uses #initFunc when called.