35#ifndef NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
36#define NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
45#ifdef NEKTAR_USE_THREAD_SAFETY
47#include <shared_mutex>
56#ifdef NEKTAR_USE_THREAD_SAFETY
58typedef std::unique_lock<std::shared_mutex>
WriteLock;
59typedef std::shared_lock<std::shared_mutex>
ReadLock;
100template <
typename tKey,
145#ifdef NEKTAR_USE_THREAD_SAFETY
157#ifdef NEKTAR_USE_THREAD_SAFETY
165 return tmp->
m_func(args...);
167 catch (
const std::string &s)
169 std::stringstream errstr;
170 errstr <<
"Unable to create module: " << idKey <<
"\n";
178 std::stringstream errstr;
179 errstr <<
"No such module: " << idKey << std::endl;
198 std::string pDesc =
"")
200#ifdef NEKTAR_USE_THREAD_SAFETY
205 getMapFactory()->insert(std::pair<tKey, ModuleEntry>(idKey, e));
214#ifdef NEKTAR_USE_THREAD_SAFETY
233#ifdef NEKTAR_USE_THREAD_SAFETY
237 pOut << std::endl <<
"Available classes: " << std::endl;
240 pOut <<
" " << it.first;
241 if (it.second.m_desc !=
"")
243 pOut <<
":" << std::endl
244 <<
" " << it.second.m_desc << std::endl;
258#ifdef NEKTAR_USE_THREAD_SAFETY
265 std::stringstream errstr;
266 errstr <<
"No such module: " << idKey << std::endl;
268 return it->second.m_desc;
287#ifdef NEKTAR_USE_THREAD_SAFETY
288 std::shared_mutex m_mutex;
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Provides a generic Factory class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
TMapFactory * getMapFactory()
Ensure the factory's map is created.
NekFactory(const NekFactory &rhs)=delete
std::shared_ptr< tBase > tBaseSharedPtr
Shared pointer to an object of baseclass type.
std::map< tKey, ModuleEntry, tPredicator > TMapFactory
Factory map between key and module data.
NekFactory & operator=(const NekFactory &rhs)=delete
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::less< tKey > tPredicator
Comparison predicator of key.
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
std::function< tBaseSharedPtr(tParam...)> CreatorFunction
CreatorFunction type which takes parameter and returns base class shared pointer.
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
std::string GetClassDescription(tKey idKey)
Returns the description of a class.
std::shared_lock< std::shared_mutex > ReadLock
std::unique_lock< std::shared_mutex > WriteLock
Define a struct to hold the information about a module.
ModuleEntry(CreatorFunction pFunc, const std::string pDesc)
std::string m_desc
Description of class for use in listing available classes.
CreatorFunction m_func
Function used to create instance of class.