]>
Dogcows Code - chaz/yoink/blob - src/Moof/Manager.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_MANAGER_HH_
13 #define _MOOF_MANAGER_HH_
17 * A library is a collection of named objects of the same type. Libraries
18 * use reference counting to automagically delete objects which no longer
19 * have any interested code.
24 #include <boost/shared_ptr.hpp>
26 #include <Moof/Hash.hh>
40 const std::string
& getName() const
45 static boost::shared_ptr
<T
> getInstance(const std::string
& name
)
47 return boost::shared_ptr
<T
>(retain(name
), &release
);
52 typedef stlplus::hash
<std::string
,T
*,getHash
> PtrMap
;
54 static PtrMap mPtrMap
;
56 unsigned mRetainCount
;
58 static T
* retain(const std::string
& name
)
60 typename
PtrMap::iterator it
= mPtrMap
.find(name
);
62 if (it
!= mPtrMap
.end())
64 ++((*it
).second
->mRetainCount
);
74 mPtrMap
.insert(std::make_pair(name
, newObj
));
80 static void release(T
* obj
)
82 if (--(obj
->mRetainCount
) == 0)
84 mPtrMap
.erase(obj
->mName
);
91 stlplus::hash
<std::string
,T
*,getHash
> Manager
<T
>::mPtrMap
;
96 #endif // _MOOF_MANAGER_HH_
This page took 0.038715 seconds and 4 git commands to generate.