A utility class to synchronize printing to one or more output streams by different threads.
More...
#include <BS_thread_pool.hpp>
|
| | synced_stream () |
| | Construct a new synced stream which prints to std::cout.
|
| |
| template<typename... T> |
| | synced_stream (T &... streams) |
| | Construct a new synced stream which prints to the given output stream(s).
|
| |
| void | add_stream (std::ostream &stream) |
| | Add a stream to the list of output streams to print to.
|
| |
| std::vector< std::ostream * > & | get_streams () noexcept |
| | Get a reference to a vector containing pointers to the output streams to print to.
|
| |
| template<typename... T> |
| void | print (const T &... items) |
| | Print any number of items into each output stream. Ensures that no other threads print to the streams simultaneously, as long as they all exclusively use the same BS::synced_stream object to print.
|
| |
| template<typename... T> |
| void | println (T &&... items) |
| | Print any number of items into each output stream, followed by a newline character. Ensures that no other threads print to the streams simultaneously, as long as they all exclusively use the same BS::synced_stream object to print.
|
| |
| void | remove_stream (std::ostream &stream) |
| | Remove a stream from the list of output streams to print to.
|
| |
|
|
static std::ostream &(&) | endl (std::ostream &) = static_cast<std::ostream& (&)(std::ostream&)>(std::endl) |
| | A stream manipulator to pass to a BS::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 a newline character 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 BS::synced_stream (an explicit cast of std::flush). Used to flush the stream.
|
| |
|
|
std::mutex | stream_mutex |
| | A mutex to synchronize printing.
|
| |
|
std::vector< std::ostream * > | out_streams |
| | The output streams to print to.
|
| |
A utility class to synchronize printing to one or more output streams by different threads.
◆ synced_stream() [1/2]
| BS::synced_stream::synced_stream |
( |
| ) |
|
|
inlineexplicit |
Construct a new synced stream which prints to std::cout.
2416 {
2418 }
void add_stream(std::ostream &stream)
Add a stream to the list of output streams to print to.
Definition BS_thread_pool.hpp:2437
◆ synced_stream() [2/2]
template<typename... T>
| BS::synced_stream::synced_stream |
( |
T &... |
streams | ) |
|
|
inlineexplicit |
Construct a new synced stream which prints to the given output stream(s).
- Template Parameters
-
| T | The types of the output streams to print to. |
- Parameters
-
| streams | The output streams to print to. |
◆ add_stream()
| void BS::synced_stream::add_stream |
( |
std::ostream & |
stream | ) |
|
|
inline |
Add a stream to the list of output streams to print to.
- Parameters
-
2438 {
2440 }
std::vector< std::ostream * > out_streams
The output streams to print to.
Definition BS_thread_pool.hpp:2507
◆ get_streams()
| std::vector< std::ostream * > & BS::synced_stream::get_streams |
( |
| ) |
|
|
inlinenoexcept |
Get a reference to a vector containing pointers to the output streams to print to.
- Returns
- The output streams.
◆ print()
template<typename... T>
| void BS::synced_stream::print |
( |
const T &... |
items | ) |
|
|
inline |
Print any number of items into each output stream. Ensures that no other threads print to the streams simultaneously, as long as they all exclusively use the same BS::synced_stream object to print.
- Template Parameters
-
- Parameters
-
2460 {
2463 (*stream << ... << items);
2464 }
std::mutex stream_mutex
A mutex to synchronize printing.
Definition BS_thread_pool.hpp:2502
◆ println()
template<typename... T>
| void BS::synced_stream::println |
( |
T &&... |
items | ) |
|
|
inline |
Print any number of items into each output stream, followed by a newline character. Ensures that no other threads print to the streams simultaneously, as long as they all exclusively use the same BS::synced_stream object to print.
- Template Parameters
-
- Parameters
-
2474 {
2475 print(std::forward<T>(items)...,
'\n');
2476 }
void print(const T &... items)
Print any number of items into each output stream. Ensures that no other threads print to the streams...
Definition BS_thread_pool.hpp:2459
◆ remove_stream()
| void BS::synced_stream::remove_stream |
( |
std::ostream & |
stream | ) |
|
|
inline |
Remove a stream from the list of output streams to print to.
- Parameters
-
The documentation for this class was generated from the following file: