35 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP
36 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP
43 #ifdef NEKTAR_USE_THREAD_SAFETY
44 #include <boost/thread/locks.hpp>
45 #include <boost/thread/shared_mutex.hpp>
52 namespace LibUtilities
54 #ifdef NEKTAR_USE_THREAD_SAFETY
55 typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
56 typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
61 bool operator()(
const KeyType &lhs,
const KeyType &rhs)
const
67 template <
typename KeyType,
typename ValueT,
76 typedef std::map<KeyType, CreateFuncType, opLessCreator>
78 typedef std::map<std::string, std::shared_ptr<ValueContainer>>
87 if (!whichPool.empty())
120 if (!whichPool.empty())
122 #ifdef NEKTAR_USE_THREAD_SAFETY
134 #ifdef NEKTAR_USE_THREAD_SAFETY
204 return (*found).second;
213 f = (*keyFound).second;
221 (*m_values)[key] = v;
227 std::stringstream ss;
229 std::string message =
230 "No create func found for key " + ss.str();
250 if (!whichPool.empty())
252 #ifdef NEKTAR_USE_THREAD_SAFETY
257 "Could not find pool " + whichPool);
262 #ifdef NEKTAR_USE_THREAD_SAFETY
288 "Could not find pool " + whichPool);
289 return x->second->size();
294 if (!whichPool.empty())
296 #ifdef NEKTAR_USE_THREAD_SAFETY
315 if (!whichPool.empty())
317 #ifdef NEKTAR_USE_THREAD_SAFETY
323 (*x->second) =
false;
344 #ifdef NEKTAR_USE_THREAD_SAFETY
345 static boost::shared_mutex m_mutex;
348 template <
typename KeyType,
typename ValueT,
typename opLessCreator>
351 template <
typename KeyType,
typename ValueT,
typename opLessCreator>
354 opLessCreator>::m_managementEnabledContainerPool;
355 #ifdef NEKTAR_USE_THREAD_SAFETY
356 template <
typename KeyType,
typename ValueT,
typename opLessCreator>
357 typename boost::shared_mutex
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
BoolSharedPtr m_managementEnabled
static void DisableManagement(std::string whichPool="")
bool AlreadyCreated(const KeyType &key)
std::shared_ptr< bool > BoolSharedPtr
ValueType operator[](const KeyType &key)
std::map< std::string, BoolSharedPtr > FlagContainerPool
size_t PoolCount(std::string whichPool)
bool RegisterCreator(const KeyType &key, const CreateFuncType &createFunc)
Register the given function and associate it with the key. The return value is just to facilitate cal...
NekManager(std::string whichPool="")
std::function< ValueType(const KeyType &key)> CreateFuncType
NekManager< KeyType, ValueType, opLessCreator > & operator=(const NekManager< KeyType, ValueType, opLessCreator > &rhs)
std::shared_ptr< ValueT > ValueType
ValueContainerShPtr m_values
std::map< std::string, std::shared_ptr< ValueContainer > > ValueContainerPool
NekManager(CreateFuncType f, std::string whichPool="")
static ValueContainerPool m_ValueContainerPool
std::shared_ptr< ValueContainer > ValueContainerShPtr
static bool PoolCreated(std::string whichPool)
CreateFuncType m_globalCreateFunc
static FlagContainerPool m_managementEnabledContainerPool
bool RegisterGlobalCreator(const CreateFuncType &createFunc)
Register the Global Create Function. The return value is just to facilitate calling statically.
CreateFuncContainer m_keySpecificCreateFuncs
static void EnableManagement(std::string whichPool="")
void DeleteObject(const KeyType &key)
std::map< KeyType, CreateFuncType, opLessCreator > CreateFuncContainer
static void ClearManager(std::string whichPool="")
NekManager(const NekManager< KeyType, ValueType, opLessCreator > &rhs)
std::map< KeyType, ValueType > ValueContainer
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.
bool operator()(const KeyType &lhs, const KeyType &rhs) const