https://mooseframework.inl.gov
Public Types | Public Member Functions | Private Attributes | Static 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, const bool &predicate, const bool store_pred_as_value=true)
 Constructor taking an FEProblemBase reference, a function to call, and the THREAD_ID argument. More...
 
 SwapBackSentinel (FEProblemBase &fe_problem, SwapBackFunction func, THREAD_ID tid)
 
 ~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
 
const bool & _predicate
 

Static Private Attributes

static constexpr bool _always_true = true
 
static constexpr bool _always_false = false
 

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

Constructor & Destructor Documentation

◆ SwapBackSentinel() [1/2]

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

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

Definition at line 46 of file SwapBackSentinel.h.

51  : _fe_problem(fe_problem),
52  _func(func),
53  _thread_id(tid),
54  _predicate(store_pred_as_value ? (predicate ? _always_true : _always_false) : predicate)
55  {
56  }
static constexpr bool _always_false
const bool & _predicate
FEProblemBase & _fe_problem
static constexpr bool _always_true
SwapBackFunction _func

◆ SwapBackSentinel() [2/2]

SwapBackSentinel::SwapBackSentinel ( FEProblemBase fe_problem,
SwapBackFunction  func,
THREAD_ID  tid 
)
inline

Definition at line 58 of file SwapBackSentinel.h.

59  : _fe_problem(fe_problem), _func(func), _thread_id(tid), _predicate(_always_true)
60  {
61  }
const bool & _predicate
FEProblemBase & _fe_problem
static constexpr bool _always_true
SwapBackFunction _func

◆ ~SwapBackSentinel()

SwapBackSentinel::~SwapBackSentinel ( )
inline

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

Definition at line 66 of file SwapBackSentinel.h.

67  {
68  if (_predicate)
70  }
const bool & _predicate
FEProblemBase & _fe_problem
SwapBackFunction _func

Member Data Documentation

◆ _always_false

constexpr bool SwapBackSentinel::_always_false = false
staticprivate

Definition at line 77 of file SwapBackSentinel.h.

◆ _always_true

constexpr bool SwapBackSentinel::_always_true = true
staticprivate

Definition at line 76 of file SwapBackSentinel.h.

◆ _fe_problem

FEProblemBase& SwapBackSentinel::_fe_problem
private

Definition at line 73 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _func

SwapBackFunction SwapBackSentinel::_func
private

Definition at line 74 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _predicate

const bool& SwapBackSentinel::_predicate
private

Definition at line 78 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().

◆ _thread_id

THREAD_ID SwapBackSentinel::_thread_id
private

Definition at line 75 of file SwapBackSentinel.h.

Referenced by ~SwapBackSentinel().


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