Belle II Software  release-08-01-10
DiscardStream Class Reference

Simple class to just discard anything written to stream by redirecting it to /dev/null. More...

#include <IOIntercept.h>

Inheritance diagram for DiscardStream:
Collaboration diagram for DiscardStream:

Public Member Functions

 DiscardStream (std::ostream &stream, FILE *fileObject)
 Create StreamInterceptor which will redirect to /dev/null.
 
bool start ()
 start intercepting the stream. More...
 
bool finish ()
 stop intercepting the stream. More...
 

Protected Member Functions

void setReplacementFD (int fd)
 set the replacement file descriptor, should be called in the constructor of derived classes
 
bool replaceFD (int fileDescriptor)
 Replace the file descriptor of m_fileObject with the one passed. More...
 

Static Protected Member Functions

static void readFD (int fd, std::string &out)
 Read the contents of a file descriptor until there is no more input and place them in out. More...
 

Protected Attributes

std::ostream & m_stream
 C++ stream object, only needed to flush before replacement.
 
FILE * m_fileObject
 File object of the file we want to replace, needed to obtain file descriptor and to flush.
 
int m_savedFD { -1}
 Saved file descriptor: a duplicate of the file descriptor of m_fileObject.
 
int m_replacementFD { -1}
 Replacement file descriptor to be used while capturing.
 
bool m_capturing {false}
 Check whether we are already capturing.
 

Detailed Description

Simple class to just discard anything written to stream by redirecting it to /dev/null.

Definition at line 88 of file IOIntercept.h.

Member Function Documentation

◆ finish()

bool finish ( )
inlineinherited

stop intercepting the stream.

Returns
true if the object was capturing and stream could be restored

Definition at line 46 of file IOIntercept.h.

◆ readFD()

void readFD ( int  fd,
std::string &  out 
)
staticprotectedinherited

Read the contents of a file descriptor until there is no more input and place them in out.

Parameters
fdfile descriptor to read, should be opened in non blocking mode O_NOBLOCK
outstring to be replaced with all the bytes read from fd

Definition at line 102 of file IOIntercept.cc.

◆ replaceFD()

bool replaceFD ( int  fileDescriptor)
protectedinherited

Replace the file descriptor of m_fileObject with the one passed.

Parameters
fileDescriptorfile descriptor to be set for m_fileObject using dup2()

Definition at line 120 of file IOIntercept.cc.

◆ start()

bool start ( )
inlineinherited

start intercepting the stream.

Returns
true on success, false on any error

Definition at line 38 of file IOIntercept.h.


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