An OptionalStreamGuard is an RAII class that sets a device to some value on initialization, and resets the device to its original value on destruction. More...
#include <StreamGuard.h>
Public Member Functions | |
OptionalStreamGuard () | |
Create an uninitialized guard. | |
OptionalStreamGuard (Stream stream) | |
Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream. More... | |
OptionalStreamGuard (optional< Stream > stream_opt) | |
Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream, if the passed stream is not nullopt. More... | |
OptionalStreamGuard (const OptionalStreamGuard &)=delete | |
Copy is disallowed. | |
OptionalStreamGuard & | operator= (const OptionalStreamGuard &)=delete |
OptionalStreamGuard (OptionalStreamGuard &&other)=delete | |
OptionalStreamGuard & | operator= (OptionalStreamGuard &&other)=delete |
void | reset_stream (Stream stream) |
Resets the currently set stream to the original stream and the currently set device to the original device. More... | |
optional< Stream > | original_stream () const |
Returns the stream that was set at the time the guard was most recently initialized, or nullopt if the guard is uninitialized. More... | |
optional< Stream > | current_stream () const |
Returns the most recent stream that was set using this stream guard, either from construction, or via reset_stream, if the guard is initialized, or nullopt if the guard is uninitialized. More... | |
void | reset () |
Restore the original device and stream, resetting this guard to uninitialized state. | |
An OptionalStreamGuard is an RAII class that sets a device to some value on initialization, and resets the device to its original value on destruction.
See OptionalDeviceGuard for more guidance on how to use this class.
Definition at line 80 of file StreamGuard.h.
|
inlineexplicit |
Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream.
Definition at line 86 of file StreamGuard.h.
Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream, if the passed stream is not nullopt.
Definition at line 91 of file StreamGuard.h.
Returns the most recent stream that was set using this stream guard, either from construction, or via reset_stream, if the guard is initialized, or nullopt if the guard is uninitialized.
Definition at line 117 of file StreamGuard.h.
Returns the stream that was set at the time the guard was most recently initialized, or nullopt if the guard is uninitialized.
Definition at line 112 of file StreamGuard.h.
|
inline |
Resets the currently set stream to the original stream and the currently set device to the original device.
Then, set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream. Initializes the guard if it was not previously initialized.
Definition at line 108 of file StreamGuard.h.