![]() |
Belle II Software
release-08-02-04
|
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. 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. | |
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.
|
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.