*******************************************************************************/
-#ifndef _MOOF_MIPPLETON_HH_
-#define _MOOF_MIPPLETON_HH_
+#ifndef _MOOF_LIBRARY_HH_
+#define _MOOF_LIBRARY_HH_
/**
- * @file Mippleton.hh
- * Related to singletons, a mippleton is an object which can be obtained
- * globally using a unique name. Unlike singletons, there can be multiple
- * mippletons per class, each with a different name or identifier. Mippletons
- * are create automatically when they are first requested (retained) and deleted
- * after the last interested code releases its hold on the object.
+ * @file Library.hh
+ * A library 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 <memory>
#include <string>
#include <boost/shared_ptr.hpp>
template <class T>
-class Mippleton
+class Library
{
typedef std::pair<unsigned,T*> PtrValue;
typedef stlplus::hash<std::string,PtrValue,getHash> PtrMap;
}
else
{
- T* newObj = new T(name);
- mPtrMap.insert(std::make_pair(name, std::make_pair(1, newObj)));
+ T* newObj(new T(name));
+ if (newObj)
+ {
+ mPtrMap.insert(std::make_pair(name, std::make_pair(1, newObj)));
+ }
return newObj;
}
}
{
typename PtrMap::iterator it;
- if ((it = mPtrMap.find(name)) != mPtrMap.end() && --(*it).second.first == 0)
+ if ((it = mPtrMap.find(name)) != mPtrMap.end() &&
+ --(*it).second.first == 0)
{
delete (*it).second.second;
mPtrMap.erase((*it).first);
public:
- explicit Mippleton(const std::string& name) :
+ explicit Library(const std::string& name) :
mName(name) {}
const std::string& getName() const
template <class T>
stlplus::hash< std::string,std::pair<unsigned,T*>,getHash >
- Mippleton<T>::mPtrMap;
+ Library<T>::mPtrMap;
} // namespace Mf
-#endif // _MOOF_MIPPLETON_HH_
+#endif // _MOOF_LIBRARY_HH_
/** vim: set ts=4 sw=4 tw=80: *************************************************/