Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>

Collaboration diagram for Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 BOOST_CLASS_REQUIRE (KeyType, boost, LessThanComparableConcept)
 
 NekManager (std::string whichPool="")
 
 NekManager (CreateFuncType f, std::string whichPool="")
 
 ~NekManager ()
 
bool RegisterCreator (typename boost::call_traits< KeyType >::const_reference 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 (typename boost::call_traits< KeyType >::const_reference key)
 
ValueType operator[] (typename boost::call_traits< KeyType >::const_reference key)
 
void DeleteObject (typename boost::call_traits< KeyType >::const_reference 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
 
static boost::shared_mutex m_mutex
 

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

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

Definition at line 80 of file NekManager.hpp.

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

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

Definition at line 75 of file NekManager.hpp.

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.

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

Definition at line 76 of file NekManager.hpp.

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

Definition at line 79 of file NekManager.hpp.

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

Definition at line 77 of file NekManager.hpp.

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

Definition at line 74 of file NekManager.hpp.

Constructor & Destructor Documentation

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.

83  :
84  m_values(),
87 
88  {
89  if (!whichPool.empty())
90  {
91  typename ValueContainerPool::iterator iter = m_ValueContainerPool.find(whichPool);
92  if (iter != m_ValueContainerPool.end())
93  {
94  m_values = iter->second;
96  }
97  else
98  {
100  m_ValueContainerPool[whichPool] = m_values;
102  {
103  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
104  }
106  }
107  }
108  else
109  {
111  m_managementEnabled = BoolSharedPtr(new bool(true));
112  }
113  };
boost::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:77
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:319
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:318
boost::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:80
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:76
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:321
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
ValueContainerShPtr m_values
Definition: NekManager.hpp:316
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.

116  :
117  m_values(),
120  {
121  if (!whichPool.empty())
122  {
123  ReadLock v_rlock(m_mutex); // reading static members
124  typename ValueContainerPool::iterator iter = m_ValueContainerPool.find(whichPool);
125  if (iter != m_ValueContainerPool.end())
126  {
127  m_values = iter->second;
129  }
130  else
131  {
132  v_rlock.unlock();
133  // now writing static members. Apparently upgrade_lock has less desirable properties
134  // than just dropping read lock, grabbing write lock.
135  // write will block until all reads are done, but reads cannot be acquired if write
136  // lock is blocking. In this context writes are supposed to be rare.
137  WriteLock v_wlock(m_mutex);
139  m_ValueContainerPool[whichPool] = m_values;
141  {
142  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
143  }
145  }
146 
147  }
148  else
149  {
151  m_managementEnabled = BoolSharedPtr(new bool(true));
152  }
153  }
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: NekFactory.hpp:70
boost::shared_ptr< ValueContainer > ValueContainerShPtr
Definition: NekManager.hpp:77
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:319
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:318
boost::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:80
std::map< KeyType, ValueType > ValueContainer
Definition: NekManager.hpp:76
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: NekFactory.hpp:71
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:321
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static boost::shared_mutex m_mutex
Definition: NekManager.hpp:322
ValueContainerShPtr m_values
Definition: NekManager.hpp:316
template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::~NekManager ( )
inline

Definition at line 155 of file NekManager.hpp.

156  {
157  }
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

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

Definition at line 178 of file NekManager.hpp.

179  {
180  bool value = false;
181  typename ValueContainer::iterator found = m_values->find(key);
182  if( found != m_values->end() )
183  {
184  value = true;
185  }
186 
187  return value;
188  }
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
ValueContainerShPtr m_values
Definition: NekManager.hpp:316
template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::BOOST_CLASS_REQUIRE ( KeyType  ,
boost  ,
LessThanComparableConcept   
)
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 238 of file NekManager.hpp.

239  {
240  typename ValueContainerPool::iterator x;
241  if (!whichPool.empty())
242  {
243  WriteLock v_wlock(m_mutex);
244 
245  x = m_ValueContainerPool.find(whichPool);
246  ASSERTL1(x != m_ValueContainerPool.end(),
247  "Could not find pool " + whichPool);
248  x->second->clear();
249  }
250  else
251  {
252  WriteLock v_wlock(m_mutex);
253 
254  for (x = m_ValueContainerPool.begin(); x != m_ValueContainerPool.end(); ++x)
255  {
256  x->second->clear();
257  }
258  }
259  }
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: NekFactory.hpp:70
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:318
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static boost::shared_mutex m_mutex
Definition: NekManager.hpp:322
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
void Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::DeleteObject ( typename boost::call_traits< KeyType >::const_reference  key)
inline

Definition at line 228 of file NekManager.hpp.

229  {
230  typename ValueContainer::iterator found = m_values->find(key);
231 
232  if( found != m_values->end() )
233  {
234  m_values->erase(found);
235  }
236  }
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
ValueContainerShPtr m_values
Definition: NekManager.hpp:316
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 293 of file NekManager.hpp.

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

294  {
295  typename FlagContainerPool::iterator x;
296  if (!whichPool.empty())
297  {
298  WriteLock v_wlock(m_mutex);
299 
300  x = m_managementEnabledContainerPool.find(whichPool);
301  if (x != m_managementEnabledContainerPool.end())
302  {
303  (*x->second) = false;
304  }
305  else
306  {
307  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(false));
308  }
309  }
310  }
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: NekFactory.hpp:70
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:319
boost::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:80
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static boost::shared_mutex m_mutex
Definition: NekManager.hpp:322
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 274 of file NekManager.hpp.

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

275  {
276  typename FlagContainerPool::iterator x;
277  if (!whichPool.empty())
278  {
279  WriteLock v_wlock(m_mutex);
280 
281  x = m_managementEnabledContainerPool.find(whichPool);
282  if (x != m_managementEnabledContainerPool.end())
283  {
284  (*x->second) = true;
285  }
286  else
287  {
288  m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(new bool(true));
289  }
290  }
291  }
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: NekFactory.hpp:70
static FlagContainerPool m_managementEnabledContainerPool
Definition: NekManager.hpp:319
boost::shared_ptr< bool > BoolSharedPtr
Definition: NekManager.hpp:80
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static boost::shared_mutex m_mutex
Definition: NekManager.hpp:322
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
template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
ValueType Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::operator[] ( typename boost::call_traits< KeyType >::const_reference  key)
inline

Definition at line 190 of file NekManager.hpp.

191  {
192  typename ValueContainer::iterator found = m_values->find(key);
193 
194  if( found != m_values->end() )
195  {
196  return (*found).second;
197  }
198  else
199  {
200  // No object, create a new one.
202  typename CreateFuncContainer::iterator keyFound = m_keySpecificCreateFuncs.find(key);
203  if( keyFound != m_keySpecificCreateFuncs.end() )
204  {
205  f = (*keyFound).second;
206  }
207 
208  if( f )
209  {
210  ValueType v = f(key);
211  if (*m_managementEnabled)
212  {
213  (*m_values)[key] = v;
214  }
215  return v;
216  }
217  else
218  {
219  std::string keyAsString = boost::lexical_cast<std::string>(key);
220  std::string message = std::string("No create func found for key ") + keyAsString;
221  NEKERROR(ErrorUtil::efatal, message.c_str());
222  static ValueType result;
223  return result;
224  }
225  }
226  }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:191
boost::function< ValueType(const KeyType &key)> CreateFuncType
Definition: NekManager.hpp:75
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:321
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< ValueT > ValueType
Definition: NekManager.hpp:74
ValueContainerShPtr m_values
Definition: NekManager.hpp:316
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 261 of file NekManager.hpp.

262  {
263  bool value = false;
264  typename ValueContainerPool::iterator x;
265 
266  x = m_ValueContainerPool.find(whichPool);
267  if (x != m_ValueContainerPool.end())
268  {
269  value = true;
270  }
271  return value;
272  }
static ValueContainerPool m_ValueContainerPool
Definition: NekManager.hpp:318
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
bool Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::RegisterCreator ( typename boost::call_traits< KeyType >::const_reference  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 161 of file NekManager.hpp.

163  {
164  m_keySpecificCreateFuncs[key] = createFunc;
165 
166  return true;
167  }
CreateFuncContainer m_keySpecificCreateFuncs
Definition: NekManager.hpp:321
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 171 of file NekManager.hpp.

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

172  {
173  m_globalCreateFunc = createFunc;
174 
175  return true;
176  }

Member Data Documentation

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

Definition at line 320 of file NekManager.hpp.

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

Definition at line 321 of file NekManager.hpp.

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

Definition at line 317 of file NekManager.hpp.

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

template<typename KeyType, typename ValueT, typename opLessCreator = defOpLessCreator<KeyType>>
boost::shared_mutex Nektar::LibUtilities::NekManager< KeyType, ValueT, opLessCreator >::m_mutex
staticprivate

Definition at line 322 of file NekManager.hpp.

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

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

Definition at line 316 of file NekManager.hpp.