zorba::transcode::auto_attach

#include <zorba/util/transcode_stream.h>

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

Private Attributes

StreamType *

stream_

Public Functions

bool

attach(StreamType &stream, char const *charset)

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

auto_attach()

Default constructor; does nothing.

auto_attach(StreamType &stream, char const *charset)

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 transcode::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, if any.

Private Attributes

stream_

StreamType * stream_

Public Functions

attach

bool attach(StreamType &stream, char const *charset)

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

Parameters

stream The stream to attach the transcode::streambuf to. If the stream already has a transcode::streambuf attached to it, this contructor does nothing.
charset The name of the character encoding to convert from/to.

Returns

true only if a transcode::streambuf was attached.

auto_attach

 auto_attach()

Default constructor; does nothing.

auto_attach

 auto_attach(StreamType &stream, char const *charset)

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

Parameters

stream The stream to attach the transcode::streambuf to. If the stream already has a transcode::streambuf attached to it, this contructor does nothing.
charset The name of the character encoding to convert from/to.

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, if any.