votca 2024.2-dev
Loading...
Searching...
No Matches
votca::tools::ObjectFactory< key_t, T, args_t > Class Template Reference

template class for object factory More...

#include <objectfactory.h>

Collaboration diagram for votca::tools::ObjectFactory< key_t, T, args_t >:

Public Types

using creator_t = std::unique_ptr<T> (*)(args_t &&...)
 

Public Member Functions

 ObjectFactory ()=default
 
virtual ~ObjectFactory ()=default
 
void Register (const key_t &key, creator_t creator)
 register an object
 
template<typename obj_t >
void Register (const key_t &key)
 
virtual std::unique_ptr< T > Create (const key_t &key, args_t &&...arguments)
 
bool IsRegistered (const key_t &id_) const
 
std::vector< key_t > getKeys () const
 

Private Attributes

std::map< key_t, creator_tobjects_
 

Detailed Description

template<typename key_t, typename T, typename... args_t>
class votca::tools::ObjectFactory< key_t, T, args_t >

template class for object factory

This class is a template for an object factory. The factory creates an instance of an derived class, be giving a key (e.g. a string) for the object which identifies it uniquely. This allows the implementation of new features (e.g. new file formats, new mapping algorithms) without touching or recompiling existing bits of code.

Definition at line 44 of file objectfactory.h.

Member Typedef Documentation

◆ creator_t

template<typename key_t , typename T , typename... args_t>
using votca::tools::ObjectFactory< key_t, T, args_t >::creator_t = std::unique_ptr<T> (*)(args_t &&...)

Definition at line 46 of file objectfactory.h.

Constructor & Destructor Documentation

◆ ObjectFactory()

template<typename key_t , typename T , typename... args_t>
votca::tools::ObjectFactory< key_t, T, args_t >::ObjectFactory ( )
default

◆ ~ObjectFactory()

template<typename key_t , typename T , typename... args_t>
virtual votca::tools::ObjectFactory< key_t, T, args_t >::~ObjectFactory ( )
virtualdefault

Member Function Documentation

◆ Create()

template<typename key_t , typename T , typename... args_t>
std::unique_ptr< T > votca::tools::ObjectFactory< key_t, T, args_t >::Create ( const key_t & key,
args_t &&... arguments )
inlinevirtual

Create an instance of the object identified by key.

Definition at line 102 of file objectfactory.h.

◆ getKeys()

template<typename key_t , typename T , typename... args_t>
std::vector< key_t > votca::tools::ObjectFactory< key_t, T, args_t >::getKeys ( ) const
inline

Definition at line 70 of file objectfactory.h.

◆ IsRegistered()

template<typename key_t , typename T , typename... args_t>
bool votca::tools::ObjectFactory< key_t, T, args_t >::IsRegistered ( const key_t & id_) const
inline

Definition at line 114 of file objectfactory.h.

◆ Register() [1/2]

template<typename key_t , typename T , typename... args_t>
template<typename obj_t >
void votca::tools::ObjectFactory< key_t, T, args_t >::Register ( const key_t & key)
inline

Definition at line 97 of file objectfactory.h.

◆ Register() [2/2]

template<typename key_t , typename T , typename... args_t>
void votca::tools::ObjectFactory< key_t, T, args_t >::Register ( const key_t & key,
creator_t creator )
inline

register an object

Parameters
keyidentifier
creatorcreate policy

This function is called to register an object in the factory. After an object is registered, an instance of it can be created by calling Create specifying the corresponding key.

Definition at line 89 of file objectfactory.h.

Member Data Documentation

◆ objects_

template<typename key_t , typename T , typename... args_t>
std::map<key_t, creator_t> votca::tools::ObjectFactory< key_t, T, args_t >::objects_
private

Definition at line 80 of file objectfactory.h.


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