Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
BS::synced_stream Class Reference

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

#include <BS_thread_pool_utils.hpp>

Public Member Functions

 synced_stream (std::ostream &stream=std::cout)
 Construct a new synced stream.
 
 synced_stream (const synced_stream &)=delete
 
 synced_stream (synced_stream &&)=delete
 
synced_streamoperator= (const synced_stream &)=delete
 
synced_streamoperator= (synced_stream &&)=delete
 
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.
 
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.
 

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 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 synced_stream (an explicit cast of std::flush). Used to flush the stream.
 

Private Attributes

std::ostream & out_stream
 The output stream to print to.
 
std::mutex stream_mutex = {}
 A mutex to synchronize printing.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ synced_stream()

BS::synced_stream::synced_stream ( std::ostream &  stream = std::cout)
inlineexplicit

Construct a new synced stream.

Parameters
streamThe output stream to print to. The default value is std::cout.
89: out_stream(stream) {}
std::ostream & out_stream
The output stream to print to.
Definition BS_thread_pool_utils.hpp:136

Member Function Documentation

◆ print()

template<typename... T>
void BS::synced_stream::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.
105 {
106 const std::scoped_lock stream_lock(stream_mutex);
107 (out_stream << ... << std::forward<T>(items));
108 }
std::mutex stream_mutex
A mutex to synchronize printing.
Definition BS_thread_pool_utils.hpp:141
Here is the caller graph for this function:

◆ println()

template<typename... T>
void BS::synced_stream::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.
118 {
119 print(std::forward<T>(items)..., '\n');
120 }
void print(T &&... items)
Print any number of items into the output stream. Ensures that no other threads print to this stream ...
Definition BS_thread_pool_utils.hpp:104

Member Data Documentation

◆ stream_mutex

std::mutex BS::synced_stream::stream_mutex = {}
mutableprivate

A mutex to synchronize printing.

141{};

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