Base Framework
Public Member Functions | List of all members
FormatOutputStream::PushContext Class Reference

Push and pop default context of format output stream. More...

#include <base/string/FormatOutputStream.h>

Inherits Object.

Public Member Functions

 PushContext (FormatOutputStream &_stream) noexcept
 
const ContextgetContext () const noexcept
 
 ~PushContext () noexcept
 

Detailed Description

Push and pop default context of format output stream.

The class is used to store and restore the default context of a format output stream using the stack.

Example:

class Composite : public Object {
private:
int x = 0;
int y = 0;
public:
Composite(int _x, int _y) noexcept
: x(_x), y(_y)
{
}
friend FormatOutputStream& operator<<(FormatOutputStream& stream, const Composite& value);
};
FormatOutputStream& operator<<(FormatOutputStream& stream, const Composite& value)
{
FormatOutputStream::PushContext pushContext(stream); // make current context the default context
return stream << '{' << value.x << ',' << value.y << '}';
}
Version
1.0

Constructor & Destructor Documentation

◆ PushContext()

FormatOutputStream::PushContext::PushContext ( FormatOutputStream _stream)
noexcept

Stores the current default context onto the stack and makes the current context the new default context of the stream object.

◆ ~PushContext()

FormatOutputStream::PushContext::~PushContext ( )
noexcept

Restores the default context of the format output stream. The current context of the stream object is reset to the default context.

FormatOutputStream
Format output stream.
Definition: FormatOutputStream.h:106
FormatOutputStream::operator<<
FormatOutputStream & operator<<(Action action)
Object
Object.
Definition: Object.h:28
FormatOutputStream::PushContext
Push and pop default context of format output stream.
Definition: FormatOutputStream.h:301