ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::lang::Owner< TOwnable, TOptional > Class Template Reference

Description:

template<typename TOwnable, bool TOptional = false>
class alib::lang::Owner< TOwnable, TOptional >

Ensures that an object of template type TOwnable is acquired and properly released when unwinding the stack (RAII idiom ). This class is meant to be allocated only on the stack and not on the heap. Therefore, the new operators as well as copy and move constructors and assignment operators are declared private.

With debug-builds, the constructor expects caller source information parameters of type CallerInfo. Use macro ALIB_CALLER_PRUNED to prune those with release-builds.

In the rather unusual case that it is a run-time decision whether this object should carry an object to acquire or not, the template parameter TOptional may be set to true. With that, pointers are accepted with construction and method Set becomes available.

See also
Template Parameters
TOwnableThe type to own. Requirements are to have methods Acquire and Release available.
TOptionalIf true, then checks is performed, whether the given owned is nulled and thus not acquired and released. If false such checks are omitted.

Definition at line 45 of file owner.inl.

Collaboration diagram for alib::lang::Owner< TOwnable, TOptional >:
[legend]

Public Type Index:

using OwnablePointer = std::remove_reference_t<TOwnable>*
 The pointer type of the owned object.
 

Public Method Index:

 Owner (OwnablePointer ownable, const CallerInfo &ci)
 
 Owner (TOwnable &ownable, const CallerInfo &ci)
 
 ~Owner ()
 Destructor. Releases the owner by invoking Release().
 
void Set (OwnablePointer ownable)
 

Protected Field Index:

CallerInfo dbgCI
 Caller information. Available only with debug-builds.
 
OwnablePointer owned
 The resource to acquire and release.
 

Type Definition Details:

◆ OwnablePointer

template<typename TOwnable, bool TOptional = false>
using alib::lang::Owner< TOwnable, TOptional >::OwnablePointer = std::remove_reference_t<TOwnable>*

The pointer type of the owned object.

Definition at line 51 of file owner.inl.

Field Details:

◆ dbgCI

template<typename TOwnable, bool TOptional = false>
CallerInfo alib::lang::Owner< TOwnable, TOptional >::dbgCI
protected

Caller information. Available only with debug-builds.

Definition at line 56 of file owner.inl.

◆ owned

template<typename TOwnable, bool TOptional = false>
OwnablePointer alib::lang::Owner< TOwnable, TOptional >::owned
protected

The resource to acquire and release.

Definition at line 54 of file owner.inl.

Constructor(s) / Destructor Details:

◆ Owner() [1/2]

template<typename TOwnable, bool TOptional = false>
alib::lang::Owner< TOwnable, TOptional >::Owner ( TOwnable & ownable,
const CallerInfo & ci )
inline

Constructor. Invokes Acquire() on the ownable.

Parameters
ownableThe ownable to acquire.
ciCaller information.

Definition at line 77 of file owner.inl.

◆ Owner() [2/2]

template<typename TOwnable, bool TOptional = false>
alib::lang::Owner< TOwnable, TOptional >::Owner ( OwnablePointer ownable,
const CallerInfo & ci )
inline

Constructor taking a pointer to the ownable. This constructor is only available if the template parameter TOptional is true.

Parameters
ownableThe ownable to acquire.
ciCaller information.

Definition at line 85 of file owner.inl.

◆ ~Owner()

template<typename TOwnable, bool TOptional = false>
alib::lang::Owner< TOwnable, TOptional >::~Owner ( )
inline

Destructor. Releases the owner by invoking Release().

Definition at line 97 of file owner.inl.

Method Details:

◆ Set()

template<typename TOwnable, bool TOptional = false>
void alib::lang::Owner< TOwnable, TOptional >::Set ( OwnablePointer ownable)
inline

Sets the ownable after construction. This method is only available if the template parameter TOptional is true. It must not be called if an object was given with construction already, and it must not be called twice. If done, an assertion is raised.

Parameters
ownableThe ownable to acquire.

Definition at line 103 of file owner.inl.


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