AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
Public Member Functions | List of all members
drama::ScopeGuard< T > Class Template Reference

Detailed Description

template<typename T>
class drama::ScopeGuard< T >

This class implements a simple scope guard class.

It will allow an item to be set to a particular value from construction and then reset when destroyed.

This class is similar to many C++ scope guard cases (e.g. std::unique_ptr) but intended for simple cases where say a value of a class is to be set from the construction point onwards and then reset when the destructor is run.

Warning
Is not thread safe! While this ScopeGuard item would normally only be constructed and destroyed in the one thread, nothing prevents another thread reading the guarded value while the thread containing the ScopeGuard is being constructed or destroyed (when the underlying guarded value may be being changed.) The ScopeGuardAtomic class could be used in those cases.

#include "util.hh"

Public Member Functions

 ScopeGuard (T &item, const T executionVal)
 Construct a ScopeGuard for the specified item.
 
 ScopeGuard (T &item, const T executionVal, const T exitVal)
 Construct a ScopeGuard for the specified item.
 
 ~ScopeGuard ()
 Destroy the ScopeGuard item, restoring its value to the specified exit value.
 

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