OpenMS
Loading...
Searching...
No Matches
SVOutStream Class Reference

Stream class for writing to comma/tab/...-separated values files. More...

#include <OpenMS/FORMAT/SVOutStream.h>

Inheritance diagram for SVOutStream:
[legend]
Collaboration diagram for SVOutStream:
[legend]

Public Member Functions

 SVOutStream (const std::string &file_out, const std::string &sep="\t", const std::string &replacement="_", OpenMS::QuotingMethod quoting=OpenMS::QuotingMethod::DOUBLE)
 Constructor.
 
 SVOutStream (std::ostream &out, const std::string &sep="\t", const std::string &replacement="_", OpenMS::QuotingMethod quoting=OpenMS::QuotingMethod::DOUBLE)
 Constructor.
 
 ~SVOutStream () override
 Destructor.
 
SVOutStreamoperator<< (std::string str)
 Stream output operator for String.
 
SVOutStreamoperator<< (const char *c_str)
 Stream output operator for char*.
 
SVOutStreamoperator<< (const char c)
 Stream output operator for char.
 
SVOutStreamoperator<< (std::ostream &(*fp)(std::ostream &))
 Stream output operator for manipulators (used to catch std::endl)
 
SVOutStreamoperator<< (enum Newline)
 Stream output operator for custom newline (nl) without flushing.
 
template<typename T >
std::enable_if< std::is_arithmetic< typenamestd::remove_reference< T >::type >::value, SVOutStream & >::type operator<< (const T &value)
 
template<typename T >
std::enable_if<!std::is_arithmetic< typenamestd::remove_reference< T >::type >::value, SVOutStream & >::type operator<< (const T &value)
 Generic stream output operator (for non-character-based types)
 
SVOutStreamwrite (const std::string &str)
 Unformatted output (no quoting: useful for comments, but use only on a line of its own!)
 
bool modifyStrings (bool modify)
 Switch modification of strings (quoting/replacing of separators) on/off.
 
template<typename NumericT >
SVOutStreamwriteValueOrNan (NumericT thing)
 Write a numeric value or "nan"/"inf"/"-inf", if applicable (would not be needed for Linux)
 

Protected Attributes

std::ofstream * ofs_
 internal file stream when C'tor is called with a filename
 
std::string sep_
 Separator string.
 
std::string replacement_
 Replacement for separator.
 
std::string nan_
 std::string to use for NaN values
 
std::string inf_
 std::string to use for Inf values
 
OpenMS::QuotingMethod quoting_
 std::string quoting method
 
bool modify_strings_
 On/off switch for modification of strings.
 
bool newline_
 Are we at the beginning of a line? (Otherwise, insert separator before next item.)
 
std::stringstream ss_
 Stream for testing if a manipulator is "std::endl".
 

Detailed Description

Stream class for writing to comma/tab/...-separated values files.

Automatically inserts separators between items and handles quoting of strings. Requires nl (preferred) or std::endl as the line delimiter - "\n" won't be accepted.

Constructor & Destructor Documentation

◆ SVOutStream() [1/2]

SVOutStream ( const std::string &  file_out,
const std::string &  sep = "\t",
const std::string &  replacement = "_",
OpenMS::QuotingMethod  quoting = OpenMS::QuotingMethod::DOUBLE 
)

Constructor.

Parameters
[out]file_outOutput filename; will be overwritten if exists
[in]sepSeparator string (typically comma, semicolon, or tab)
[in]replacementIf quoting is NONE, used to replace occurrences of sep within strings before writing them
[in]quotingQuoting method for strings (see String::quote)

◆ SVOutStream() [2/2]

SVOutStream ( std::ostream &  out,
const std::string &  sep = "\t",
const std::string &  replacement = "_",
OpenMS::QuotingMethod  quoting = OpenMS::QuotingMethod::DOUBLE 
)

Constructor.

Parameters
[out]outOutput stream to write to (open file or cout)
[in]sepSeparator string (typically comma, semicolon, or tab)
[in]replacementIf quoting is NONE, used to replace occurrences of sep within strings before writing them
[in]quotingQuoting method for strings (see String::quote)

◆ ~SVOutStream()

~SVOutStream ( )
override

Destructor.

Frees ofstream_* if filename c'tor was used.

Member Function Documentation

◆ modifyStrings()

bool modifyStrings ( bool  modify)

Switch modification of strings (quoting/replacing of separators) on/off.

Returns
previous modification state

Referenced by NucleicAcidSearchEngine::generateLFQInput_().

◆ operator<<() [1/7]

SVOutStream & operator<< ( const char *  c_str)

Stream output operator for char*.

The argument is quoted before writing; it must not contain the newline character

◆ operator<<() [2/7]

SVOutStream & operator<< ( const char  c)

Stream output operator for char.

The argument is quoted before writing; it must not contain the newline character

◆ operator<<() [3/7]

template<typename T >
std::enable_if< std::is_arithmetic< typenamestd::remove_reference< T >::type >::value, SVOutStream & >::type operator<< ( const T &  value)
inline

numeric types should be converted to std::string first to make use of StringConversion

◆ operator<<() [4/7]

template<typename T >
std::enable_if<!std::is_arithmetic< typenamestd::remove_reference< T >::type >::value, SVOutStream & >::type operator<< ( const T &  value)
inline

Generic stream output operator (for non-character-based types)

◆ operator<<() [5/7]

SVOutStream & operator<< ( enum  Newline)

Stream output operator for custom newline (nl) without flushing.

Use "nl" instead of "endl" for improved performance

◆ operator<<() [6/7]

SVOutStream & operator<< ( std::ostream &(*)(std::ostream &)  fp)

Stream output operator for manipulators (used to catch std::endl)

◆ operator<<() [7/7]

SVOutStream & operator<< ( std::string  str)

Stream output operator for String.

The argument is quoted before writing; it must not contain the newline character

◆ write()

SVOutStream & write ( const std::string &  str)

Unformatted output (no quoting: useful for comments, but use only on a line of its own!)

◆ writeValueOrNan()

template<typename NumericT >
SVOutStream & writeValueOrNan ( NumericT  thing)
inline

Write a numeric value or "nan"/"inf"/"-inf", if applicable (would not be needed for Linux)

References OpenMS::operator<<().

Member Data Documentation

◆ inf_

std::string inf_
protected

std::string to use for Inf values

◆ modify_strings_

bool modify_strings_
protected

On/off switch for modification of strings.

◆ nan_

std::string nan_
protected

std::string to use for NaN values

◆ newline_

bool newline_
protected

Are we at the beginning of a line? (Otherwise, insert separator before next item.)

◆ ofs_

std::ofstream* ofs_
protected

internal file stream when C'tor is called with a filename

◆ quoting_

OpenMS::QuotingMethod quoting_
protected

std::string quoting method

◆ replacement_

std::string replacement_
protected

Replacement for separator.

◆ sep_

std::string sep_
protected

Separator string.

◆ ss_

std::stringstream ss_
protected

Stream for testing if a manipulator is "std::endl".