Nektar++
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator > Class Template Reference

#include <NekManager.hpp>

Public Types

typedef std::shared_ptr< ValueT > ValueType
 
typedef std::function< ValueType(const KeyType &key)> CreateFuncType
 
typedef std::map< KeyType, ValueTypeValueContainer
 
typedef std::shared_ptr< ValueContainerValueContainerShPtr
 
typedef std::map< KeyType, CreateFuncType, opLessCreator > CreateFuncContainer
 
typedef std::map< std::string, std::shared_ptr< ValueContainer > > ValueContainerPool
 
typedef std::shared_ptr< bool > BoolSharedPtr
 
typedef std::map< std::string, BoolSharedPtrFlagContainerPool
 

Public Member Functions

 NekManager (std::string whichPool="")
 
 NekManager (CreateFuncType f, std::string whichPool="")
 
 ~NekManager ()
 
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 calling statically. More...
 
bool RegisterGlobalCreator (const CreateFuncType &createFunc)
 Register the Global Create Function. The return value is just to facilitate calling statically. More...
 
ValueType operator[] (const KeyType &key)
 
void DeleteObject (const KeyType &key)
 
size_t PoolCount (std::string whichPool)
 

Static Public Member Functions

static void ClearManager (std::string whichPool="")
 
static bool PoolCreated (std::string whichPool)
 
static void EnableManagement (std::string whichPool="")
 
static void DisableManagement (std::string whichPool="")
 

Private Member Functions

NekManager< KeyType, ValueType, opLessCreator > & operator= (const NekManager< KeyType, ValueType, opLessCreator > &rhs)
 
 NekManager (const NekManager< KeyType, ValueType, opLessCreator > &rhs)
 

Private Attributes

ValueContainerShPtr m_values
 
BoolSharedPtr m_managementEnabled
 
CreateFuncType m_globalCreateFunc
 
CreateFuncContainer m_keySpecificCreateFuncs
 

Static Private Attributes

static ValueContainerPool m_ValueContainerPool
 
static FlagContainerPool m_managementEnabledContainerPool
 

Detailed Description

template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
class Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >

Definition at line 68 of file NekManager.hpp.

Member Typedef Documentation

◆ BoolSharedPtr

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::shared_ptr<bool> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::BoolSharedPtr

Definition at line 79 of file NekManager.hpp.

◆ CreateFuncContainer

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::map<KeyType, CreateFuncType, opLessCreator> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::CreateFuncContainer

Definition at line 76 of file NekManager.hpp.

◆ CreateFuncType

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::function<ValueType(const KeyType &key)> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::CreateFuncType

Definition at line 72 of file NekManager.hpp.

◆ FlagContainerPool

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::map<std::string, BoolSharedPtr> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::FlagContainerPool

Definition at line 80 of file NekManager.hpp.

◆ ValueContainer

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::map<KeyType, ValueType> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::ValueContainer

Definition at line 73 of file NekManager.hpp.

◆ ValueContainerPool

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::map<std::string, std::shared_ptr<ValueContainer> > Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::ValueContainerPool

Definition at line 78 of file NekManager.hpp.

◆ ValueContainerShPtr

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::shared_ptr<ValueContainer> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::ValueContainerShPtr

Definition at line 74 of file NekManager.hpp.

◆ ValueType

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
typedef std::shared_ptr<ValueT> Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::ValueType

Definition at line 71 of file NekManager.hpp.

Constructor & Destructor Documentation

◆ NekManager() [1/3]

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::NekManager ( std::string  whichPool = "")
inline

Definition at line 82 of file NekManager.hpp.

