Belle II Software development
|
Class to capture anything written to stream into a string. More...
#include <IOIntercept.h>
Public Member Functions | |
CaptureStream (std::ostream &stream, FILE *fileObject) | |
Create a StreamInterceptor which writes into a pipe. | |
~CaptureStream () | |
Close file descriptors. | |
const std::string & | getOutput () const |
Get the output, only set after finish() | |
bool | start () |
Start intercepting the output. | |
bool | finish () |
Restore the stream and get the output from the pipe. | |
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. | |
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. | |
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. | |
Private Attributes | |
int | m_pipeReadFD { -1} |
file descriptor of the read end of the pipe | |
std::string | m_outputStr |
string with the output, only filled after finish() | |
Friends | |
class | CaptureStreamAbortHandler |
allow handling of SIGABRT | |
Class to capture anything written to stream into a string.
Underlying this uses a pipe to buffer the output.
Definition at line 103 of file IOIntercept.h.
CaptureStream | ( | std::ostream & | stream, |
FILE * | fileObject | ||
) |
Create a StreamInterceptor which writes into a pipe.
Definition at line 156 of file IOIntercept.cc.
~CaptureStream | ( | ) |
Close file descriptors.
Definition at line 167 of file IOIntercept.cc.
bool finish | ( | ) |
Restore the stream and get the output from the pipe.
Definition at line 185 of file IOIntercept.cc.
|
inline |
|
staticprotectedinherited |
Read the contents of a file descriptor until there is no more input and place them in out.
fd | file descriptor to read, should be opened in non blocking mode O_NOBLOCK |
out | string to be replaced with all the bytes read from fd |
Definition at line 102 of file IOIntercept.cc.
|
protectedinherited |
Replace the file descriptor of m_fileObject with the one passed.
fileDescriptor | file descriptor to be set for m_fileObject using dup2() |
Definition at line 120 of file IOIntercept.cc.
|
inlineprotectedinherited |
set the replacement file descriptor, should be called in the constructor of derived classes
Definition at line 54 of file IOIntercept.h.
bool start | ( | ) |
Start intercepting the output.
Definition at line 176 of file IOIntercept.cc.
|
friend |
allow handling of SIGABRT
Definition at line 121 of file IOIntercept.h.
|
protectedinherited |
Check whether we are already capturing.
Definition at line 73 of file IOIntercept.h.
|
protectedinherited |
File object of the file we want to replace, needed to obtain file descriptor and to flush.
Definition at line 67 of file IOIntercept.h.
|
private |
string with the output, only filled after finish()
Definition at line 119 of file IOIntercept.h.
|
private |
file descriptor of the read end of the pipe
Definition at line 117 of file IOIntercept.h.
|
protectedinherited |
Replacement file descriptor to be used while capturing.
Definition at line 71 of file IOIntercept.h.
|
protectedinherited |
Saved file descriptor: a duplicate of the file descriptor of m_fileObject.
Definition at line 69 of file IOIntercept.h.
|
protectedinherited |
C++ stream object, only needed to flush before replacement.
Definition at line 65 of file IOIntercept.h.