36 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP 
   37 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP 
   41 #include <boost/function.hpp> 
   42 #include <boost/call_traits.hpp> 
   43 #include <boost/concept_check.hpp> 
   44 #include <boost/thread/shared_mutex.hpp> 
   45 #include <boost/thread/locks.hpp> 
   47 #include <boost/shared_ptr.hpp> 
   52     namespace LibUtilities
 
   56         typedef boost::unique_lock<boost::shared_mutex> 
WriteLock;
 
   57         typedef boost::shared_lock<boost::shared_mutex> 
ReadLock;
 
   59         template <
typename KeyType>
 
   68         template <
typename KeyType, 
typename ValueT, 
typename opLessCreator = defOpLessCreator<KeyType> >
 
   72                 BOOST_CLASS_REQUIRE(KeyType, boost, LessThanComparableConcept);
 
   86                     m_keySpecificCreateFuncs()
 
   89                     if (!whichPool.empty())
 
   92                         if (iter != m_ValueContainerPool.end())
 
   94                             m_values = iter->second;
 
   95                             m_managementEnabled = m_managementEnabledContainerPool[whichPool];
 
   99                             m_values = ValueContainerShPtr(
new ValueContainer);
 
  100                             m_ValueContainerPool[whichPool] = m_values;
 
  101                             if (m_managementEnabledContainerPool.find(whichPool) == m_managementEnabledContainerPool.end())
 
  103                                 m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(
new bool(
true));
 
  105                             m_managementEnabled = m_managementEnabledContainerPool[whichPool];
 
  110                         m_values = ValueContainerShPtr(
new ValueContainer);
 
  111                         m_managementEnabled = BoolSharedPtr(
new bool(
true));
 
  116                 explicit NekManager(CreateFuncType f, std::string whichPool=
"") :
 
  118                     m_globalCreateFunc(f),
 
  119                     m_keySpecificCreateFuncs()
 
  121                     if (!whichPool.empty())
 
  123                         ReadLock v_rlock(m_mutex); 
 
  125                         if (iter != m_ValueContainerPool.end())
 
  127                             m_values = iter->second;
 
  128                             m_managementEnabled = m_managementEnabledContainerPool[whichPool];
 
  137                             WriteLock v_wlock(m_mutex);
 
  138                             m_values = ValueContainerShPtr(
new ValueContainer);
 
  139                             m_ValueContainerPool[whichPool] = m_values;
 
  140                             if (m_managementEnabledContainerPool.find(whichPool) == m_managementEnabledContainerPool.end())
 
  142                                 m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(
new bool(
true));
 
  144                             m_managementEnabled = m_managementEnabledContainerPool[whichPool];
 
  150                         m_values = ValueContainerShPtr(
new ValueContainer);
 
  151                         m_managementEnabled = BoolSharedPtr(
new bool(
true));
 
  162                                      const CreateFuncType& createFunc)
 
  164                     m_keySpecificCreateFuncs[key] = createFunc;
 
  173                     m_globalCreateFunc = createFunc;
 
  182                     if( found != m_values->end() )
 
  190                 ValueType 
operator[](
typename boost::call_traits<KeyType>::const_reference key)
 
  194                     if( found != m_values->end() )
 
  196                         return (*found).second;
 
  201                         CreateFuncType f = m_globalCreateFunc;
 
  203                         if( keyFound != m_keySpecificCreateFuncs.end() )
 
  205                             f = (*keyFound).second;
 
  210                             ValueType v = f(key);
 
  211                             if (*m_managementEnabled)
 
  213                                 (*m_values)[key] = v;
 
  219                             std::string keyAsString = boost::lexical_cast<std::string>(key);
 
  220                             std::string message = std::string(
"No create func found for key ") + keyAsString;
 
  222                             static ValueType result;
 
  228                 void DeleteObject(
typename boost::call_traits<KeyType>::const_reference key)
 
  232                     if( found != m_values->end() )
 
  234                         m_values->erase(found);
 
  241                     if (!whichPool.empty())
 
  243                         WriteLock v_wlock(m_mutex);
 
  245                         x = m_ValueContainerPool.find(whichPool);
 
  246                         ASSERTL1(x != m_ValueContainerPool.end(),
 
  247                                 "Could not find pool " + whichPool);
 
  252                         WriteLock v_wlock(m_mutex);
 
  254                         for (x = m_ValueContainerPool.begin(); x != m_ValueContainerPool.end(); ++x)
 
  266                     x = m_ValueContainerPool.find(whichPool);
 
  267                     if (x != m_ValueContainerPool.end())
 
  277                     if (!whichPool.empty())
 
  279                         WriteLock v_wlock(m_mutex);
 
  281                         x = m_managementEnabledContainerPool.find(whichPool);
 
  282                         if (x != m_managementEnabledContainerPool.end())
 
  288                             m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(
new bool(
true));
 
  296                     if (!whichPool.empty())
 
  298                         WriteLock v_wlock(m_mutex);
 
  300                         x = m_managementEnabledContainerPool.find(whichPool);
 
  301                         if (x != m_managementEnabledContainerPool.end())
 
  303                             (*x->second) = 
false;
 
  307                             m_managementEnabledContainerPool[whichPool] = BoolSharedPtr(
new bool(
false));
 
  326         template <
typename KeyType, 
typename ValueT, 
typename opLessCreator>
 
  332 #endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP 
boost::unique_lock< boost::shared_mutex > WriteLock
 
static void DisableManagement(std::string whichPool="")
 
boost::shared_ptr< ValueContainer > ValueContainerShPtr
 
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
 
NekManager(CreateFuncType f, std::string whichPool="")
 
static FlagContainerPool m_managementEnabledContainerPool
 
NekManager(std::string whichPool="")
 
static ValueContainerPool m_ValueContainerPool
 
CreateFuncType m_globalCreateFunc
 
boost::shared_ptr< bool > BoolSharedPtr
 
static void EnableManagement(std::string whichPool="")
 
std::map< KeyType, ValueType > ValueContainer
 
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 cal...
 
boost::function< ValueType(const KeyType &key)> CreateFuncType
 
BoolSharedPtr m_managementEnabled
 
bool operator()(const KeyType &lhs, const KeyType &rhs) const 
 
std::map< std::string, boost::shared_ptr< ValueContainer > > ValueContainerPool
 
void DeleteObject(typename boost::call_traits< KeyType >::const_reference key)
 
boost::shared_lock< boost::shared_mutex > ReadLock
 
bool AlreadyCreated(typename boost::call_traits< KeyType >::const_reference key)
 
std::map< KeyType, CreateFuncType, opLessCreator > CreateFuncContainer
 
CreateFuncContainer m_keySpecificCreateFuncs
 
static void ClearManager(std::string whichPool="")
 
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
 
static bool PoolCreated(std::string whichPool)
 
boost::shared_ptr< ValueT > ValueType
 
static boost::shared_mutex m_mutex
 
bool RegisterGlobalCreator(const CreateFuncType &createFunc)
Register the Global Create Function. The return value is just to facilitate calling statically...
 
ValueContainerShPtr m_values
 
std::map< std::string, BoolSharedPtr > FlagContainerPool
 
ValueType operator[](typename boost::call_traits< KeyType >::const_reference key)
 
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...