ezconfig
Create C++ Objects from Yaml and Json
Loading...
Searching...
No Matches
ezconfig::GeneralFactory< many, Base, Args > Class Template Reference

A Factory creates objects in a class hierarchy. More...

#include <factory.hpp>

Public Types

using OutputT = std::conditional_t<many, std::vector<std::unique_ptr<Base>>, std::unique_ptr<Base>>
 
using GeneratorT = std::function<OutputT(Args...)>
 

Public Member Functions

void add (const std::string &tag, GeneratorT factory)
 Add a factory method to the factory.
 
OutputT create (const std::string &tag, auto &&... args)
 Create an object.
 

Protected Attributes

std::map< std::string, GeneratorT > m_tags
 

Detailed Description

template<bool many, typename Base, typename... Args>
class ezconfig::GeneralFactory< many, Base, Args >

A Factory creates objects in a class hierarchy.

Template Parameters
manywhether to create a one-to-many factory or a one-to-one factory.
Signaturetype signature Base(Args...) where Base is the hierarchy base class, and Args... are the inputs to the factory methods.

If many = false, then the factory is (Args...) -> std::unique_ptr<Base> If many = true, then the factory is (Args...) -> std::vector<std::unique_ptr<Base>>

Definition at line 30 of file factory.hpp.

Member Typedef Documentation

◆ GeneratorT

template<bool many, typename Base , typename... Args>
using ezconfig::GeneralFactory< many, Base, Args >::GeneratorT = std::function<OutputT(Args...)>

Definition at line 34 of file factory.hpp.

◆ OutputT

template<bool many, typename Base , typename... Args>
using ezconfig::GeneralFactory< many, Base, Args >::OutputT = std::conditional_t<many, std::vector<std::unique_ptr<Base>>, std::unique_ptr<Base>>

Definition at line 33 of file factory.hpp.

Member Function Documentation

◆ add()

template<bool many, typename Base , typename... Args>
void ezconfig::GeneralFactory< many, Base, Args >::add ( const std::string & tag,
GeneratorT factory )
inline

Add a factory method to the factory.

Parameters
tag
factory

Definition at line 42 of file factory.hpp.

◆ create()

template<bool many, typename Base , typename... Args>
OutputT ezconfig::GeneralFactory< many, Base, Args >::create ( const std::string & tag,
auto &&... args )
inline

Create an object.

Definition at line 51 of file factory.hpp.

Member Data Documentation

◆ m_tags

template<bool many, typename Base , typename... Args>
std::map<std::string, GeneratorT> ezconfig::GeneralFactory< many, Base, Args >::m_tags
protected

Definition at line 69 of file factory.hpp.


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