cpp-mate  0.7
Helpful library for C++.
CppMate::Forge::Factory< T, I, P > Class Template Reference

Represents abstract factory. More...

#include <Forge.hpp>

Public Member Functions

 Factory (const Factory &other)=delete
 Disabled copy constructor. More...
 
 Factory (Factory &&other)=default
 Default move constructor. More...
 
Factoryoperator= (const Factory &other)=delete
 Disabled assign operator. More...
 
Factoryoperator= (Factory &&other)=default
 Default move operator. More...
 
template<typename... A>
std::unique_ptr< T > createInstance (const std::string &name, A &&... args) const
 Creates a new instance by name. More...
 
template<typename... A>
std::unique_ptr< T > requestInstance (A &&... args) const
 Tries to create a new instance by provided arguments. More...
 
std::vector< std::string > getProviders () const
 Returns list of provider names. More...
 
getInfo (const std::string &name) const
 Returns information about provider by name. More...
 
void registerProvider (std::unique_ptr< P > provider, bool override=false)
 Registers new provider. More...
 
bool deregisterProvider (const std::string &name)
 Deregisters provider by name. More...
 

Protected Member Functions

 Factory ()=default
 
virtual ~Factory ()=default
 
P & getProvider (const std::string &name) const
 Returns provider by name. More...
 

Protected Attributes

std::map< std::string, std::unique_ptr< P > > _providers
 Map of providers. More...
 

Detailed Description

template<typename T, typename I, typename P>
class CppMate::Forge::Factory< T, I, P >

Represents abstract factory.

Constructor & Destructor Documentation

◆ Factory() [1/3]

template<typename T , typename I , typename P >
CppMate::Forge::Factory< T, I, P >::Factory ( const Factory< T, I, P > &  other)
delete

Disabled copy constructor.

Parameters
otheranother instance to copy.

◆ Factory() [2/3]

template<typename T , typename I , typename P >
CppMate::Forge::Factory< T, I, P >::Factory ( Factory< T, I, P > &&  other)
default

Default move constructor.

Parameters
otheranother instance to move.

◆ Factory() [3/3]

template<typename T , typename I , typename P >
CppMate::Forge::Factory< T, I, P >::Factory ( )
protecteddefault

Constructor.

◆ ~Factory()

template<typename T , typename I , typename P >
virtual CppMate::Forge::Factory< T, I, P >::~Factory ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ createInstance()

template<typename T , typename I , typename P >
template<typename... A>
std::unique_ptr<T> CppMate::Forge::Factory< T, I, P >::createInstance ( const std::string &  name,
A &&...  args 
) const
inline

Creates a new instance by name.

Parameters
namethe name of the provider.
argsarguments for instance initialization.
Returns
new instance.
Exceptions
std::invalid_argument

◆ deregisterProvider()

template<typename T , typename I , typename P >
bool CppMate::Forge::Factory< T, I, P >::deregisterProvider ( const std::string &  name)
inline

Deregisters provider by name.

Parameters
namethe name of provider to unregister.
Returns
true if the provider has been successfully deregistered; false otherwise.

◆ getInfo()

template<typename T , typename I , typename P >
I CppMate::Forge::Factory< T, I, P >::getInfo ( const std::string &  name) const
inline

Returns information about provider by name.

Parameters
namethe name of provider.
Returns
information about provider.
Exceptions
std::invalid_argument

◆ getProvider()

template<typename T , typename I , typename P >
P& CppMate::Forge::Factory< T, I, P >::getProvider ( const std::string &  name) const
inlineprotected

Returns provider by name.

Parameters
namethe name of provider.
Returns
reference to provider.

◆ getProviders()

template<typename T , typename I , typename P >
std::vector<std::string> CppMate::Forge::Factory< T, I, P >::getProviders ( ) const
inline

Returns list of provider names.

Returns
list of provider names.

◆ operator=() [1/2]

template<typename T , typename I , typename P >
Factory& CppMate::Forge::Factory< T, I, P >::operator= ( const Factory< T, I, P > &  other)
delete

Disabled assign operator.

Parameters
otherother instance to assign.
Returns
itself.

◆ operator=() [2/2]

template<typename T , typename I , typename P >
Factory& CppMate::Forge::Factory< T, I, P >::operator= ( Factory< T, I, P > &&  other)
default

Default move operator.

Parameters
otheranother instance to move.
Returns
itself.

◆ registerProvider()

template<typename T , typename I , typename P >
void CppMate::Forge::Factory< T, I, P >::registerProvider ( std::unique_ptr< P >  provider,
bool  override = false 
)
inline

Registers new provider.

Parameters
providerthe provider to register.
overrideif this flag is true existing provider (with same name) will be overridden; otherwise std::invalid_argument will be thrown.
Exceptions
std::invalid_argument

◆ requestInstance()

template<typename T , typename I , typename P >
template<typename... A>
std::unique_ptr<T> CppMate::Forge::Factory< T, I, P >::requestInstance ( A &&...  args) const
inline

Tries to create a new instance by provided arguments.

Parameters
argsarguments for instance initialization.
Returns
new instance.
Exceptions
std::invalid_argument

Member Data Documentation

◆ _providers

template<typename T , typename I , typename P >
std::map<std::string, std::unique_ptr<P> > CppMate::Forge::Factory< T, I, P >::_providers
protected

Map of providers.


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