#include <pool.hh>
Classes | |
class | Handle |
Public Types | |
typedef std::function< ref< R >()> | Factory |
typedef std::function< bool(const ref< R > &)> | Validator |
Public Member Functions | |
Pool (size_t max=std::numeric_limits< size_t >::max(), const Factory &factory=[]() { return make_ref< R >();}, const Validator &validator=[](ref< R > r) { return true;}) | |
void | incCapacity () |
void | decCapacity () |
Handle | get () |
size_t | count () |
size_t | capacity () |
void | flushBad () |
This template class implements a simple pool manager of resources of some type R, such as database connections. It is used as follows:
class Connection { ... };
Pool<Connection> pool;
{ auto conn(pool.get()); conn->exec("select ..."); }
Here, the Connection object referenced by ‘conn’ is automatically returned to the pool when ‘conn’ goes out of scope.
A function that produces new instances of R on demand.
A function that checks whether an instance of R is still usable. Unusable instances are removed from the pool.