blocxx
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
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:

Definition at line 97 of file AutoResource.hpp.

Member Typedef Documentation

◆ AutoResource< Policy >safe_bool

Definition at line 161 of file AutoResource.hpp.

◆ handle_type

template<typename Policy >
typedef 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()

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()

template<typename Policy >
handle_type BLOCXX_NAMESPACE::AutoResource< Policy >::get ( ) const
inline

Return handle of resource, retaining ownership.

Definition at line 165 of file AutoResource.hpp.

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

◆ operator AutoResourceRef< Policy >()

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

Definition at line 211 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::operator==(), and 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]

Assignment takes over ownership of resource owned by x.

Definition at line 148 of file AutoResource.hpp.

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

◆ operator=() [2/2]

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::operator==().

◆ release()

Relinquish ownership of resource and return its handle.

Definition at line 172 of file AutoResource.hpp.

References BLOCXX_NAMESPACE::AutoResource< Policy >::hdl, and BLOCXX_NAMESPACE::operator==().

Referenced by BLOCXX_NAMESPACE::AutoResource< Policy >::operator AutoResourceRef< Policy >().

◆ reset() [1/2]

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

◆ reset() [2/2]

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, and BLOCXX_NAMESPACE::operator==().

Member Data Documentation

◆ hdl


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