35 #ifndef NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
36 #define NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
45 #ifdef NEKTAR_USE_THREAD_SAFETY
46 #include <boost/thread/locks.hpp>
47 #include <boost/thread/shared_mutex.hpp>
54 namespace LibUtilities
57 #ifdef NEKTAR_USE_THREAD_SAFETY
59 typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
60 typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
101 template <
typename tKey,
146 #ifdef NEKTAR_USE_THREAD_SAFETY
158 #ifdef NEKTAR_USE_THREAD_SAFETY
166 return tmp->
m_func(args...);
168 catch (
const std::string &s)
170 std::stringstream errstr;
171 errstr <<
"Unable to create module: " << idKey <<
"\n";
179 std::stringstream errstr;
180 errstr <<
"No such module: " << idKey << std::endl;
199 std::string pDesc =
"")
201 #ifdef NEKTAR_USE_THREAD_SAFETY
206 getMapFactory()->insert(std::pair<tKey, ModuleEntry>(idKey, e));
215 #ifdef NEKTAR_USE_THREAD_SAFETY
234 #ifdef NEKTAR_USE_THREAD_SAFETY
238 pOut << std::endl <<
"Available classes: " << std::endl;
241 pOut <<
" " << it.first;
242 if (it.second.m_desc !=
"")
244 pOut <<
":" << std::endl
245 <<
" " << it.second.m_desc << std::endl;
259 #ifdef NEKTAR_USE_THREAD_SAFETY
265 if (it.second.m_desc == pDesc)
270 std::string errstr =
"Module '" + pDesc +
"' is not known.";
279 #ifdef NEKTAR_USE_THREAD_SAFETY
286 std::stringstream errstr;
287 errstr <<
"No such module: " << idKey << std::endl;
289 return it->second.m_desc;
308 #ifdef NEKTAR_USE_THREAD_SAFETY
309 boost::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.
NekFactory(const NekFactory &rhs)
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.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
tKey GetKey(std::string pDesc)
Retrieves a key, given a description.
std::less< tKey > tPredicator
Comparison predicator of key.
TMapFactory * getMapFactory()
Ensure the factory's map is created.
NekFactory & operator=(const NekFactory &rhs)
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.
boost::shared_lock< boost::shared_mutex > ReadLock
boost::unique_lock< boost::shared_mutex > WriteLock
The above copyright notice and this permission notice shall be included.
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.