A StreamGuard is an RAII class that changes the current device to the device corresponding to some stream, and changes the default stream on that device to be this stream. More...
#include <StreamGuard.h>
Public Member Functions | |
StreamGuard ()=delete | |
No default constructor, see Note [Omitted default constructor from RAII]. | |
StreamGuard (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... | |
StreamGuard (const StreamGuard &)=delete | |
Copy is disallowed. | |
StreamGuard & | operator= (const StreamGuard &)=delete |
StreamGuard (StreamGuard &&other)=delete | |
Move is disallowed, as StreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors. More... | |
StreamGuard & | operator= (StreamGuard &&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... | |
Stream | original_stream () const |
Returns the stream that was set at the time the guard was constructed. | |
Stream | current_stream () const |
Returns the most recent stream that was set using this device guard, either from construction, or via set_stream. More... | |
Device | current_device () const |
Returns the most recent device that was set using this device guard, either from construction, or via set_device/reset_device/set_index. More... | |
Device | original_device () const |
Returns the device that was set at the most recent reset_stream(), or otherwise the device at construction time. More... | |
A StreamGuard is an RAII class that changes the current device to the device corresponding to some stream, and changes the default stream on that device to be this stream.
Use of StreamGuard is HIGHLY discouraged in operator definitions. In a single operator, you probably don't know enough about the global state of the world to profitably decide how to set streams. Let the caller handle this appropriately, and just use the current stream in your operator code.
This StreamGuard does NOT have an uninitialized state; it is guaranteed to reset the stream and device on exit. If you are in a situation where you might want to setup a stream guard, see OptionalStreamGuard.
Definition at line 22 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 28 of file StreamGuard.h.
|
delete |
Move is disallowed, as StreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors.
|
inline |
Returns the most recent device that was set using this device guard, either from construction, or via set_device/reset_device/set_index.
Definition at line 65 of file StreamGuard.h.
|
inline |
Returns the most recent stream that was set using this device guard, either from construction, or via set_stream.
Definition at line 59 of file StreamGuard.h.
|
inline |
Returns the device that was set at the most recent reset_stream(), or otherwise the device at construction time.
Definition at line 69 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.
NOTE: this implementation may skip some stream/device setting if it can prove that it is unnecessary.
WARNING: reset_stream does NOT preserve previously set streams on different devices. If you need to set streams on multiple devices on , use MultiStreamGuard instead.
Definition at line 50 of file StreamGuard.h.