A library for working with phylogenetic and population genetic data.
v0.32.0
BaseOutputTarget Class Referenceabstract

#include <genesis/utils/io/base_output_target.hpp>

Inherited by FileOutputTarget, GzipBlockOutputTarget, GzipOutputTarget, StreamOutputTarget, and StringOutputTarget.

Detailed Description

Abstract base class for writing data to an output target.

The class is an interface that allows writing to different targets, and adds a layer of abstraction around using simple std::ostream functionality. In particular, we want to add some checks, naming of the streams, etc. Internally however, the derived classes of this base class use std::ostream, and make it accessible.

See also
FileOutputTarget, GzipOutputTarget, StreamOutputTarget, StringOutputTarget for our derived output target classes.
to_file(), to_gzip_block_file(), to_stream(), to_string() for helper functions to create these classes, to add some syntactic sugar and make it easy to use.

Definition at line 59 of file base_output_target.hpp.

Public Member Functions

 BaseOutputTarget ()=default
 
 BaseOutputTarget (BaseOutputTarget &&)=default
 
 BaseOutputTarget (BaseOutputTarget const &)=default
 
virtual ~BaseOutputTarget ()
 
std::ostream & flush ()
 Flush output stream buffer. More...
 
template<typename T >
BaseOutputTargetoperator<< (T const &content)
 Output stream operator template that simply forwards to the underlying ostream() object. More...
 
BaseOutputTargetoperator= (BaseOutputTarget &&)=default
 
BaseOutputTargetoperator= (BaseOutputTarget const &)=default
 
std::ostream & ostream ()
 Get the underlying output stream that is used for writing. More...
 
std::string target_name () const
 Get a name of the output target. This is intended for user output. More...
 
std::string target_string () const
 Get a string representing the output target. More...
 

Constructor & Destructor Documentation

◆ BaseOutputTarget() [1/3]

BaseOutputTarget ( )
default

◆ BaseOutputTarget() [2/3]

BaseOutputTarget ( BaseOutputTarget const &  )
default

◆ BaseOutputTarget() [3/3]

◆ ~BaseOutputTarget()

virtual ~BaseOutputTarget ( )
inlinevirtual

Definition at line 75 of file base_output_target.hpp.

Member Function Documentation

◆ flush()

std::ostream& flush ( )
inline

Flush output stream buffer.

Internally, the different output target derived classes use some variant of std::ostream to do the writing. Hence, the target might need flushing in cases where we want to synchronize it while writing, before closing the stream.

Definition at line 117 of file base_output_target.hpp.

◆ operator<<()

BaseOutputTarget& operator<< ( T const &  content)
inline

Output stream operator template that simply forwards to the underlying ostream() object.

This is the main function used to write output. This way, nothing has to be changed in code that wants to write some output, comared to standard write-to-stream functions. The only change necessary is the initial setup of the output object: Instead of an std::ostream, one has to initialize this class. From then on, usage is identical.

Alternatively, the ostream() function can be used to obtain the underlying stream that is internally used to write the data. Also, see flush() to synchronize the writing with the actual target of the stream.

Definition at line 95 of file base_output_target.hpp.

◆ operator=() [1/2]

BaseOutputTarget& operator= ( BaseOutputTarget &&  )
default

◆ operator=() [2/2]

BaseOutputTarget& operator= ( BaseOutputTarget const &  )
default

◆ ostream()

std::ostream& ostream ( )
inline

Get the underlying output stream that is used for writing.

Definition at line 104 of file base_output_target.hpp.

◆ target_name()

std::string target_name ( ) const
inline

Get a name of the output target. This is intended for user output.

This will for example return something like "output file (/path/to/file.txt)", so that users know what type of output stream it is, and where it streams to.

Definition at line 128 of file base_output_target.hpp.

◆ target_string()

std::string target_string ( ) const
inline

Get a string representing the output target.

This is intended for the writer classes, which for example might want to examine the output file name. Hence, this function is meant to return just the file path (for a file target).

Definition at line 140 of file base_output_target.hpp.


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