Manages a cache of objects of various types. More...
#include <ObjectPool.hpp>
Public Member Functions | |
template<typename T > | |
void | enableCaching (std::size_t maxCount, std::function< void(T *)> clearFunc) |
template<typename T > | |
void | disableCaching () |
Disables caching of objects of type T. More... | |
template<typename T > | |
void | getObj (std::shared_ptr< T > &objPtr, bool alwaysCreate=true) |
Manages a cache of objects of various types.
void RCF::ObjectPool::enableCaching | ( | std::size_t | maxCount, |
std::function< void(T *)> | clearFunc | ||
) |
Enables caching of objects of type T. The cache will hold at most maxCount instances of objects of type T. clearFunc() will be called on each instance of type T which is passed in to the cache.
void RCF::ObjectPool::disableCaching | ( | ) |
Disables caching of objects of type T.
void RCF::ObjectPool::getObj | ( | std::shared_ptr< T > & | objPtr, |
bool | alwaysCreate = true |
||
) |
Returns an object of type T from the cache. The object is returned as a std::shared_ptr<T> and is equipped with a custom deleter, so that once the shared_ptr<T> goes out of scope, the object is automatically returned to the cache. If alwaysCreate is true, an object will be created if none is present in the cache.