ModErn Text Analysis
META Enumerates Textual Applications
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
meta::util::factory< DerivedFactory, Type, Arguments > Class Template Reference

Generic factory that can be subclassed to create factories for specific types. More...

#include <factory.h>

Classes

class  exception
 Simple exception for factories. More...
 

Public Types

using base_factory = factory
 Convenience typedef for the derived classes.
 
using pointer = std::unique_ptr< Type >
 The return type for the create method.
 
using factory_method = std::function< pointer(Arguments...)>
 Convenience typedef for the factory methods used to create objects.
 

Public Member Functions

template<class Function >
void add (const std::string &identifier, Function &&fn)
 Associates the given identifier with the given factory method. More...
 
template<class... Args>
pointer create (const std::string &identifier, Args &&...args)
 Creates a new object based on the factory method parameters. More...
 

Static Public Member Functions

static DerivedFactory & get ()
 Obtains the singleton. More...
 

Private Attributes

std::unordered_map< std::string, factory_methodmethods_
 The internal map of identifiers to factory_methods.
 

Detailed Description

template<class DerivedFactory, class Type, class... Arguments>
class meta::util::factory< DerivedFactory, Type, Arguments >

Generic factory that can be subclassed to create factories for specific types.

Member Function Documentation

template<class DerivedFactory, class Type, class... Arguments>
static DerivedFactory& meta::util::factory< DerivedFactory, Type, Arguments >::get ( )
inlinestatic

Obtains the singleton.

Returns
a singleton of type DerivedFactory
template<class DerivedFactory, class Type, class... Arguments>
template<class Function >
void meta::util::factory< DerivedFactory, Type, Arguments >::add ( const std::string &  identifier,
Function &&  fn 
)
inline

Associates the given identifier with the given factory method.

Parameters
identifierThe identifier to associate the factory method with
fnThe factory method
template<class DerivedFactory, class Type, class... Arguments>
template<class... Args>
pointer meta::util::factory< DerivedFactory, Type, Arguments >::create ( const std::string &  identifier,
Args &&...  args 
)
inline

Creates a new object based on the factory method parameters.

Parameters
identifierThe identifier to use to select a factory method
argsThe arguments to forward to that factory method
Returns
a unique_ptr to the new object created

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