|
arrp 0.0.15
Auto returning resource pool for modern C++
|
RAII wrapper for managing resource lifecycle with automatic return to pool. More...
#include <siddiqsoft/private/scoped_resource.hpp>
Public Member Functions | |
| scoped_resource ()=delete | |
| Default constructor is deleted. | |
| scoped_resource (T &&src, std::function< void(T &&)> &&f={}) | |
| scoped_resource (const T &)=delete | |
| Copy constructor is deleted. | |
| scoped_resource (scoped_resource &&src) noexcept | |
| scoped_resource & | operator= (scoped_resource &&src) noexcept |
| scoped_resource & | operator= (T &&src) |
| scoped_resource & | operator= (const scoped_resource &)=delete |
| Copy assignment operator is deleted. | |
| auto | operator* () -> T & |
| operator T& () | |
| void | invalidate () |
Protected Attributes | |
| T | m_rsrc {} |
| The actual resource being wrapped. | |
| std::function< void(T &&)> | m_putback_callback {} |
| Callback function to return the resource to the pool. | |
| bool | m_is_valid {false} |
| Tracks whether the resource is valid and should be returned to pool. | |
Friends | |
| template<typename U, typename SRT, uint8_t IC> | |
| class | resource_pool |
RAII wrapper for managing resource lifecycle with automatic return to pool.
| T | The resource type to wrap. Must be move-constructible and non-arithmetic. |
The scoped_resource class implements the Resource Acquisition Is Initialization (RAII) pattern for managing resources that should be returned to a resource pool. It wraps a resource and automatically invokes a callback when the wrapper is destroyed, enabling automatic resource management without manual cleanup.
Key Features:
Usage Pattern:
Thread Safety:
Constraints:
Definition at line 134 of file scoped_resource.hpp.
|
delete |
Default constructor is deleted.
Resources must be explicitly constructed with a valid resource. This prevents accidental creation of invalid scoped_resource objects.
Referenced by operator=(), and scoped_resource().
|
inlineexplicit |
Definition at line 203 of file scoped_resource.hpp.
|
explicitdelete |
Copy constructor is deleted.
Resources are move-only to maintain clear ownership semantics. Copying would create ambiguity about which wrapper owns the resource and when it should be returned to the pool.
References scoped_resource().
|
inlinenoexcept |
Definition at line 246 of file scoped_resource.hpp.
|
inline |
Definition at line 389 of file scoped_resource.hpp.
|
inline |
Definition at line 434 of file scoped_resource.hpp.
|
inline |
Definition at line 359 of file scoped_resource.hpp.
|
inline |
Definition at line 357 of file scoped_resource.hpp.
|
delete |
Copy assignment operator is deleted.
Copy assignment is not allowed to maintain move-only semantics and prevent resource ownership ambiguity.
References m_rsrc, and scoped_resource().
|
inlinenoexcept |
Definition at line 278 of file scoped_resource.hpp.
|
inline |
Definition at line 323 of file scoped_resource.hpp.
|
friend |
Definition at line 140 of file scoped_resource.hpp.
|
protected |
Tracks whether the resource is valid and should be returned to pool.
Prevents returning uninitialized or moved-out resources
Definition at line 156 of file scoped_resource.hpp.
|
protected |
Callback function to return the resource to the pool.
Called by destructor when resource is valid. Typically returns the resource to the resource_pool for reuse.
Definition at line 150 of file scoped_resource.hpp.
|
protected |
The actual resource being wrapped.
Stores the resource object that will be managed by this wrapper
Definition at line 145 of file scoped_resource.hpp.
Referenced by operator=().