X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FMippleton.hh;h=e9b97328d351ae9de7e08527a49984f90030231b;hp=9ef960276b34a8d9384557d2b2a8d690c36d7488;hb=5fa5f117f28922a7e539a432367960c1a61f837d;hpb=a5f0d391406a68275b41448fc3f49e8d8396c497 diff --git a/src/Moof/Mippleton.hh b/src/Moof/Mippleton.hh index 9ef9602..e9b9732 100644 --- a/src/Moof/Mippleton.hh +++ b/src/Moof/Mippleton.hh @@ -40,6 +40,8 @@ #include +#include + #include @@ -49,26 +51,15 @@ namespace Mf { template class Mippleton { - typedef std::pair ptr_value_t; - typedef std::pair ptr_map_pair_t; - typedef stlplus::hash ptr_map_t; - //typedef std::map ptr_map_t; - - static ptr_map_t ptrs_; - std::string name_; - -public: - explicit Mippleton(const std::string& name) : - name_(name) {} + typedef std::pair PtrValue; + typedef stlplus::hash PtrMap; - inline const std::string& getName() const - { - return name_; - } + static PtrMap ptrs_; + std::string name_; inline static T* retain(const std::string& name) { - typename ptr_map_t::iterator it = ptrs_.find(name); + typename PtrMap::iterator it = ptrs_.find(name); if (it != ptrs_.end()) { @@ -78,14 +69,19 @@ public: else { T* newObj = new T(name); - ptrs_.insert(ptr_map_pair_t(name, ptr_value_t(1, newObj))); + ptrs_.insert(std::make_pair(name, std::make_pair(1, newObj))); return newObj; } } + inline static void release(T* obj) + { + releaseByName(obj->name_); + } + inline static void releaseByName(const std::string& name) { - typename ptr_map_t::iterator it; + typename PtrMap::iterator it; if ((it = ptrs_.find(name)) != ptrs_.end() && --(*it).second.first == 0) { @@ -94,15 +90,23 @@ public: } } - inline static void release(T* obj) +public: + explicit Mippleton(const std::string& name) : + name_(name) {} + + inline const std::string& getName() const + { + return name_; + } + + inline static boost::shared_ptr getInstance(const std::string& name) { - releaseByName(obj->getName()); + return boost::shared_ptr(retain(name), &release); } }; template -stlplus::hash< std::string,std::pair,hash_string > -//std::map< std::string,std::pair > +stlplus::hash< std::string,std::pair,getHash > Mippleton::ptrs_;