zorba::hexbinary::auto_attach

#include <zorba/util/hexbinary_stream.h>

A hexbinary::auto_attach is a class that attaches a hexbinary::streambuf to a stream and automatically detaches it when the auto_attach object is destroyed.
  void f( ostream &os ) {
    hexbinary::auto_attach<ostream> const raii( os );
    // ...
  }
A hexbinary::auto_attach is useful for streams not created by you.

Private Attributes

StreamType *

stream_

Public Functions

bool

attach(StreamType &stream)

Calls hexbinary::attach() on the given stream.

auto_attach()

Default constructor; does nothing.

auto_attach(StreamType &stream)

Constructs an auto_attach object calling attach() on the given stream.

auto_attach(auto_attach &from)

Copy constructor that takes ownership of the stream.

void

detach()

Calls hexbinary::detach().

auto_attach &

operator=(auto_attach &from)

Assignment operator that takes ownership of the stream.

~auto_attach()

Destroys this auto_attach object calling detach() on the previously attached stream.

Private Attributes

stream_

StreamType * stream_

Public Functions

attach

bool attach(StreamType &stream)

Calls hexbinary::attach() on the given stream.

Parameters

stream The stream to attach the hexbinary::streambuf to. If the stream already has a hexbinary::streambuf attached to it, this contructor does nothing.

Returns

true only if a hexbinary::streambuf was attached.

auto_attach

 auto_attach()

Default constructor; does nothing.

auto_attach

 auto_attach(StreamType &stream)

Constructs an auto_attach object calling attach() on the given stream.

Parameters

stream The stream to attach the hexbinary::streambuf to. If the stream already has a hexbinary::streambuf attached to it, this contructor does nothing.

auto_attach

 auto_attach(auto_attach &from)

Copy constructor that takes ownership of the stream.

Parameters

from The auto_attach to take ownership from.

detach

void detach()

operator=

auto_attach & operator=(auto_attach &from)

Assignment operator that takes ownership of the stream.

Parameters

from The auto_attach to take ownership from.

Returns

*this.

~auto_attach

 ~auto_attach()

Destroys this auto_attach object calling detach() on the previously attached stream.