xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::core::Factory< SmartPointer, ConstructorArguments > Class Template Referencefinal

A factory for creating objects derived from of a certain base class. More...

#include <core/Factory.hpp>

Public Types

using BaseClass = typename std::pointer_traits< SmartPointer >::element_type
 

Public Member Functions

template<typename ConcreteClass >
 Factory (FactoryTag< ConcreteClass > tag)
 Constructs a factory for a certain concrete class.
 
auto operator() (ConstructorArguments... constructorArguments) const -> SmartPointer
 Creates an object.
 

Related Symbols

(Note that these are not member symbols.)

template<typename ConcreteClass >
constexpr FactoryTag< ConcreteClass > kFactory
 A marker used to create factories for a specific concrete type.
 

Detailed Description

template<typename SmartPointer, typename... ConstructorArguments>
class xentara::utils::core::Factory< SmartPointer, ConstructorArguments >

A factory for creating objects derived from of a certain base class.

Template Parameters
SmartPointerThe base class pointer used to manage the created object. Must be a unique_ptr or a shared_ptr to the base class object type.
ConstructorArgumentsArguments that will be passed to the objects' constructor when creating them. If SmartPointer is a unique_ptr, and the first argument is the corresponding deleter, or a reference to it, then that deleter will be passed to the constructor of unique_ptr instead of the object.

Member Typedef Documentation

◆ BaseClass

template<typename SmartPointer , typename... ConstructorArguments>
using xentara::utils::core::Factory< SmartPointer, ConstructorArguments >::BaseClass = typename std::pointer_traits<SmartPointer>::element_type

Constructor & Destructor Documentation

◆ Factory()

template<typename SmartPointer , typename... ConstructorArguments>
template<typename ConcreteClass >
xentara::utils::core::Factory< SmartPointer, ConstructorArguments >::Factory ( FactoryTag< ConcreteClass >  tag)

Constructs a factory for a certain concrete class.

Parameters
tagThe tag used to specify the conrete class of the objects to create. Pass kFactory<ConcreteClass> for the concrete class of object you want to create

Member Function Documentation

◆ operator()()

template<typename SmartPointer , typename... ConstructorArguments>
auto xentara::utils::core::Factory< SmartPointer, ConstructorArguments >::operator() ( ConstructorArguments...  constructorArguments) const -> SmartPointer

Creates an object.

Parameters
constructorArgumentsArguments that should be passed to the object's constructor when creating it
Returns

Friends And Related Symbol Documentation

◆ kFactory

template<typename SmartPointer , typename... ConstructorArguments>
template<typename ConcreteClass >
constexpr FactoryTag<ConcreteClass> kFactory
related

A marker used to create factories for a specific concrete type.

Template Parameters
ConcreteClassThe class of object to create