www.mooseframework.org
Public Types | Public Member Functions | Private Attributes | List of all members
SwapBackSentinel Class Reference

The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,Neighbor}() is called even when an exception is thrown from FEProblemBase::reinitMaterials{Face,Neighbor}. More...

#include <SwapBackSentinel.h>

Public Types

using SwapBackFunction = void(FEProblemBase::*)(THREAD_ID)
 SwapBackFunction is a typedef for a pointer to an FEProblemBase member function taking a THREAD_ID and returning void. More...
 

Public Member Functions

 SwapBackSentinel (FEProblemBase &fe_problem, SwapBackFunction func, THREAD_ID tid, bool predicate=true)
 Constructor taking an FEProblemBase reference, a function to call, and the THREAD_ID argument. More...
 
 ~SwapBackSentinel ()
 The destructor calls swap back function only if the predicate is true. More...
 

Private Attributes

FEProblemBase_fe_problem
 
SwapBackFunction _func
 
THREAD_ID _thread_id
 
bool _predicate
 

Detailed Description

The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,Neighbor}() is called even when an exception is thrown from FEProblemBase::reinitMaterials{Face,Neighbor}.

This is because stack unwinding (for caught exceptions) guarantees that object destructors are called. The typical way of using this object is to construct it in the same scope where reinitMaterials is called:

{ SwapBackSentinel sentinel(_fe_problem, &FEProblemBase::swapBackMaterials, _tid); _fe_problem.reinitMaterials(_subdomain, _tid); }

Definition at line 38 of file SwapBackSentinel.h.

Member Typedef Documentation

using SwapBackSentinel::SwapBackFunction = void (FEProblemBase::*)(THREAD_ID)

SwapBackFunction is a typedef for a pointer to an FEProblemBase member function taking a THREAD_ID and returning void.

All the FEProblemBase::swapBackMaterialXXX() members have this signature.

Definition at line 46 of file SwapBackSentinel.h.

Constructor & Destructor Documentation

SwapBackSentinel::SwapBackSentinel ( FEProblemBase fe_problem,
SwapBackFunction  func,
THREAD_ID  tid,
bool  predicate = true 
)
inline

Constructor taking an FEProblemBase reference, a function to call, and the THREAD_ID argument.

Definition at line 52 of file SwapBackSentinel.h.

56  : _fe_problem(fe_problem), _func(func), _thread_id(tid), _predicate(predicate)
57  {
58  }
FEProblemBase & _fe_problem
SwapBackFunction _func
SwapBackSentinel::~SwapBackSentinel ( )
inline

The destructor calls swap back function only if the predicate is true.

Definition at line 63 of file SwapBackSentinel.h.

64  {
65  if (_predicate)
67  }
FEProblemBase & _fe_problem
SwapBackFunction _func

Member Data Documentation

FEProblemBase& SwapBackSentinel::_fe_problem
private

Definition at line 70 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

SwapBackFunction SwapBackSentinel::_func
private

Definition at line 71 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

bool SwapBackSentinel::_predicate
private

Definition at line 73 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

THREAD_ID SwapBackSentinel::_thread_id
private

Definition at line 72 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().


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