]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Library.hh
renamed mippleton to library
[chaz/yoink] / src / Moof / Library.hh
similarity index 78%
rename from src/Moof/Mippleton.hh
rename to src/Moof/Library.hh
index a27a6c5023645e049fe51cebe6055a34964cda9c..1d5af36c34b6f22cff945ad3e8be5bb9d6001434 100644 (file)
 
 *******************************************************************************/
 
-#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>
@@ -49,7 +48,7 @@ namespace Mf {
 
 
 template <class T>
-class Mippleton
+class Library
 {
        typedef std::pair<unsigned,T*>                                                  PtrValue;
        typedef stlplus::hash<std::string,PtrValue,getHash>             PtrMap;
@@ -68,8 +67,11 @@ class Mippleton
                }
                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; 
                }
        }
@@ -83,7 +85,8 @@ class Mippleton
        {
                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);
@@ -92,7 +95,7 @@ class Mippleton
 
 public:
 
-       explicit Mippleton(const std::string& name) :
+       explicit Library(const std::string& name) :
                mName(name) {}
 
        const std::string& getName() const
@@ -108,12 +111,12 @@ public:
 
 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: *************************************************/
 
This page took 0.02193 seconds and 4 git commands to generate.