Celeritas 0.7.0-dev.127+develop.e63889793
Loading...
Searching...
No Matches
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.
 
std::stringstream & get ()
 Get the raw stream after flushing the input.
 
 CELER_DELETE_COPY_MOVE (ScopedStreamRedirect)
 

Static Public Member Functions

static bool enabled ()
 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();
Redirect the given stream to an internal stringstream.
Definition ScopedStreamRedirect.hh:35
#define CELER_LOG(LEVEL)
Return a LogMessage object for streaming into at the given level.
Definition corecel/io/Logger.hh:47

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: