All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
icarus::ns::util::FormatFlagsGuard< IOS > Class Template Reference

Saves some status of the specified stream object, and restores it. More...

#include <BinaryDumpUtils.h>

Public Member Functions

 FormatFlagsGuard (IOS &ios)
 
 ~FormatFlagsGuard ()
 
void restore ()
 

Private Attributes

IOS & ios
 
IOS::fmtflags const flags
 
IOS::char_type const fill
 

Detailed Description

template<typename IOS>
class icarus::ns::util::FormatFlagsGuard< IOS >

Saves some status of the specified stream object, and restores it.

Template Parameters
IOStype of stream object, with flag interface like std::ostream

This object uses the RIIA pattern to read some status from a stream, and then restore it on the destruction of the object itself. Example:

std::cout << std::hex << 26 << std::endl; // prints "1a"
std::cout << 28 << std::endl; // prints "1c" (hexadecimal format sticks)
{
icarus::ns::util::FormatFlagsGuard sg(std::cout); // saves std::cout status
std::cout << std::oct << 26 << std::endl; // prints "32"
std::cout << 28 << std::endl; // prints "34" (octal format sticks)
// destruction of sg happens here, std::cout flags are restored
}
std::cout << 28 << std::endl; // prints "1c" (hexadecimal format restored)

Saved settings currently include:

Definition at line 206 of file BinaryDumpUtils.h.

Constructor & Destructor Documentation

template<typename IOS >
icarus::ns::util::FormatFlagsGuard< IOS >::FormatFlagsGuard ( IOS &  ios)
inline

Definition at line 360 of file BinaryDumpUtils.h.

361  : ios{ios}, flags{ios.flags()}, fill{ios.fill()} {}
template<typename IOS >
icarus::ns::util::FormatFlagsGuard< IOS >::~FormatFlagsGuard ( )
inline

Definition at line 363 of file BinaryDumpUtils.h.

Member Function Documentation

template<typename IOS >
void icarus::ns::util::FormatFlagsGuard< IOS >::restore ( )
inline

Definition at line 365 of file BinaryDumpUtils.h.

Member Data Documentation

template<typename IOS >
IOS::char_type const icarus::ns::util::FormatFlagsGuard< IOS >::fill
private

Definition at line 357 of file BinaryDumpUtils.h.

template<typename IOS >
IOS::fmtflags const icarus::ns::util::FormatFlagsGuard< IOS >::flags
private

Definition at line 356 of file BinaryDumpUtils.h.

template<typename IOS >
IOS& icarus::ns::util::FormatFlagsGuard< IOS >::ios
private

Definition at line 353 of file BinaryDumpUtils.h.


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