Celeritas  0.5.0-86+4a8eea4
Public Member Functions | Static Public Member Functions | List of all members
celeritas::ScopedStreamRedirect Class Reference

Redirect the given stream to an internal stringstream. More...

#include <ScopedStreamRedirect.hh>

Public Member Functions

 ScopedStreamRedirect (std::ostream *os)
 Construct with pointer to a stream such as cout.
 
 ~ScopedStreamRedirect ()
 Restore stream on destruction.
 
std::string str ()
 Get redirected output with trailing whitespaces removed. More...
 
std::stringstream & get ()
 Get the raw stream after flushing the input. More...
 
 CELER_DELETE_COPY_MOVE (ScopedStreamRedirect)
 

Static Public Member Functions

static bool allow_redirect ()
 Whether signal handling is enabled.
 

Detailed Description

Redirect the given stream to an internal stringstream.

This is primarily for interfacing with poorly-behaved external libraries that write to cout/cerr by default.

ScopedStreamRedirect silenced(&std::cout);
LoadVecGeom();
CELER_LOG(diagnostic) << "Vecgeom said: " << silenced.str();
ScopedStreamRedirect(std::ostream *os)
Construct with pointer to a stream such as cout.
Definition: ScopedStreamRedirect.cc:41
#define CELER_LOG(LEVEL)
Return a LogMessage object for streaming into at the given level.
Definition: corecel/io/Logger.hh:48

The environment variable CELER_DISABLE_REDIRECT will prevent stream redirection, which might be needed if the code segfaults/aborts before this class's destructor is reached.

Member Function Documentation

◆ CELER_DELETE_COPY_MOVE()

celeritas::ScopedStreamRedirect::CELER_DELETE_COPY_MOVE ( ScopedStreamRedirect  )

Prevent copying and moving for RAII class

◆ get()

std::stringstream & celeritas::ScopedStreamRedirect::get ( )

Get the raw stream after flushing the input.

If redirection is disabled, this will be an empty stream.

◆ str()

std::string celeritas::ScopedStreamRedirect::str ( )

Get redirected output with trailing whitespaces removed.

If redirection is disabled, this will be an empty string.


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