![]() |
AnCH Framework
0.1
Another C++ Hack Framework
|
Generic resource pool utility class. More...
#include <resourcePool.hpp>
Public Member Functions | |
ResourcePool (const C &config, std::size_t maxSize, std::size_t initialiSize=0, std::chrono::milliseconds timeout=std::chrono::milliseconds(100)) | |
ResourcePool (const ResourcePool &)=delete | |
virtual | ~ResourcePool () |
PoolableResource | borrowResource () |
void | setTimeout (const std::chrono::milliseconds timeout) |
Generic resource pool utility class.
Maximum number of resources is mandatory.
Intialize pool size will instanciate resources for imediate use.
Resources will be instanciated with their configuration.
If no resource is available, pool will wait until timeout (default to 100ms) is reached.
Resources are automatically released through their destructor.
If you have only one action to do, you can use pool.borrowResource.get().doAction() ; otherwise you should to keep reference to anch::PoolableResource
until all actions have been done (with auto res = pool.borrowResource()).
You can specifiy an std::shared_ptr
creation function as third template parameter. By default, std::make_shared<T>
will be used. It can be usefull for polymorphism dynamic allocation.
|
inline |
ResourcePool constructor
config | the resource configuration |
maxSize | the pool maximum size |
initialiSize | the initialize size |
timeout | the timeout |
|
delete |
Prohibits ResourcePool copy constructor
|
inlinevirtual |
ResourcePool destructor
Destroy every resource in pool.
|
inline |
Retrieve available resource if there is one.
Create a new resource if maximum size has not been reached.
This method will raise TimeoutException if timeout has been reached while waiting available resource or any other exception thrown by the resource constructor.
anch::PoolableResource
)
|
inline |
Timeout setter
timeout | the timeout to set |