Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::IFileOutputRedirector Class Referenceabstract

#include <gromacs/utility/fileredirector.h>

+ Inheritance diagram for gmx::IFileOutputRedirector:

Description

Allows capturing stdout and file output from code that supports it.

The calling code should take in this interface and use the stream objects it returns for all output that needs to support this redirection.

Currently, the (nearly) only purpose for this interface is for unit tests to capture the file output without duplicating the knowledge of which files are actually produced. The tests can also replace actual files with in-memory streams (e.g., a StringOutputStream), and test the output without actually accessing the file system and managing actual files.

As the main user for non-default implementation of this interface is tests, code using this interface generally uses a pattern where the redirector is initialized to defaultFileOutputRedirector(), and a separate setter is provided for tests to change the default. This allows code outside the tests (and outside the code actually calling the redirector) to be written as if this interface did not exist (i.e., they do not need to pass the default instance).

Also, the interface only supports text files, but can be generalized if/when there is a need for binary streams (see also TextOutputStream).

Public Member Functions

virtual TextOutputStreamstandardOutput ()=0
 Returns a stream to use for stdout output.
 
virtual TextOutputStreamPointer openTextOutputFile (const char *filename)=0
 Returns a stream to use for output to a file at a given path. More...
 
TextOutputStreamPointer openTextOutputFile (const std::string &filename)
 Convenience method to open a stream using an std::string path.
 

Member Function Documentation

virtual TextOutputStreamPointer gmx::IFileOutputRedirector::openTextOutputFile ( const char *  filename)
pure virtual

Returns a stream to use for output to a file at a given path.

Parameters
[in]filenameRequested file name.

Implemented in gmx::test::TestFileOutputRedirector.


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