blocxx
BLOCXX_NAMESPACE::AutoResource< Policy > Class Template Reference

PURPOSE: The AutoResource class template is an analog of std::auto_ptr for managing arbitrary resource handles. More...

#include <AutoResource.hpp>

Public Types

typedef handle_type AutoResource< Policy >safe_bool
 

Public Member Functions

 AutoResource ()
 Default (no argument) ctor initializes with value indicating no resource currently owned.
 
 AutoResource (handle_type h)
 Take over ownership of h.
 
 AutoResource (AutoResource &x)
 Take over ownership of resource owned by x.
 
AutoResourceoperator= (AutoResource &x)
 Assignment takes over ownership of resource owned by x.
 
 ~AutoResource ()
 Free resource when AutoResource object reaches end of lifetime.
 
 operator safe_bool () const
 
bool operator! () const
 
handle_type get () const
 Return handle of resource, retaining ownership.
 
handle_type release ()
 Relinquish ownership of resource and return its handle.
 
void reset (handle_type h)
 Free resource and take over ownership of another.
 
void reset ()
 
 AutoResource (AutoResourceRef< Policy > href)
 Conversion to facilitate passing and returning AutoResource by value (which transfers ownership).
 
 operator AutoResourceRef< Policy > ()
 Conversion to facilitate passing and returning AutoResource by value (which transfers ownership).
 
AutoResourceoperator= (AutoResourceRef< Policy > href)
 Converting assignment to facilitate returning autorc by value (which transfers ownership).
 

Private Types

typedef Policy::handle_type handle_type
 

Private Attributes

handle_type hdl
 

Detailed Description

template<typename Policy>
class BLOCXX_NAMESPACE::AutoResource< Policy >

PURPOSE: The AutoResource class template is an analog of std::auto_ptr for managing arbitrary resource handles.

The Policy template argument specifies what type of resource to manage and how to release the resource.

PROMISE: None of the operations of the class throw exceptions.

REQUIRE: the Policy argument used below must be a class with these properties:

  • Policy::handle_type is the type of resource handle to be managed.
  • Policy::null() is an expression convertible to Policy::handle_type, denoting an invalid resource handle. It always returns the same value, and throws no exception.
  • Policy::free(h) is a legal expression whenever h is convertible to Policy::handle_type. It frees the resource indicated by h, unless h is Policy::null(), in which case it does nothing. It throws no exception.
  • Policy::equal(h1, h2) is a legal expression convertible to bool whenever h1 and h2 are convertible to Policy::handle_type. Either

    • (1) the expression is always false, or
    • (2) the expression is true if and only if h1 and h2 are the same resource handle.

    Note the additional requirements for reset(handle_type) and operator=(autorc_ref) in case (1). The equal function never throws.

Definition at line 97 of file AutoResource.hpp.

Member Typedef Documentation

◆ AutoResource< Policy >safe_bool

template<typename Policy >
handle_type BLOCXX_NAMESPACE::AutoResource< Policy >::AutoResource< Policy >safe_bool

Definition at line 161 of file AutoResource.hpp.

◆ handle_type

template<typename Policy >
Policy::handle_type BLOCXX_NAMESPACE::AutoResource< Policy >::handle_type
private

Definition at line 99 of file AutoResource.hpp.

Constructor & Destructor Documentation

◆ AutoResource() [1/4]

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::AutoResource ( )
inline

Default (no argument) ctor initializes with value indicating no resource currently owned.

Definition at line 108 of file AutoResource.hpp.

◆ AutoResource() [2/4]

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::AutoResource ( handle_type h)
inlineexplicit

Take over ownership of h.

Definition at line 116 of file AutoResource.hpp.

◆ AutoResource() [3/4]

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::AutoResource ( AutoResource< Policy > & x)
inline

Take over ownership of resource owned by x.

Definition at line 131 of file AutoResource.hpp.

◆ ~AutoResource()

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::~AutoResource ( )
inline

Free resource when AutoResource object reaches end of lifetime.

Definition at line 156 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::hdl.

◆ AutoResource() [4/4]

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::AutoResource ( AutoResourceRef< Policy > href)
inline

Conversion to facilitate passing and returning AutoResource by value (which transfers ownership).

Definition at line 202 of file AutoResource.hpp.

Member Function Documentation

◆ get()

◆ operator AutoResourceRef< Policy >()

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::operator AutoResourceRef< Policy > ( )
inline

Conversion to facilitate passing and returning AutoResource by value (which transfers ownership).

Definition at line 211 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::release().

◆ operator safe_bool()

template<typename Policy >
BLOCXX_NAMESPACE::AutoResource< Policy >::operator safe_bool ( ) const
inline

Definition at line 161 of file AutoResource.hpp.

◆ operator!()

template<typename Policy >
bool BLOCXX_NAMESPACE::AutoResource< Policy >::operator! ( ) const
inline

Definition at line 161 of file AutoResource.hpp.

◆ operator=() [1/2]

template<typename Policy >
AutoResource & BLOCXX_NAMESPACE::AutoResource< Policy >::operator= ( AutoResource< Policy > & x)
inline

Assignment takes over ownership of resource owned by x.

Definition at line 148 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::release(), and BLOCXX_NAMESPACE::AutoResource< Policy >::reset().

◆ operator=() [2/2]

template<typename Policy >
AutoResource & BLOCXX_NAMESPACE::AutoResource< Policy >::operator= ( AutoResourceRef< Policy > href)
inline

Converting assignment to facilitate returning autorc by value (which transfers ownership).

REQUIRE: if Policy::equal() always returns false, then href must not contain the resource handle currently owned by *this;

Definition at line 223 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::hdl, and BLOCXX_NAMESPACE::AutoResourceRef< Policy >::hdl.

◆ release()

◆ reset() [1/2]

◆ reset() [2/2]

template<typename Policy >
void BLOCXX_NAMESPACE::AutoResource< Policy >::reset ( handle_type h)
inline

Free resource and take over ownership of another.

REQUIRE: if Policy::equal() always returns false, then h must must not be the resource handle currently owned by *this.

Definition at line 185 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::hdl.

Member Data Documentation

◆ hdl


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