Public Member Functions | Protected Member Functions
zorba::transcode::streambuf Class Reference

A transcode::streambuf is-a std::streambuf for transcoding character encodings from/to UTF-8 on-the-fly. More...

#include <zorba/transcode_stream.h>

List of all members.

Public Member Functions

std::streambuf * orig_streambuf () const
 Gets the original streambuf.
 streambuf (char const *charset, std::streambuf *orig)
 Constructs a transcode::streambuf.
 ~streambuf ()
 Destructs a transcode::streambuf.

Protected Member Functions

void imbue (std::locale const &)
int_type overflow (int_type)
int_type pbackfail (int_type)
pos_type seekoff (off_type, std::ios_base::seekdir, std::ios_base::openmode)
pos_type seekpos (pos_type, std::ios_base::openmode)
std::streambuf * setbuf (char_type *, std::streamsize)
std::streamsize showmanyc ()
int sync ()
int_type uflow ()
int_type underflow ()
std::streamsize xsgetn (char_type *, std::streamsize)
std::streamsize xsputn (char_type const *, std::streamsize)

Detailed Description

A transcode::streambuf is-a std::streambuf for transcoding character encodings from/to UTF-8 on-the-fly.

To use it, replace a stream's streambuf:

  istream is;
  // ...
  transcode::streambuf tbuf( "ISO-8859-1", is.rdbuf() );
  is.ios::rdbuf( &tbuf );

Note that the transcode::streambuf must exist for as long as it's being used by the stream. If you are replacing the streabuf for a stream you did not create, you should set it back to the original streambuf:

  void f( ostream &os ) {
    transcode::streambuf tbuf( "ISO-8859-1", os.rdbuf() );
    try {
      os.ios::rdbuf( &tbuf );
      // ...
    }
    catch ( ... ) {
      os.ios::rdbuf( tbuf.orig_streambuf() );
      throw;
    }
  }

While transcode::streambuf does support seeking, the positions are relative to the original byte stream.


Constructor & Destructor Documentation

zorba::transcode::streambuf::streambuf ( char const *  charset,
std::streambuf *  orig 
)

Constructs a transcode::streambuf.

Parameters:
charsetThe name of the character encoding to convert from/to.
origThe original streambuf to read/write from/to.
Exceptions:
std::invalid_argumentif either charset is not supported or orig is null.
zorba::transcode::streambuf::~streambuf ( )

Destructs a transcode::streambuf.


Member Function Documentation

void zorba::transcode::streambuf::imbue ( std::locale const &  ) [protected]
std::streambuf* zorba::transcode::streambuf::orig_streambuf ( ) const [inline]

Gets the original streambuf.

Returns:
said streambuf.

Definition at line 89 of file transcode_stream.h.

int_type zorba::transcode::streambuf::overflow ( int_type  ) [protected]
int_type zorba::transcode::streambuf::pbackfail ( int_type  ) [protected]
pos_type zorba::transcode::streambuf::seekoff ( off_type  ,
std::ios_base::seekdir  ,
std::ios_base::openmode   
) [protected]
pos_type zorba::transcode::streambuf::seekpos ( pos_type  ,
std::ios_base::openmode   
) [protected]
std::streambuf* zorba::transcode::streambuf::setbuf ( char_type *  ,
std::streamsize   
) [protected]
std::streamsize zorba::transcode::streambuf::showmanyc ( ) [protected]
int zorba::transcode::streambuf::sync ( ) [protected]
int_type zorba::transcode::streambuf::uflow ( ) [protected]
int_type zorba::transcode::streambuf::underflow ( ) [protected]
std::streamsize zorba::transcode::streambuf::xsgetn ( char_type *  ,
std::streamsize   
) [protected]
std::streamsize zorba::transcode::streambuf::xsputn ( char_type const *  ,
std::streamsize   
) [protected]

The documentation for this class was generated from the following file:
blog comments powered by Disqus