#define _MOOF_MANAGER_HH_
/**
- * @file Manager.hh
- * A library is a collection of named objects of the same type. Libraries
+ * \file manager.hh
+ * A manager is a collection of named objects of the same type. Libraries
* use reference counting to automagically delete objects which no longer
* have any interested code.
*/
#include <boost/shared_ptr.hpp>
-#include <Moof/HashTools.hh>
+#include <moof/hash.hh>
-namespace Mf {
+namespace moof {
template <class T>
-class Manager
+class manager
{
public:
- Manager() :
- mRetainCount(1) {}
+ manager() :
+ retain_count_(1) {}
- const std::string& getName() const
+ const std::string& name() const
{
- return mName;
+ return name_;
}
- static boost::shared_ptr<T> getInstance(const std::string& name)
+ static boost::shared_ptr<T> instance(const std::string& name)
{
return boost::shared_ptr<T>(retain(name), &release);
}
-private:
- typedef stlplus::hash<std::string,T*,HashFunction> PtrMap;
+private:
- static PtrMap mPtrMap;
- std::string mName;
- unsigned mRetainCount;
+ typedef stlplus::hash<std::string,T*,hash_function> ptr_lookup;
static T* retain(const std::string& name)
{
- typename PtrMap::iterator it = mPtrMap.find(name);
+ typename ptr_lookup::iterator it = ptr_lookup_.find(name);
- if (it != mPtrMap.end())
+ if (it != ptr_lookup_.end())
{
- ++((*it).second->mRetainCount);
+ ++((*it).second->retain_count_);
return (*it).second;
}
else
{
- T* newObj(new T);
- if (newObj)
+ T* new_object(new T);
+ if (new_object)
{
- newObj->mName = name;
- newObj->init(name);
- mPtrMap.insert(std::make_pair(name, newObj));
+ new_object->name_ = name;
+ new_object->init(name);
+ ptr_lookup_.insert(std::make_pair(name, new_object));
}
- return newObj;
+ return new_object;
}
}
static void release(T* obj)
{
- if (--(obj->mRetainCount) == 0)
+ if (--(obj->retain_count_) == 0)
{
- mPtrMap.erase(obj->mName);
+ ptr_lookup_.erase(obj->name_);
delete obj;
}
}
+
+
+ static ptr_lookup ptr_lookup_;
+ std::string name_;
+ unsigned retain_count_;
};
template <class T>
-stlplus::hash<std::string,T*,HashFunction> Manager<T>::mPtrMap;
+hash<std::string,T*,hash_function> manager<T>::ptr_lookup_;
-} // namespace Mf
+} // namespace moof
#endif // _MOOF_MANAGER_HH_