X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FLibrary.hh;fp=src%2FMoof%2FMippleton.hh;h=1d5af36c34b6f22cff945ad3e8be5bb9d6001434;hp=a27a6c5023645e049fe51cebe6055a34964cda9c;hb=bffc879fc8ee8167bb123310d39fad4e2f426ffd;hpb=9619ed3cee0f9e465ad2747fcb4f1f6cb6d3d889 diff --git a/src/Moof/Mippleton.hh b/src/Moof/Library.hh similarity index 78% rename from src/Moof/Mippleton.hh rename to src/Moof/Library.hh index a27a6c5..1d5af36 100644 --- a/src/Moof/Mippleton.hh +++ b/src/Moof/Library.hh @@ -26,18 +26,17 @@ *******************************************************************************/ -#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 #include #include @@ -49,7 +48,7 @@ namespace Mf { template -class Mippleton +class Library { typedef std::pair PtrValue; typedef stlplus::hash 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 stlplus::hash< std::string,std::pair,getHash > - Mippleton::mPtrMap; + Library::mPtrMap; } // namespace Mf -#endif // _MOOF_MIPPLETON_HH_ +#endif // _MOOF_LIBRARY_HH_ /** vim: set ts=4 sw=4 tw=80: *************************************************/