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>
45 #include <boost/shared_ptr.hpp>
52 namespace LibUtilities
54 template <
typename KeyType>
57 bool operator()(
const KeyType &
lhs,
const KeyType &rhs)
const
63 template <
typename KeyType,
typename ValueT,
typename opLessCreator = defOpLessCreator<KeyType> >
67 BOOST_CLASS_REQUIRE(KeyType, boost, LessThanComparableConcept);
81 m_keySpecificCreateFuncs()
83 if (!whichPool.empty())
86 if (iter != m_ValueContainerPool.end())
88 m_values = iter->second;
89 m_managementEnabled = m_managementEnabledContainerPool[whichPool];
94 m_ValueContainerPool[whichPool] = m_values;
95 if (m_managementEnabledContainerPool.find(whichPool) == m_managementEnabledContainerPool.end())
97 m_managementEnabledContainerPool[whichPool] =
BoolSharedPtr(
new bool(
true));
99 m_managementEnabled = m_managementEnabledContainerPool[whichPool];
112 m_globalCreateFunc(f),
113 m_keySpecificCreateFuncs()
115 if (!whichPool.empty())
118 if (iter != m_ValueContainerPool.end())
120 m_values = iter->second;
121 m_managementEnabled = m_managementEnabledContainerPool[whichPool];
126 m_ValueContainerPool[whichPool] = m_values;
127 if (m_managementEnabledContainerPool.find(whichPool) == m_managementEnabledContainerPool.end())
129 m_managementEnabledContainerPool[whichPool] =
BoolSharedPtr(
new bool(
true));
131 m_managementEnabled = m_managementEnabledContainerPool[whichPool];
148 bool RegisterCreator(
typename boost::call_traits<KeyType>::const_reference key,
151 m_keySpecificCreateFuncs[key] = createFunc;
160 m_globalCreateFunc = createFunc;
165 bool AlreadyCreated(
typename boost::call_traits<KeyType>::const_reference key)
169 if( found != m_values->end() )
177 ValueType operator[](
typename boost::call_traits<KeyType>::const_reference key)
181 if( found != m_values->end() )
183 return (*found).second;
190 if( keyFound != m_keySpecificCreateFuncs.end() )
192 f = (*keyFound).second;
198 if (*m_managementEnabled)
200 (*m_values)[key] = v;
206 std::string keyAsString = boost::lexical_cast<std::string>(key);
207 std::string message = std::string(
"No create func found for key ") + keyAsString;
215 void DeleteObject(
typename boost::call_traits<KeyType>::const_reference key)
219 if( found != m_values->end() )
221 m_values->erase(found);
225 static void ClearManager(std::string whichPool =
"")
228 if (!whichPool.empty())
230 x = m_ValueContainerPool.find(whichPool);
231 ASSERTL1(x != m_ValueContainerPool.end(),
232 "Could not find pool " + whichPool);
237 for (x = m_ValueContainerPool.begin(); x != m_ValueContainerPool.end(); ++x)
244 static void EnableManagement(std::string whichPool =
"")
247 if (!whichPool.empty())
249 x = m_managementEnabledContainerPool.find(whichPool);
250 if (x != m_managementEnabledContainerPool.end())
256 m_managementEnabledContainerPool[whichPool] =
BoolSharedPtr(
new bool(
true));
261 static void DisableManagement(std::string whichPool =
"")
264 if (!whichPool.empty())
266 x = m_managementEnabledContainerPool.find(whichPool);
267 if (x != m_managementEnabledContainerPool.end())
269 (*x->second) =
false;
273 m_managementEnabledContainerPool[whichPool] =
BoolSharedPtr(
new bool(
false));
295 #endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_NEK_MANAGER_HPP