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...
 
bool AlreadyCreated (const KeyType &key)
 
ValueType operator[] (const KeyType &key)
 
void DeleteObject (const KeyType &key)
 

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 78 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 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 79 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 77 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 81 of file NekManager.hpp.

81  :
82  m_values(),
85 
86  {
87  if (!whichPool.empty())
88  {
89  auto iter = m_ValueContainerPool.find(whichPool);
90  if (iter != m_ValueContainerPool.end())
91  {
92  m_values = iter->second;
94  }
95  else
96  {
98  m_ValueContainerPool[whichPool] = m_values;
100  {
101  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
102  }
104  }
105  }
106  else
107  {
109  m_managementEnabled = BoolSharedPtr(new bool(true));
110  }
111  };
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:326
std::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:75
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:325
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:78
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:74
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:328
ValueContainerShPtr m_values
Definition: NekManager.hpp:323

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

114  :
115  m_values(),
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;
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;
146  {
147  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
148  }
150  }
151 
152  }
153  else
154  {
156  m_managementEnabled = BoolSharedPtr(new bool(true));
157  }
158  }
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:326
std::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:75
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:325
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:78
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: Thread.h:323
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:74
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: Thread.h:322
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:328
ValueContainerShPtr m_values
Definition: NekManager.hpp:323

◆ ~NekManager()

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

Definition at line 160 of file NekManager.hpp.

161  {
162  }

◆ 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

◆ AlreadyCreated()

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

Definition at line 183 of file NekManager.hpp.

184  {
185  bool value = false;
186  auto found = m_values->find(key);
187  if( found != m_values->end() )
188  {
189  value = true;
190  }
191 
192  return value;
193  }
ValueContainerShPtr m_values
Definition: NekManager.hpp:323

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

245  {
246  if (!whichPool.empty())
247  {
248 #ifdef NEKTAR_USE_THREAD_SAFETY
249  WriteLock v_wlock(m_mutex);
250 #endif
251  auto x = m_ValueContainerPool.find(whichPool);
252  ASSERTL1(x != m_ValueContainerPool.end(),
253  "Could not find pool " + whichPool);
254  x->second->clear();
255  }
256  else
257  {
258 #ifdef NEKTAR_USE_THREAD_SAFETY
259  WriteLock v_wlock(m_mutex);
260 #endif
261 
262  for (auto &x : m_ValueContainerPool)
263  {
264  x.second->clear();
265  }
266  }
267  }
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:325
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: Thread.h:322
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250

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

235  {
236  auto found = m_values->find(key);
237 
238  if( found != m_values->end() )
239  {
240  m_values->erase(found);
241  }
242  }
ValueContainerShPtr m_values
Definition: NekManager.hpp:323

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

Referenced by Nektar::VortexWaveInteraction::ExecuteLoop().

301  {
302  if (!whichPool.empty())
303  {
304 #ifdef NEKTAR_USE_THREAD_SAFETY
305  WriteLock v_wlock(m_mutex);
306 #endif
307  auto x = m_managementEnabledContainerPool.find(whichPool);
308  if (x != m_managementEnabledContainerPool.end())
309  {
310  (*x->second) = false;
311  }
312  else
313  {
314  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(false));
315  }
316  }
317  }
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:326
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:78
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: Thread.h:322

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

Referenced by Nektar::VortexWaveInteraction::ExecuteLoop().

281  {
282  if (!whichPool.empty())
283  {
284 #ifdef NEKTAR_USE_THREAD_SAFETY
285  WriteLock v_wlock(m_mutex);
286 #endif
287 
288  auto x = m_managementEnabledContainerPool.find(whichPool);
289  if (x != m_managementEnabledContainerPool.end())
290  {
291  (*x->second) = true;
292  }
293  else
294  {
295  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
296  }
297  }
298  }
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:326
std::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:78
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: Thread.h:322

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

196  {
197  auto found = m_values->find(key);
198 
199  if( found != m_values->end() )
200  {
201  return (*found).second;
202  }
203  else
204  {
205  // No object, create a new one.
207  auto keyFound = m_keySpecificCreateFuncs.find(key);
208  if( keyFound != m_keySpecificCreateFuncs.end() )
209  {
210  f = (*keyFound).second;
211  }
212 
213  if( f )
214  {
215  ValueType v = f(key);
216  if (*m_managementEnabled)
217  {
218  (*m_values)[key] = v;
219  }
220  return v;
221  }
222  else
223  {
224  std::stringstream ss;
225  ss << key;
226  std::string message = "No create func found for key " + ss.str();
227  NEKERROR(ErrorUtil::efatal, message.c_str());
228  static ValueType result;
229  return result;
230  }
231  }
232  }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
std::function< ValueType(const KeyType &key)> CreateFuncType
Definition: NekManager.hpp:73
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:328
std::shared_ptr< ValueT > ValueType
Definition: NekManager.hpp:72
ValueContainerShPtr m_values
Definition: NekManager.hpp:323

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

270  {
271  bool value = false;
272  auto x = m_ValueContainerPool.find(whichPool);
273  if (x != m_ValueContainerPool.end())
274  {
275  value = true;
276  }
277  return value;
278  }
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:325

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

168  {
169  m_keySpecificCreateFuncs[key] = createFunc;
170 
171  return true;
172  }
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:328

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

Referenced by Nektar::LibUtilities::TimeIntegrationSchemeManager().

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

Member Data Documentation

◆ m_globalCreateFunc

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

Definition at line 327 of file NekManager.hpp.

◆ m_keySpecificCreateFuncs

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

Definition at line 328 of file NekManager.hpp.

◆ m_managementEnabled

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

Definition at line 324 of file NekManager.hpp.

◆ m_managementEnabledContainerPool

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

Definition at line 326 of file NekManager.hpp.

◆ m_ValueContainerPool

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

Definition at line 325 of file NekManager.hpp.

◆ m_values

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

Definition at line 323 of file NekManager.hpp.