35 #ifndef NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
36 #define NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY
45 #ifdef NEKTAR_USE_THREAD_SAFETY
46 #include <boost/thread/shared_mutex.hpp>
47 #include <boost/thread/locks.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,
147 #ifdef NEKTAR_USE_THREAD_SAFETY
159 #ifdef NEKTAR_USE_THREAD_SAFETY
167 return tmp->
m_func(args...);
169 catch (
const std::string& s)
171 std::stringstream errstr;
172 errstr <<
"Unable to create module: " << idKey <<
"\n";
180 std::stringstream errstr;
181 errstr <<
"No such module: " << idKey << std::endl;
201 std::string pDesc =
"")
203 #ifdef NEKTAR_USE_THREAD_SAFETY
208 getMapFactory()->insert(std::pair<tKey,ModuleEntry>(idKey, e));
218 #ifdef NEKTAR_USE_THREAD_SAFETY
238 #ifdef NEKTAR_USE_THREAD_SAFETY
242 pOut << std::endl <<
"Available classes: " << std::endl;
245 pOut <<
" " << it.first;
246 if (it.second.m_desc !=
"")
248 pOut <<
":" << std::endl <<
" "
249 << it.second.m_desc << std::endl;
264 #ifdef NEKTAR_USE_THREAD_SAFETY
270 if (it.second.m_desc == pDesc)
275 std::string errstr =
"Module '" + pDesc +
"' is not known.";
285 #ifdef NEKTAR_USE_THREAD_SAFETY
292 std::stringstream errstr;
293 errstr <<
"No such module: " << idKey << std::endl;
295 return it->second.m_desc;
314 #ifdef NEKTAR_USE_THREAD_SAFETY
315 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.