Celeritas 0.7.0-dev.249+develop.4727547b
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.
 
 ScopedStreamRedirect (ScopedStreamRedirect const &)=delete
 
ScopedStreamRedirectoperator= (ScopedStreamRedirect const &)=delete
 
 ScopedStreamRedirect (ScopedStreamRedirect &&)=delete
 
ScopedStreamRedirectoperator= (ScopedStreamRedirect &&)=delete
 

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.

Constructor & Destructor Documentation

◆ ScopedStreamRedirect() [1/2]

celeritas::ScopedStreamRedirect::ScopedStreamRedirect ( ScopedStreamRedirect const )
delete

Prevent copying and moving for RAII class

◆ ScopedStreamRedirect() [2/2]

celeritas::ScopedStreamRedirect::ScopedStreamRedirect ( ScopedStreamRedirect &&  )
delete

Prevent copying and moving for RAII class

Member Function Documentation

◆ get()

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

Get the raw stream after flushing the input.

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

◆ operator=() [1/2]

ScopedStreamRedirect & celeritas::ScopedStreamRedirect::operator= ( ScopedStreamRedirect &&  )
delete

Prevent copying and moving for RAII class

◆ operator=() [2/2]

ScopedStreamRedirect & celeritas::ScopedStreamRedirect::operator= ( ScopedStreamRedirect const )
delete

Prevent copying and moving for RAII class

◆ 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: