35 #ifndef NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY 36 #define NEKTAR_LIBUTILITIES_BASICUTILS_NEKFACTORY 44 #ifdef NEKTAR_USE_THREAD_SAFETY 45 #include <boost/thread/shared_mutex.hpp> 46 #include <boost/thread/locks.hpp> 53 namespace LibUtilities
56 #ifdef NEKTAR_USE_THREAD_SAFETY 58 typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
59 typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
100 template <
typename tKey,
146 #ifdef NEKTAR_USE_THREAD_SAFETY 147 ReadLock vReadLock(m_mutex);
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;
200 std::string pDesc =
"")
202 #ifdef NEKTAR_USE_THREAD_SAFETY 203 WriteLock vWriteLock(m_mutex);
207 getMapFactory()->insert(std::pair<tKey,ModuleEntry>(idKey, e));
217 #ifdef NEKTAR_USE_THREAD_SAFETY 218 ReadLock vReadLock(m_mutex);
237 #ifdef NEKTAR_USE_THREAD_SAFETY 238 ReadLock vReadLock(m_mutex);
241 pOut << std::endl <<
"Available classes: " << std::endl;
244 pOut <<
" " << it.first;
245 if (it.second.m_desc !=
"")
247 pOut <<
":" << std::endl <<
" " 248 << it.second.m_desc << std::endl;
263 #ifdef NEKTAR_USE_THREAD_SAFETY 264 ReadLock vReadLock(m_mutex);
269 if (it.second.m_desc == pDesc)
274 std::string errstr =
"Module '" + pDesc +
"' is not known.";
284 #ifdef NEKTAR_USE_THREAD_SAFETY 285 ReadLock vReadLock(m_mutex);
291 std::stringstream errstr;
292 errstr <<
"No such module: " << idKey << std::endl;
294 return it->second.m_desc;
313 #ifdef NEKTAR_USE_THREAD_SAFETY 314 boost::shared_mutex m_mutex;
std::shared_ptr< tBase > tBaseSharedPtr
Shared pointer to an object of baseclass type.
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
ModuleEntry(CreatorFunction pFunc, const std::string pDesc)
std::map< tKey, ModuleEntry, tPredicator > TMapFactory
Factory map between key and module data.
tBaseSharedPtr(* CreatorFunction)(tParam...)
CreatorFunction type which takes parameter and returns base class shared pointer. ...
std::string m_desc
Description of class for use in listing available classes.
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
Define a struct to hold the information about a module.
boost::shared_lock< boost::shared_mutex > ReadLock
tKey GetKey(std::string pDesc)
Retrieves a key, given a description.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
NekFactory & operator=(const NekFactory &rhs)
std::less< tKey > tPredicator
Comparison predicator of key.
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
boost::unique_lock< boost::shared_mutex > WriteLock
TMapFactory * getMapFactory()
Ensure the factory's map is created.
std::string GetClassDescription(tKey idKey)
Returns the description of a class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
CreatorFunction m_func
Function used to create instance of class.
Provides a generic Factory class.