asynchrony 2.3.1
Add asynchrony to your C++ applications using standard C++20
Loading...
Searching...
No Matches
siddiqsoft::resource_wrap< T > Class Template Reference

Public Member Functions

 resource_wrap ()=delete
 Default constructor is deleted Resources must be explicitly constructed with a valid resource.
 resource_wrap (T &&src, std::function< void(T &&)> &&f={})
 Construct a resource_wrap with a resource and optional callback.
 resource_wrap (const T &)=delete
 Copy constructor is deleted Resources are move-only to maintain clear ownership semantics.
resource_wrapoperator= (T &&src)
 Move assignment operator.
resource_wrapoperator= (const resource_wrap &)=delete
 Copy assignment is deleted.
auto operator* () -> T &
 operator T ()
 Type conversion operator.
 ~resource_wrap ()
 Destructor - automatically returns resource to pool if valid.

Protected Attributes

rsrc {}
 The actual resource being wrapped.
uint64_t debugId {static_cast<uint64_t>(std::rand())}
 Debug identifier for tracking (used in DEBUG builds).
std::function< void(T &&)> putbackCallback {}
 Callback function to return the resource to the pool Called by destructor when resource is valid.
bool isValid {false}
 Tracks whether the resource is valid and should be returned to pool Prevents returning uninitialized or moved-out resources.

Detailed Description

template<typename T>
requires std::move_constructible<T>
class siddiqsoft::resource_wrap< T >

Definition at line 105 of file resource_pool.hpp.

Constructor & Destructor Documentation

◆ resource_wrap()

template<typename T>
siddiqsoft::resource_wrap< T >::resource_wrap ( T && src,
std::function< void(T &&)> && f = {} )
inline

Construct a resource_wrap with a resource and optional callback.

Parameters
srcR-value reference to the resource to wrap
fOptional callback function to return resource to pool

The resource is marked as valid upon construction. The callback is typically provided by resource_pool::checkout() to automatically return the resource.

Note
This constructor is typically called by resource_pool::checkout()

Definition at line 141 of file resource_pool.hpp.

◆ ~resource_wrap()

template<typename T>
siddiqsoft::resource_wrap< T >::~resource_wrap ( )
inline

Destructor - automatically returns resource to pool if valid.

The destructor implements the RAII pattern:

  • If isValid is true and putbackCallback exists: returns resource to pool
  • If isValid is false: resource is discarded (not returned)

This ensures resources are always properly managed, even if an exception occurs.

Note
This is called automatically when the resource_wrap goes out of scope
Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 222 of file resource_pool.hpp.

Member Function Documentation

◆ operator T()

template<typename T>
siddiqsoft::resource_wrap< T >::operator T ( )
inline

Type conversion operator.

Returns
Copy of the wrapped resource

Allows implicit conversion to the resource type. Useful for passing to functions expecting the resource type.

Definition at line 208 of file resource_pool.hpp.

◆ operator*()

template<typename T>
auto siddiqsoft::resource_wrap< T >::operator* ( ) -> T &
inline

Definition at line 197 of file resource_pool.hpp.

◆ operator=()

template<typename T>
resource_wrap & siddiqsoft::resource_wrap< T >::operator= ( T && src)
inline

Move assignment operator.

Parameters
srcR-value reference to the resource to assign
Returns
Reference to this resource_wrap

Assigns a new resource to this wrapper and marks it as valid. The previous resource (if any) is discarded.

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 173 of file resource_pool.hpp.

Member Data Documentation

◆ debugId

template<typename T>
uint64_t siddiqsoft::resource_wrap< T >::debugId {static_cast<uint64_t>(std::rand())}
protected

Debug identifier for tracking (used in DEBUG builds).

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 112 of file resource_pool.hpp.

◆ isValid

template<typename T>
bool siddiqsoft::resource_wrap< T >::isValid {false}
protected

Tracks whether the resource is valid and should be returned to pool Prevents returning uninitialized or moved-out resources.

  • true: resource will be returned to pool on destruction
  • false: resource will NOT be returned to pool on destruction
Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 122 of file resource_pool.hpp.

◆ putbackCallback

template<typename T>
std::function<void(T&&)> siddiqsoft::resource_wrap< T >::putbackCallback {}
protected

Callback function to return the resource to the pool Called by destructor when resource is valid.

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 116 of file resource_pool.hpp.

◆ rsrc

template<typename T>
T siddiqsoft::resource_wrap< T >::rsrc {}
protected

The actual resource being wrapped.

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 109 of file resource_pool.hpp.


The documentation for this class was generated from the following file: