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 69 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 80 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 77 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 73 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 81 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 74 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 79 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 75 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 72 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 83 of file NekManager.hpp.

85 {
86 if (!whichPool.empty())
87 {
88 auto iter = m_ValueContainerPool.find(whichPool);
89 if (iter != m_ValueContainerPool.end())
90 {
91 m_values = iter->second;
94 }
95 else
96 {
98 m_ValueContainerPool[whichPool] = m_values;
99 if (m_managementEnabledContainerPool.find(whichPool) ==
101 {
103 BoolSharedPtr(new bool(true));
104 }
107 }
108 }
109 else
110 {
112 m_managementEnabled = BoolSharedPtr(new bool(true));
113 }
114 };
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:80
ValueContainerShPtr m_values
Definition: NekManager.hpp:315
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:317
std::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:75
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:318
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:320
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:74

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 116 of file NekManager.hpp.

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

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 163 of file NekManager.hpp.

164 {
165 }

◆ 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 233 of file NekManager.hpp.

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

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 223 of file NekManager.hpp.

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

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 290 of file NekManager.hpp.

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

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 269 of file NekManager.hpp.

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

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 185 of file NekManager.hpp.

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

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 261 of file NekManager.hpp.

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

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 255 of file NekManager.hpp.

256 {
257 return m_ValueContainerPool.find(whichPool) !=
259 }

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 169 of file NekManager.hpp.

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

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 178 of file NekManager.hpp.

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

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