EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Lock< T > Class Template Reference

A lock for a Lockable object. More...

#include "Lock.h"

Public Member Functions

 Lock (T &object, bool lock=true)
 Primary contructor, locks the object. More...
 
 ~Lock ()
 Destructor, unlocks the object. More...
 
bool isLocked () const
 Obtains the lock state of the object. More...
 
void Relock ()
 Locks the object. More...
 
void Unlock ()
 Unlocks the object. More...
 

Protected Attributes

T & mObject
 The object this lock is bound to. More...
 
bool mLocked
 True the mObject is locked, false if not. More...
 

Detailed Description

template<typename T>
class Lock< T >

A lock for a Lockable object.

The object is locked during contruction and unlocked during destruction.

The passed typename should be a child of the class Lockable.

Author
Bloody.Rabbit

Definition at line 70 of file Lock.h.

Constructor & Destructor Documentation

template<typename T >
Lock< T >::Lock ( T &  object,
bool  lock = true 
)
inline

Primary contructor, locks the object.

Parameters
[in]objectObject to bound this lock to.
[in]lockLock the object during construction.

Definition at line 79 of file Lock.h.

References Lock< T >::Relock().

80  : mObject( object ),
81  mLocked( false )
82  {
83  if( lock )
84  Relock();
85  }
void Relock()
Locks the object.
Definition: Lock.h:105
T & mObject
The object this lock is bound to.
Definition: Lock.h:125
bool mLocked
True the mObject is locked, false if not.
Definition: Lock.h:127

Here is the call graph for this function:

template<typename T >
Lock< T >::~Lock ( )
inline

Destructor, unlocks the object.

Definition at line 89 of file Lock.h.

References Lock< T >::Unlock().

90  {
91  Unlock();
92  }
void Unlock()
Unlocks the object.
Definition: Lock.h:115

Here is the call graph for this function:

Member Function Documentation

template<typename T >
bool Lock< T >::isLocked ( ) const
inline

Obtains the lock state of the object.

Return values
trueThe object is locked.
falseThe object is not locked.

Definition at line 100 of file Lock.h.

References Lock< T >::mLocked.

Referenced by Lock< T >::Relock(), and Lock< T >::Unlock().

100 { return mLocked; }
bool mLocked
True the mObject is locked, false if not.
Definition: Lock.h:127

Here is the caller graph for this function:

template<typename T >
void Lock< T >::Relock ( )
inline

Locks the object.

Definition at line 105 of file Lock.h.

References Lock< T >::isLocked(), Lock< T >::mLocked, and Lock< T >::mObject.

Referenced by Lock< T >::Lock().

106  {
107  if( !isLocked() )
108  mObject.Lock();
109 
110  mLocked = true;
111  }
T & mObject
The object this lock is bound to.
Definition: Lock.h:125
bool mLocked
True the mObject is locked, false if not.
Definition: Lock.h:127
bool isLocked() const
Obtains the lock state of the object.
Definition: Lock.h:100

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
void Lock< T >::Unlock ( )
inline

Unlocks the object.

Definition at line 115 of file Lock.h.

References Lock< T >::isLocked(), Lock< T >::mLocked, and Lock< T >::mObject.

Referenced by log_messageVA(), and Lock< T >::~Lock().

116  {
117  if( isLocked() )
118  mObject.Unlock();
119 
120  mLocked = false;
121  }
T & mObject
The object this lock is bound to.
Definition: Lock.h:125
bool mLocked
True the mObject is locked, false if not.
Definition: Lock.h:127
bool isLocked() const
Obtains the lock state of the object.
Definition: Lock.h:100

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

template<typename T >
bool Lock< T >::mLocked
protected

True the mObject is locked, false if not.

Definition at line 127 of file Lock.h.

Referenced by Lock< T >::isLocked(), Lock< T >::Relock(), and Lock< T >::Unlock().

template<typename T >
T& Lock< T >::mObject
protected

The object this lock is bound to.

Definition at line 125 of file Lock.h.

Referenced by Lock< T >::Relock(), and Lock< T >::Unlock().


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