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 33 of file SwapBackSentinel.h.

Member Typedef Documentation

◆ SwapBackFunction

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 41 of file SwapBackSentinel.h.

Constructor & Destructor Documentation

◆ SwapBackSentinel()

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 47 of file SwapBackSentinel.h.

51  : _fe_problem(fe_problem), _func(func), _thread_id(tid), _predicate(predicate)
52  {
53  }
FEProblemBase & _fe_problem
SwapBackFunction _func

◆ ~SwapBackSentinel()

SwapBackSentinel::~SwapBackSentinel ( )
inline

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

Definition at line 58 of file SwapBackSentinel.h.

59  {
60  if (_predicate)
62  }
FEProblemBase & _fe_problem
SwapBackFunction _func

Member Data Documentation

◆ _fe_problem

FEProblemBase& SwapBackSentinel::_fe_problem
private

Definition at line 65 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _func

SwapBackFunction SwapBackSentinel::_func
private

Definition at line 66 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _predicate

bool SwapBackSentinel::_predicate
private

Definition at line 68 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _thread_id

THREAD_ID SwapBackSentinel::_thread_id
private

Definition at line 67 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().


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