Belle II Software light-2406-ragdoll
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.
 
 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;
}
};
Capture stdout and stderr and convert into log messages.
Definition: IOIntercept.h:226
See also
start_intercept for a convenience wrapper for this class

Definition at line 301 of file IOIntercept.h.

Constructor & Destructor Documentation

◆ InterceptorScopeGuard() [1/2]

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.

307 : m_interceptor(&interceptor)
308 {
309 m_interceptor->start();
310 }
T * m_interceptor
pointer to the interceptor we guard
Definition: IOIntercept.h:327

◆ InterceptorScopeGuard() [2/2]

Move constructor which will take over the interception state.

Definition at line 312 of file IOIntercept.h.

312 : m_interceptor(b.m_interceptor)
313 {
314 b.m_interceptor = nullptr;
315 }

◆ ~InterceptorScopeGuard()

~InterceptorScopeGuard ( )
inline

Finish interception on cleanup.

Definition at line 321 of file IOIntercept.h.

322 {
323 if (m_interceptor) m_interceptor->finish();
324 }

Member Data Documentation

◆ m_interceptor

T* m_interceptor
private

pointer to the interceptor we guard

Definition at line 327 of file IOIntercept.h.


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