![]() |
Dakota
Version 7.0
Explore and Predict with Confidence
|
Public Types | |
| using | return_type = typename FunctionInfo< CreateFun >::return_type |
Public Types inherited from DefaultGenericFactoryErrorPolicy< Key, CreateFun > | |
| using | return_type = typename FunctionInfo< CreateFun >::return_type |
Public Member Functions | |
| template<typename Fun > | |
| bool | register_key (const Key &key, Fun &&fun) |
| bool | key_is_registered (const Key &key) const noexcept |
| template<typename... Args> | |
| auto | create (const Key &key, Args &&... args) |
Public Member Functions inherited from DefaultGenericFactoryErrorPolicy< Key, CreateFun > | |
| template<typename... CreateArgs> | |
| return_type | on_unknown_key (const Key &, CreateArgs &&...) const |
Private Attributes | |
| std::unordered_map< Key, std::function< CreateFun > > | m_registrar |
A class for registering factory functions and calling them by providing a key. Factory functions are added to the registry via register_key. Providing a registered key to create will return the result of invoking the factory function registered with the key.
| Key | the lookup key; any hashable type is allowed |
| CreateFun | the type of function for creating factory items |
| ErrorPolicy | a policy type that implements on_unknown_key |
|
inline |
Register a factory function with the given key. Future calls to create will invoke Fun when provided the same value for key. If the key is already registered, Fun will not be inserted and this method will return false.
| key | the key to associate the given function with |
| fun | the function, functor, or function pointer associated with the key |
|
inlinenoexcept |
Returns whether a given key is registered.
| key | the key to query |
|
inline |
Invoke the factory function registered to the given key, returning its result if the key exists; otherwise returns ErrorPolicy::on_unknown_key(std::forward<Args>(args)...).
| key | the key for looking up the factory function |
| args | the arguments to forward to the factory function for the key if it exists; ErrorPolicy::on_unknown_key otherwise |