RobWorkProject  23.9.11-
Public Member Functions | Static Public Attributes | List of all members
synced_stream Class Reference

A helper class to synchronize printing to an output stream by different threads. More...

#include <BS_thread_pool.hpp>

Public Member Functions

 synced_stream (std::ostream &out_stream_=std::cout)
 Construct a new synced stream. More...
 
template<typename... T>
void print (T &&... items)
 Print any number of items into the output stream. Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use the same synced_stream object to print. More...
 
template<typename... T>
void println (T &&... items)
 Print any number of items into the output stream, followed by a newline character. Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use the same synced_stream object to print. More...
 

Static Public Attributes

static std::ostream &(&) endl (std::ostream &) = static_cast<std::ostream& (&)(std::ostream&)>(std::endl)
 A stream manipulator to pass to a synced_stream (an explicit cast of std::endl). Prints a newline character to the stream, and then flushes it. Should only be used if flushing is desired, otherwise '
' should be used instead.
 
static std::ostream &(&) flush (std::ostream &) = static_cast<std::ostream& (&)(std::ostream&)>(std::flush)
 A stream manipulator to pass to a synced_stream (an explicit cast of std::flush). Used to flush the stream.
 

Detailed Description

A helper class to synchronize printing to an output stream by different threads.

Constructor & Destructor Documentation

◆ synced_stream()

synced_stream ( std::ostream &  out_stream_ = std::cout)
inline

Construct a new synced stream.

Parameters
out_stream_The output stream to print to. The default value is std::cout.

Member Function Documentation

◆ print()

void print ( T &&...  items)
inline

Print any number of items into the output stream. Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use the same synced_stream object to print.

Template Parameters
TThe types of the items
Parameters
itemsThe items to print.

◆ println()

void println ( T &&...  items)
inline

Print any number of items into the output stream, followed by a newline character. Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use the same synced_stream object to print.

Template Parameters
TThe types of the items
Parameters
itemsThe items to print.

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