ensmallen
mlpack
fast, flexible C++ machine learning library
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...

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. More...

 
PrefixedOutStreamoperator<< (unsigned short val)
 Write an unsigned short to the stream. More...

 
PrefixedOutStreamoperator<< (int val)
 Write an int to the stream. More...

 
PrefixedOutStreamoperator<< (unsigned int val)
 Write an unsigned int to the stream. More...

 
PrefixedOutStreamoperator<< (long val)
 Write a long to the stream. More...

 
PrefixedOutStreamoperator<< (unsigned long val)
 Write an unsigned long to the stream. More...

 
PrefixedOutStreamoperator<< (float val)
 Write a float to the stream. More...

 
PrefixedOutStreamoperator<< (double val)
 Write a double to the stream. More...

 
PrefixedOutStreamoperator<< (long double val)
 Write a long double to the stream. More...

 
PrefixedOutStreamoperator<< (void *val)
 Write a void pointer to the stream. More...

 
PrefixedOutStreamoperator<< (const char *str)
 Write a character array to the stream. More...

 
PrefixedOutStreamoperator<< (std::string &str)
 Write a string to the stream. More...

 
PrefixedOutStreamoperator<< (std::streambuf *sb)
 Write a streambuf to the stream. More...

 
PrefixedOutStreamoperator<< (std::ostream &(*pf)(std::ostream &))
 Write an ostream manipulator function to the stream. More...

 
PrefixedOutStreamoperator<< (std::ios &(*pf)(std::ios &))
 Write an ios manipulator function to the stream. More...

 
PrefixedOutStreamoperator<< (std::ios_base &(*pf)(std::ios_base &))
 Write an ios_base manipulator function to the stream. More...

 
template
<
typename
T
>
PrefixedOutStreamoperator<< (const T &s)
 Write anything else to the stream. More...

 

Public Attributes

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

 
std::ostream & destination
 The output stream that all data is to be sent to; example: std::cout. More...

 
bool ignoreInput
 Discards input, prints nothing if true. 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(std::cout, "[TEST] ");
outstr << "Hello world I like " << 7.5;
outstr << "...Continue" << std::endl;
outstr << "After the CR\n" << std::endl;

would give, on std::cout,

[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).

Definition at line 46 of file prefixedoutstream.hpp.

Constructor & Destructor Documentation

◆ 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).

Definition at line 60 of file prefixedoutstream.hpp.

References PrefixedOutStream::operator<<().

Member Function Documentation

◆ operator<<() [1/18]

PrefixedOutStream& operator<< ( bool  val)

Write a bool to the stream.

Referenced by PrefixedOutStream::PrefixedOutStream().

◆ operator<<() [2/18]

PrefixedOutStream& operator<< ( short  val)

Write a short to the stream.

◆ operator<<() [3/18]

PrefixedOutStream& operator<< ( unsigned short  val)

Write an unsigned short to the stream.

◆ operator<<() [4/18]

PrefixedOutStream& operator<< ( int  val)

Write an int to the stream.

◆ operator<<() [5/18]

PrefixedOutStream& operator<< ( unsigned int  val)

Write an unsigned int to the stream.

◆ operator<<() [6/18]

PrefixedOutStream& operator<< ( long  val)

Write a long to the stream.

◆ operator<<() [7/18]

PrefixedOutStream& operator<< ( unsigned long  val)

Write an unsigned long to the stream.

◆ operator<<() [8/18]

PrefixedOutStream& operator<< ( float  val)

Write a float to the stream.

◆ operator<<() [9/18]

PrefixedOutStream& operator<< ( double  val)

Write a double to the stream.

◆ operator<<() [10/18]

PrefixedOutStream& operator<< ( long double  val)

Write a long double to the stream.

◆ operator<<() [11/18]

PrefixedOutStream& operator<< ( void *  val)

Write a void pointer to the stream.

◆ operator<<() [12/18]

PrefixedOutStream& operator<< ( const char *  str)

Write a character array to the stream.

◆ operator<<() [13/18]

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

Write a string to the stream.

◆ operator<<() [14/18]

PrefixedOutStream& operator<< ( std::streambuf *  sb)

Write a streambuf to the stream.

◆ operator<<() [15/18]

PrefixedOutStream& operator<< ( std::ostream &(*)(std::ostream &)  pf)

Write an ostream manipulator function to the stream.

◆ operator<<() [16/18]

PrefixedOutStream& operator<< ( std::ios &(*)(std::ios &)  pf)

Write an ios manipulator function to the stream.

◆ operator<<() [17/18]

PrefixedOutStream& operator<< ( std::ios_base &(*)(std::ios_base &)  pf)

Write an ios_base manipulator function to the stream.

◆ operator<<() [18/18]

PrefixedOutStream& operator<< ( const T &  s)

Write anything else to the stream.

Member Data Documentation

◆ backtrace

bool backtrace

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

Definition at line 122 of file prefixedoutstream.hpp.

Referenced by mlpack::util::DisableBacktrace().

◆ destination

std::ostream& destination

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

Definition at line 115 of file prefixedoutstream.hpp.

◆ ignoreInput

bool ignoreInput

Discards input, prints nothing if true.

Definition at line 118 of file prefixedoutstream.hpp.

Referenced by mlpack::util::DisableVerbose(), mlpack::util::EnableVerbose(), and mlpack::bindings::cli::ParseCommandLine().


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