Public Member Functions | Protected Member Functions

Utils::Guard< T > Class Template Reference

This template class employs a C++ idiom (described by Bjarne Stroustrup) that uses the constructor to acquire a resource automatically when an object of the class is created and uses the destructor to release the resource automatically when it goes out of scope. More...

#include <B2BITS_Guard.h>

List of all members.

Public Member Functions

 Guard (T &lock)
 Constructor.
void release ()
 Releases the resource.
 ~Guard ()
 Destructor.

Protected Member Functions

 Guard (const Guard &)
 Copy constructor.
Guardoperator= (const Guard &)
 Assignment operator.

Detailed Description

template<class T>
class Utils::Guard< T >

This template class employs a C++ idiom (described by Bjarne Stroustrup) that uses the constructor to acquire a resource automatically when an object of the class is created and uses the destructor to release the resource automatically when it goes out of scope.

Since Guard is parameterized by the type of lock (such as Mutex), this class can be used with a fam-ily of synchronization wrappers that conform to a uniform interface. E.g.: Guard<Mutex> guard (lock_); // guard constructor acquires m_lock.

Definition at line 67 of file B2BITS_Guard.h.


Constructor & Destructor Documentation

template<class T >
Utils::Guard< T >::Guard ( T &  lock ) [inline]

Constructor.

Acquires the given resource.

Parameters:
lockResource monitor implementation

Definition at line 72 of file B2BITS_Guard.h.

template<class T >
Utils::Guard< T >::~Guard (  ) [inline]

Destructor.

Releases the given resource.

Definition at line 77 of file B2BITS_Guard.h.

References Utils::Guard< T >::release().

template<class T >
Utils::Guard< T >::Guard ( const Guard< T > &   ) [protected]

Copy constructor.


Member Function Documentation

template<class T >
Guard& Utils::Guard< T >::operator= ( const Guard< T > &   ) [protected]

Assignment operator.

template<class T >
void Utils::Guard< T >::release (  ) [inline]

Releases the resource.

Definition at line 84 of file B2BITS_Guard.h.

Referenced by Utils::Guard< T >::~Guard().