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
45#include <shared_mutex>
53#ifdef NEKTAR_USE_THREAD_SAFETY
54typedef std::unique_lock<std::shared_mutex>
WriteLock;
55typedef std::shared_lock<std::shared_mutex>
ReadLock;
60 bool operator()(
const KeyType &lhs,
const KeyType &rhs)
const
66template <
typename KeyType,
typename ValueT,
75 typedef std::map<KeyType, CreateFuncType, opLessCreator>
77 typedef std::map<std::string, std::shared_ptr<ValueContainer>>
85 if (!whichPool.empty())
118 if (!whichPool.empty())
120#ifdef NEKTAR_USE_THREAD_SAFETY
132#ifdef NEKTAR_USE_THREAD_SAFETY
190 return (*found).second;
205 (*m_values)[key] = v;
211 std::stringstream ss;
213 std::string message =
214 "No create func found for key " + ss.str();
234#ifdef NEKTAR_USE_THREAD_SAFETY
238 if (!whichPool.empty())
242 "Could not find pool " + whichPool);
264 "Could not find pool " + whichPool);
265 return x->second->size();
270 if (!whichPool.empty())
272#ifdef NEKTAR_USE_THREAD_SAFETY
291 if (!whichPool.empty())
293#ifdef NEKTAR_USE_THREAD_SAFETY
299 (*x->second) =
false;
320#ifdef NEKTAR_USE_THREAD_SAFETY
321 static std::shared_mutex m_mutex;
325template <
typename KeyType,
typename ValueT,
typename opLessCreator>
328template <
typename KeyType,
typename ValueT,
typename opLessCreator>
331 opLessCreator>::m_managementEnabledContainerPool;
332#ifdef NEKTAR_USE_THREAD_SAFETY
333template <
typename KeyType,
typename ValueT,
typename opLessCreator>
#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
std::shared_lock< std::shared_mutex > ReadLock
std::unique_lock< std::shared_mutex > WriteLock
bool operator()(const KeyType &lhs, const KeyType &rhs) const