Belle II Software  release-08-01-10
InterceptorScopeGuard< T > Class Template Reference

Simple RAII guard for output interceptor. More...

#include <IOIntercept.h>

Public Member Functions

 InterceptorScopeGuard (T &interceptor)
 Construct a new instance for a given interceptor object and start intercepting io. More...
 
 InterceptorScopeGuard (InterceptorScopeGuard< T > &&b)
 Move constructor which will take over the interception state.
 
 InterceptorScopeGuard (const InterceptorScopeGuard< T > &)=delete
 We don't want copying.
 
InterceptorScopeGuardoperator= (const InterceptorScopeGuard &)=delete
 Also no assignment.
 
 ~InterceptorScopeGuard ()
 Finish interception on cleanup.
 

Private Attributes

T * m_interceptor
 pointer to the interceptor we guard
 

Detailed Description

template<class T>
class Belle2::IOIntercept::InterceptorScopeGuard< T >

Simple RAII guard for output interceptor.

In case you have one of the IOIntercept classes as member and want to enable it in a function with multiple return paths this class makes sure that the interceptor is properly finished on exiting the function/scope.

struct example {
IOIntercept::OutputToLogMessages m_interceptor{"examplestruct"};
int sign(int number) {
// this starts interception which will last until the
// InterceptorGuard is destructed so no matter which return is taken
// the intercept will always be properly finished()
IOIntercept::InteceptorGuard<IOIntercept::OutputToLogMessages> guard(m_interceptor);
if(number<0) {
return -1;
} else if(number>0) {
return 1;
}
return 0;
}
};
T * m_interceptor
pointer to the interceptor we guard
Definition: IOIntercept.h:327
See also
start_intercept for a convenience wrapper for this class

Definition at line 301 of file IOIntercept.h.

Constructor & Destructor Documentation

◆ InterceptorScopeGuard()

InterceptorScopeGuard ( T &  interceptor)
inlineexplicit

Construct a new instance for a given interceptor object and start intercepting io.

Parameters
interceptorthe interceptor object to use, must stay valid during the lifetime of this object.

Definition at line 307 of file IOIntercept.h.


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