rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

Scope Guard
[Essential Tools Module]


Module Description

Classes and functions in this group provide an implementation of the Resource Acquisition Is Initialization (RAII) programming idiom. This idiom is useful for writing exception-safe code. It relies on guarantees provided by the C++ language to perform an action when control flow leaves the current scope.

Classes

class  RWScopeGuardImp
 Base class for derived RWScopeGuardImp classes. More...
class  RWScopeGuard0GImp< Fun >
 Derived RWScopeGuardImp for global or static member functions that take 0 parameters. More...
class  RWScopeGuard1GImp< Fun, P1 >
 Derived RWScopeGuardImp for global or static member functions that take 1 parameter. More...
class  RWScopeGuard2GImp< Fun, P1, P2 >
 Derived RWScopeGuardImp for global or static member functions that take 2 parameters. More...
class  RWScopeGuard3GImp< Fun, P1, P2, P3 >
 Derived RWScopeGuardImp for global or static member functions that take 3 parameters. More...
class  RWScopeGuard4GImp< Fun, P1, P2, P3, P4 >
 Derived RWScopeGuardImp for global or static member functions that take 4 parameters. More...
class  RWScopeGuard5GImp< Fun, P1, P2, P3, P4, P5 >
 Derived RWScopeGuardImp for global or static member functions that take 5 parameters. More...
class  RWScopeGuard0MImp< Obj, Fun >
 Derived RWScopeGuardImp for member functions that take 0 parameters. More...
class  RWScopeGuard1MImp< Obj, Fun, P1 >
 Derived RWScopeGuardImp for member functions that take 1 parameter. More...
class  RWScopeGuard2MImp< Obj, Fun, P1, P2 >
 Derived RWScopeGuardImp for member functions that take 2 parameters. More...
class  RWScopeGuard3MImp< Obj, Fun, P1, P2, P3 >
 Derived RWScopeGuardImp for member functions that take 3 parameters. More...
class  RWScopeGuard4MImp< Obj, Fun, P1, P2, P3, P4 >
 Derived RWScopeGuardImp for member functions that take 4 parameters. More...
class  RWScopeGuard5MImp< Obj, Fun, P1, P2, P3, P4, P5 >
 Derived RWScopeGuardImp for member functions that take 5 parameters. More...
class  RWTRefHolder< T >
 Helper class for storing a reference to an object by value. More...

Modules

 rwtMakeScopeGuard Functions

Typedefs

typedef const RWScopeGuardImpRWScopeGuard

Functions

template<class T >
RWTRefHolder< T > rwtMakeRef (T &t)

Typedef Documentation

typedef const RWScopeGuardImp& RWScopeGuard

RWScopeGuard encapsulates a function to invoke and a set of parameters to pass to that function on exit from the current local scope. It can handle functions that take up to five parameters, and those parameters can be of any type.

Examples

 FILE* f = fopen("file.txt", "w+");

 // close the file automatically on exit from scope
 RWScopeGuard sg = rwtMakeScopeGuardG(fclose, f);

 // some operation that might throw
 potentially_dangerous_call();

If the action to be performed by the scope guard is no longer necessary, it may be canceled.

 // prevent the action from being performed
 sg.dismiss();

Function Documentation

template<class T >
RWTRefHolder<T> rwtMakeRef ( T &  t  )  [inline]

Creates an instance of a reference wrapper object RWTRefHolder.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.