mlpack
Public Member Functions | Public Attributes | List of all members
mlpack::util::PrefixedOutStream Class Reference

Allows us to output to an ostream with a prefix at the beginning of each line, in the same way we would output to cout or cerr. More...

#include <prefixedoutstream.hpp>

Public Member Functions

 PrefixedOutStream (std::ostream &destination, const char *prefix, bool ignoreInput=false, bool fatal=false, bool backtrace=true)
 Set up the PrefixedOutStream. More...
 
PrefixedOutStreamoperator<< (bool val)
 Write a bool to the stream. More...
 
PrefixedOutStreamoperator<< (short val)
 Write a short to the stream.
 
PrefixedOutStreamoperator<< (unsigned short val)
 Write an unsigned short to the stream.
 
PrefixedOutStreamoperator<< (int val)
 Write an int to the stream.
 
PrefixedOutStreamoperator<< (unsigned int val)
 Write an unsigned int to the stream.
 
PrefixedOutStreamoperator<< (long val)
 Write a long to the stream.
 
PrefixedOutStreamoperator<< (unsigned long val)
 Write an unsigned long to the stream.
 
PrefixedOutStreamoperator<< (float val)
 Write a float to the stream.
 
PrefixedOutStreamoperator<< (double val)
 Write a double to the stream.
 
PrefixedOutStreamoperator<< (long double val)
 Write a long double to the stream.
 
PrefixedOutStreamoperator<< (void *val)
 Write a void pointer to the stream.
 
PrefixedOutStreamoperator<< (const char *str)
 Write a character array to the stream.
 
PrefixedOutStreamoperator<< (std::string &str)
 Write a string to the stream.
 
PrefixedOutStreamoperator<< (std::streambuf *sb)
 Write a streambuf to the stream.
 
PrefixedOutStreamoperator<< (std::ostream &(*pf)(std::ostream &))
 Write an ostream manipulator function to the stream.
 
PrefixedOutStreamoperator<< (std::ios &(*pf)(std::ios &))
 Write an ios manipulator function to the stream.
 
PrefixedOutStreamoperator<< (std::ios_base &(*pf)(std::ios_base &))
 Write an ios_base manipulator function to the stream.
 
template<typename T >
PrefixedOutStreamoperator<< (const T &s)
 Write anything else to the stream.
 

Public Attributes

std::ostream & destination
 The output stream that all data is to be sent to; example: MLPACK_COUT_STREAM. More...
 
bool ignoreInput
 Discards input, prints nothing if true.
 
bool backtrace
 If true, on a fatal error, a backtrace will be printed if HAS_BFD_DL is defined. More...
 

Detailed Description

Allows us to output to an ostream with a prefix at the beginning of each line, in the same way we would output to cout or cerr.

The prefix is specified in the constructor (as well as the destination ostream). A newline must be passed to the stream, and then the prefix will be prepended to the next line. For example,

PrefixedOutStream outstr(MLPACK_COUT_STREAM, "[TEST] ");
outstr << "Hello world I like " << 7.5;
outstr << "...Continue" << std::endl;
outstr << "After the CR\n" << std::endl;

would give, on MLPACK_COUT_STREAM,

[TEST] Hello world I like 7.5...Continue
[TEST] After the CR
[TEST]

These objects are used for the mlpack::Log levels (DEBUG, INFO, WARN, and FATAL).

Constructor & Destructor Documentation

◆ PrefixedOutStream()

mlpack::util::PrefixedOutStream::PrefixedOutStream ( std::ostream &  destination,
const char *  prefix,
bool  ignoreInput = false,
bool  fatal = false,
bool  backtrace = true 
)
inline

Set up the PrefixedOutStream.

Parameters
destinationostream which receives output from this object.
prefixThe prefix to prepend to each line.
ignoreInputIf true, the stream will not be printed.
fatalIf true, a std::runtime_error exception is thrown after printing a newline.
backtraceIf true, attempt to print a backtrace (will only be done if HAS_BFD_DL is defined).

Member Function Documentation

◆ operator<<()

PrefixedOutStream & PrefixedOutStream::operator<< ( bool  val)

Write a bool to the stream.

These are all necessary because gcc's template mechanism does not seem smart enough to figure out what I want to pass into operator<< without these.

That may not be the actual case, but it works when these is here.

Member Data Documentation

◆ backtrace

bool mlpack::util::PrefixedOutStream::backtrace

If true, on a fatal error, a backtrace will be printed if HAS_BFD_DL is defined.

◆ destination

std::ostream& mlpack::util::PrefixedOutStream::destination

The output stream that all data is to be sent to; example: MLPACK_COUT_STREAM.


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