SYNOPSIS

Public Member Functions

PrefixedOutStream (std::ostream &destination, const char *prefix, bool ignoreInput=false, bool fatal=false)

Set up the PrefixedOutStream. PrefixedOutStream & operator<< (bool val)

Write a bool to the stream. PrefixedOutStream & operator<< (short val)

Write a short to the stream. PrefixedOutStream & operator<< (unsigned short val)

Write an unsigned short to the stream. PrefixedOutStream & operator<< (int val)

Write an int to the stream. PrefixedOutStream & operator<< (unsigned int val)

Write an unsigned int to the stream. PrefixedOutStream & operator<< (long val)

Write a long to the stream. PrefixedOutStream & operator<< (unsigned long val)

Write an unsigned long to the stream. PrefixedOutStream & operator<< (float val)

Write a float to the stream. PrefixedOutStream & operator<< (double val)

Write a double to the stream. PrefixedOutStream & operator<< (long double val)

Write a long double to the stream. PrefixedOutStream & operator<< (void *val)

Write a void pointer to the stream. PrefixedOutStream & operator<< (const char *str)

Write a character array to the stream. PrefixedOutStream & operator<< (std::string &str)

Write a string to the stream. PrefixedOutStream & operator<< (std::streambuf *sb)

Write a streambuf to the stream. PrefixedOutStream & operator<< (std::ostream &(*pf)(std::ostream &))

Write an ostream manipulator function to the stream. PrefixedOutStream & operator<< (std::ios &(*pf)(std::ios &))

Write an ios manipulator function to the stream. PrefixedOutStream & operator<< (std::ios_base &(*pf)(std::ios_base &))

Write an ios_base manipulator function to the stream. template<typename T > PrefixedOutStream & operator<< (const T &s)

Write anything else to the stream.

Public Attributes

std::ostream & destination

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

Discards input, prints nothing if true.

Private Member Functions

template<typename T > void BaseLogic (const T &val)

Conducts the base logic required in all the operator << overloads. template<typename T > void CallBaseLogic (const T &s, typename boost::disable_if< boost::is_class< T > >::type *=0)

This handles forwarding all primitive types transparently. template<typename T > void CallBaseLogic (const T &s, typename boost::enable_if< boost::is_class< T > >::type *=0, typename boost::disable_if< HasToString< T, std::string(T::*)() const > >::type *=0)

Forward all objects that do not implement a ToString() method. template<typename T > void CallBaseLogic (const T &s, typename boost::enable_if< boost::is_class< T > >::type *=0, typename boost::enable_if< HasToString< T, std::string(T::*)() const > >::type *=0)

Call ToString() on all objects that implement ToString() before forwarding. void PrefixIfNeeded ()

Output the prefix, but only if we need to and if we are allowed to.

Private Attributes

bool carriageReturned

If true, the previous call to operator<< encountered a CR, and a prefix will be necessary. bool fatal

If true, the application will terminate with an error code when a CR is encountered. std::string prefix

Contains the prefix we must prepend to each line.

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 66 of file prefixedoutstream.hpp.

Constructor & Destructor Documentation

mlpack::util::PrefixedOutStream::PrefixedOutStream (std::ostream &destination, const char *prefix, boolignoreInput = \fCfalse\fP, boolfatal = \fCfalse\fP)\fC [inline]\fP

Set up the PrefixedOutStream.

Parameters:

destination ostream which receives output from this object.

prefix The prefix to prepend to each line.

Definition at line 75 of file prefixedoutstream.hpp.

Member Function Documentation

template<typename T > void mlpack::util::PrefixedOutStream::BaseLogic (const T &val)\fC [private]\fP

Conducts the base logic required in all the operator << overloads. Mostly just a good idea to reduce copy-pasta.

Template Parameters:

T The type of the data to output.

Parameters:

val The The data to be output.

template<typename T > void mlpack::util::PrefixedOutStream::CallBaseLogic (const T &s, typename boost::disable_if< boost::is_class< T > >::type * = \fC0\fP)\fC [private]\fP

This handles forwarding all primitive types transparently.

template<typename T > void mlpack::util::PrefixedOutStream::CallBaseLogic (const T &s, typename boost::enable_if< boost::is_class< T > >::type * = \fC0\fP, typename boost::disable_if< HasToString< T, std::string(T::*)() const > >::type * = \fC0\fP)\fC [private]\fP

Forward all objects that do not implement a ToString() method.

template<typename T > void mlpack::util::PrefixedOutStream::CallBaseLogic (const T &s, typename boost::enable_if< boost::is_class< T > >::type * = \fC0\fP, typename boost::enable_if< HasToString< T, std::string(T::*)() const > >::type * = \fC0\fP)\fC [private]\fP

Call ToString() on all objects that implement ToString() before forwarding.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (boolval)

Write a bool to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (shortval)

Write a short to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (unsigned shortval)

Write an unsigned short to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (intval)

Write an int to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (unsigned intval)

Write an unsigned int to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (longval)

Write a long to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (unsigned longval)

Write an unsigned long to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (floatval)

Write a float to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (doubleval)

Write a double to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (long doubleval)

Write a long double to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (void *val)

Write a void pointer to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (const char *str)

Write a character array to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (std::string &str)

Write a string to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (std::streambuf *sb)

Write a streambuf to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (std::ostream &(*)(std::ostream &)pf)

Write an ostream manipulator function to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (std::ios &(*)(std::ios &)pf)

Write an ios manipulator function to the stream.

\fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (std::ios_base &(*)(std::ios_base &)pf)

Write an ios_base manipulator function to the stream.

template<typename T > \fBPrefixedOutStream\fP& mlpack::util::PrefixedOutStream::operator<< (const T &s)

Write anything else to the stream.

void mlpack::util::PrefixedOutStream::PrefixIfNeeded ()\fC [inline]\fP, \fC [private]\fP

Output the prefix, but only if we need to and if we are allowed to.

Member Data Documentation

bool mlpack::util::PrefixedOutStream::carriageReturned\fC [private]\fP

If true, the previous call to operator<< encountered a CR, and a prefix will be necessary.

Definition at line 183 of file prefixedoutstream.hpp.

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

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

Definition at line 128 of file prefixedoutstream.hpp.

bool mlpack::util::PrefixedOutStream::fatal\fC [private]\fP

If true, the application will terminate with an error code when a CR is encountered.

Definition at line 187 of file prefixedoutstream.hpp.

bool mlpack::util::PrefixedOutStream::ignoreInput

Discards input, prints nothing if true.

Definition at line 131 of file prefixedoutstream.hpp.

std::string mlpack::util::PrefixedOutStream::prefix\fC [private]\fP

Contains the prefix we must prepend to each line.

Definition at line 179 of file prefixedoutstream.hpp.

Author

Generated automatically by Doxygen for MLPACK from the source code.