B2BITS FIX Antenna HFT  1.0.16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
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>

Public Member Functions

 Guard (T &lock, bool lockNow)
 Constructor. More...
 
 Guard (T &lock)
 
void release ()
 Releases the resource. More...
 
void setIsLocked ()
 
 ~Guard ()
 Destructor. More...
 

Protected Member Functions

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

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.

Constructor & Destructor Documentation

template<class T >
Utils::Guard< T >::Guard ( T &  lock,
bool  lockNow 
)
inline

Constructor.

Acquires the given resource.

Parameters
lockResource monitor implementation
template<class T >
Utils::Guard< T >::Guard ( T &  lock)
inline
template<class T >
Utils::Guard< T >::~Guard ( )
inline

Destructor.

Releases the given resource.

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.

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

template<class T >
void Utils::Guard< T >::setIsLocked ( )
inline