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>
54#ifdef NEKTAR_USE_THREAD_SAFETY
55typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
56typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
61 bool operator()(
const KeyType &lhs,
const KeyType &rhs)
const
67template <
typename KeyType,
typename ValueT,
76 typedef std::map<KeyType, CreateFuncType, opLessCreator>
78 typedef std::map<std::string, std::shared_ptr<ValueContainer>>
86 if (!whichPool.empty())
119 if (!whichPool.empty())
121#ifdef NEKTAR_USE_THREAD_SAFETY
133#ifdef NEKTAR_USE_THREAD_SAFETY
191 return (*found).second;
206 (*m_values)[key] = v;
212 std::stringstream ss;
214 std::string message =
215 "No create func found for key " + ss.str();
235#ifdef NEKTAR_USE_THREAD_SAFETY
239 if (!whichPool.empty())
243 "Could not find pool " + whichPool);
265 "Could not find pool " + whichPool);
266 return x->second->size();
271 if (!whichPool.empty())
273#ifdef NEKTAR_USE_THREAD_SAFETY
292 if (!whichPool.empty())
294#ifdef NEKTAR_USE_THREAD_SAFETY
300 (*x->second) =
false;
321#ifdef NEKTAR_USE_THREAD_SAFETY
322 static boost::shared_mutex m_mutex;
326template <
typename KeyType,
typename ValueT,
typename opLessCreator>
329template <
typename KeyType,
typename ValueT,
typename opLessCreator>
332 opLessCreator>::m_managementEnabledContainerPool;
333#ifdef NEKTAR_USE_THREAD_SAFETY
334template <
typename KeyType,
typename ValueT,
typename opLessCreator>
335typename 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="")
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