Snap! Websites
An Open Source CMS System in C++
A class used to safely handle stream flags, width, and precision. More...
#include <os_raii.h>
Create an object of this type on your stack, and the flags, width, and precision of your standard streams will be safe-guarded.
See the constructor for an example.
This function saves the flags, precision, and width of a stream inside this object so as to restore them later.
The destructor will automatically restore the flags. The restore() function can also be called early, although that will eventually break the RAII feature since restore only restores the flags once. Further calls to the restore() function do nothing.
To use:
Definition at line 79 of file os_raii.cpp.
The destructor automatically restores the stream flags, width, and precision when called. Putting such an object on the stack is the safest way to make sure that your function does not leak the stream flags, width, and precision.
This function calls the restore() function. Note that restore() has no effect when called more than once.
Definition at line 98 of file os_raii.cpp.
References restore().
This function restores the flags, width, and precision of the stream as they were when the object was passed to the constructor of this object.
The function can be called any number of time, however, it only restores the flags, width, and precision the first time it is called.
In most cases, you want to let your raii_stream_flags object destructor call this restore() function automatically, although you may need to restore the format early once in a while.
Definition at line 118 of file os_raii.cpp.
References f_flags, f_precision, f_stream, and f_width.
Referenced by ~raii_stream_flags().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.
Snap! Websites
An Open Source CMS System in C++