84 {
85 if (!whichPool.empty())
86 {
87 auto iter = m_ValueContainerPool.find(whichPool);
88 if (iter != m_ValueContainerPool.end())
89 {
90 m_values = iter->second;
93 }
94 else
95 {
97 m_ValueContainerPool[whichPool] = m_values;
98 if (m_managementEnabledContainerPool.find(whichPool) ==
100 {
102 BoolSharedPtr(new bool(true));
103 }
106 }
107 }
108 else
109 {
111 m_managementEnabled = BoolSharedPtr(new bool(true));
112 }
113 };
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:79
ValueContainerShPtr m_values
Definition: NekManager.hpp:314
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:316
std::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:74
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:317
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:319
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:73

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabled, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabledContainerPool, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool, and Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_values.

◆ NekManager() [2/3]

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::NekManager ( CreateFuncType  f,
std::string  whichPool = "" 
)
inlineexplicit

Definition at line 115 of file NekManager.hpp.

117 {
118 if (!whichPool.empty())
119 {
120#ifdef NEKTAR_USE_THREAD_SAFETY
121 ReadLock v_rlock(m_mutex); // reading static members
122#endif
123 auto iter = m_ValueContainerPool.find(whichPool);
124 if (iter != m_ValueContainerPool.end())
125 {
126 m_values = iter->second;
129 }
130 else
131 {
132#ifdef NEKTAR_USE_THREAD_SAFETY
133 v_rlock.unlock();
134 // Now writing static members. Apparently
135 // upgrade_lock has less desirable properties than
136 // just dropping read lock, grabbing write lock.
137 // write will block until all reads are done, but
138 // reads cannot be acquired if write lock is
139 // blocking. In this context writes are supposed to
140 // be rare.
141 WriteLock v_wlock(m_mutex);
142#endif
144 m_ValueContainerPool[whichPool] = m_values;
145 if (m_managementEnabledContainerPool.find(whichPool) ==
147 {
149 BoolSharedPtr(new bool(true));
150 }
153 }
154 }
155 else
156 {
158 m_managementEnabled = BoolSharedPtr(new bool(true));
159 }
160 }
std::shared_lock< std::shared_mutex > ReadLock
Definition: Thread.h:377
std::unique_lock< std::shared_mutex > WriteLock
Definition: Thread.h:376

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabled, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabledContainerPool, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool, and Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_values.

◆ ~NekManager()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::~NekManager ( )
inline

Definition at line 162 of file NekManager.hpp.

163 {
164 }

◆ NekManager() [3/3]

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::NekManager ( const NekManager< KeyType, ValueType, opLessCreator > &  rhs)
private

Member Function Documentation

◆ ClearManager()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
static void Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::ClearManager ( std::string  whichPool = "")
inlinestatic

Definition at line 232 of file NekManager.hpp.

233 {
234#ifdef NEKTAR_USE_THREAD_SAFETY
235 WriteLock v_wlock(m_mutex);
236#endif
237
238 if (!whichPool.empty())
239 {
240 auto x = m_ValueContainerPool.find(whichPool);
242 "Could not find pool " + whichPool);
243 x->second->clear();
244 }
245 else
246 {
247 for (auto &x : m_ValueContainerPool)
248 {
249 x.second->clear();
250 }
251 }
252 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242

References ASSERTL1, and Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool.

◆ DeleteObject()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
void Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::DeleteObject ( const KeyType &  key)
inline

Definition at line 222 of file NekManager.hpp.

223 {
224 auto found = m_values->find(key);
225
226 if (found != m_values->end())
227 {
228 m_values->erase(found);
229 }
230 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_values.

◆ DisableManagement()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
static void Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::DisableManagement ( std::string  whichPool = "")
inlinestatic

Definition at line 289 of file NekManager.hpp.

290 {
291 if (!whichPool.empty())
292 {
293#ifdef NEKTAR_USE_THREAD_SAFETY
294 WriteLock v_wlock(m_mutex);
295#endif
296 auto x = m_managementEnabledContainerPool.find(whichPool);
298 {
299 (*x->second) = false;
300 }
301 else
302 {
304 BoolSharedPtr(new bool(false));
305 }
306 }
307 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabledContainerPool.

◆ EnableManagement()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
static void Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::EnableManagement ( std::string  whichPool = "")
inlinestatic

Definition at line 268 of file NekManager.hpp.

269 {
270 if (!whichPool.empty())
271 {
272#ifdef NEKTAR_USE_THREAD_SAFETY
273 WriteLock v_wlock(m_mutex);
274#endif
275
276 auto x = m_managementEnabledContainerPool.find(whichPool);
278 {
279 (*x->second) = true;
280 }
281 else
282 {
284 BoolSharedPtr(new bool(true));
285 }
286 }
287 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabledContainerPool.

◆ operator=()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
NekManager< KeyType, ValueType, opLessCreator > & Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::operator= ( const NekManager< KeyType, ValueType, opLessCreator > &  rhs)
private

◆ operator[]()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
ValueType Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::operator[] ( const KeyType &  key)
inline

Definition at line 184 of file NekManager.hpp.

185 {
186 auto found = m_values->find(key);
187
188 if (found != m_values->end())
189 {
190 return (*found).second;
191 }
192 else
193 {
194 // No object, create a new one.
195 auto keyFound = m_keySpecificCreateFuncs.find(key);
196 bool isfound = keyFound != m_keySpecificCreateFuncs.end();
198 isfound ? (*keyFound).second : m_globalCreateFunc;
199
200 if (f)
201 {
202 ValueType v = f(key);
204 {
205 (*m_values)[key] = v;
206 }
207 return v;
208 }
209 else
210 {
211 std::stringstream ss;
212 ss << key;
213 std::string message =
214 "No create func found for key " + ss.str();
215 NEKERROR(ErrorUtil::efatal, message.c_str());
216 static ValueType result;
217 return result;
218 }
219 }
220 }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
std::function< ValueType(const KeyType &key)> CreateFuncType
Definition: NekManager.hpp:72
std::shared_ptr< ValueT > ValueType
Definition: NekManager.hpp:71

References Nektar::ErrorUtil::efatal, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_globalCreateFunc, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_keySpecificCreateFuncs, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabled, Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_values, and NEKERROR.

◆ PoolCount()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
size_t Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::PoolCount ( std::string  whichPool)
inline

Definition at line 260 of file NekManager.hpp.

261 {
262 auto x = m_ValueContainerPool.find(whichPool);
264 "Could not find pool " + whichPool);
265 return x->second->size();
266 }

References ASSERTL1, and Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool.

◆ PoolCreated()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
static bool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::PoolCreated ( std::string  whichPool)
inlinestatic

Definition at line 254 of file NekManager.hpp.

255 {
256 return m_ValueContainerPool.find(whichPool) !=
258 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool.

◆ RegisterCreator()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
bool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::RegisterCreator ( const KeyType &  key,
const CreateFuncType createFunc 
)
inline

Register the given function and associate it with the key. The return value is just to facilitate calling statically.

Definition at line 168 of file NekManager.hpp.

169 {
170 m_keySpecificCreateFuncs[key] = createFunc;
171
172 return true;
173 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_keySpecificCreateFuncs.

◆ RegisterGlobalCreator()

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
bool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::RegisterGlobalCreator ( const CreateFuncType createFunc)
inline

Register the Global Create Function. The return value is just to facilitate calling statically.

Definition at line 177 of file NekManager.hpp.

178 {
179 m_globalCreateFunc = createFunc;
180
181 return true;
182 }

References Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_globalCreateFunc.

Member Data Documentation

◆ m_globalCreateFunc

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
CreateFuncType Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_globalCreateFunc
private

◆ m_keySpecificCreateFuncs

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
CreateFuncContainer Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_keySpecificCreateFuncs
private

◆ m_managementEnabled

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
BoolSharedPtr Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabled
private

◆ m_managementEnabledContainerPool

template<typename KeyType , typename ValueT , typename opLessCreator >
NekManager< KeyType, ValueT, opLessCreator >::FlagContainerPool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_managementEnabledContainerPool
staticprivate

◆ m_ValueContainerPool

template<typename KeyType , typename ValueT , typename opLessCreator >
NekManager< KeyType, ValueT, opLessCreator >::ValueContainerPool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_ValueContainerPool
staticprivate

◆ m_values

template<typename KeyType , typename ValueT , typename opLessCreator = defOpLessCreator<KeyType>>
ValueContainerShPtr Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_values
private