BasicTextBuffer< CharT, ByteT > Class Template Reference

#include <Pt/TextBuffer.h>

Converts character sequences with different encodings. More...

Inherits BasicStreamBuffer< CharT >.

Public Types

typedef CharT char_type
 Internal character type.
 
typedef TextCodec< char_type,
extern_type
CodecType
 Codec type.
 
typedef ByteT extern_type
 External character type.
 
typedef traits_type::int_type int_type
 Integer type.
 
typedef CharT intern_type
 Internal character type.
 
typedef traits_type::off_type off_type
 Stream offset type.
 
typedef traits_type::pos_type pos_type
 Stream position type.
 
typedef std::char_traits< CharT > traits_type
 Internal character traits.
 

Public Member Functions

 BasicTextBuffer (std::basic_ios< extern_type > &target, CodecType *codec=0)
 Construct with external device and codec. More...
 
 BasicTextBuffer (CodecType *codec=0)
 Construct with codec. More...
 
 ~BasicTextBuffer () throw ()
 Destructor.
 
void attach (std::basic_ios< extern_type > &target)
 Attach to external target.
 
CodecTypecodec ()
 Returns the used codec or a nullptr.
 
void detach ()
 Detach from external target.
 
void discard ()
 Discards the buffer.
 
std::streamsize import (std::streamsize size=0)
 Import data from the external device. More...
 
std::streamsize import (const extern_type *buf, std::streamsize size)
 Import data from a buffer. More...
 
std::streamsize out_avail ()
 Returns the number of characters buffered for output.
 
void reset ()
 Resets the buffer and target. More...
 
void reset (std::basic_ios< extern_type > &target)
 Resets the buffer and target. More...
 
void setCodec (CodecType *codec)
 Sets the text codec. More...
 
std::streamsize speekn (CharT *buffer, std::streamsize size)
 Peek data in stream.
 

Protected Member Functions

virtual std::streamsize showfull ()
 Returns the number of characters buffered for output.
 

Detailed Description

template<typename CharT, typename ByteT>
class Pt::BasicTextBuffer< CharT, ByteT >

This stream buffer encodes and decodes an external character sequence using a codec. Writing to the stream buffer will convert the written characters to the external character types in the external encoding. Reading from the stream buffer will convert from the the encoding of external characters.

Constructor & Destructor Documentation

BasicTextBuffer ( std::basic_ios< extern_type > &  target,
CodecType codec = 0 
)
explicit

The given stream buffer target is used as external device. All input from and output to the external device is converted using the codec codec. The codec object which is passed as a pointer will be managed by this class and deleted if its reference count reaches 0.

BasicTextBuffer ( CodecType codec = 0)
explicit

All input from and output to the external device is converted using the codec codec.

The codec object which is passed as pointer will be managed by this class and deleted if its reference count reaches 0.

Member Function Documentation

void setCodec ( CodecType codec)

The codec object which is passed as pointer will be managed by this class and deleted if its reference count reaches 0.

void reset ( )

The target is detached and the buffer content is discarded. The codec is kept, if one was set previously.

void reset ( std::basic_ios< extern_type > &  target)

Attaches to the new target and discards the buffer. The codec is kept, if one was set previously.

std::streamsize import ( std::streamsize  size = 0)

Returns the number of bytes consumed from the underlying stream.

std::streamsize import ( const extern_type buf,
std::streamsize  size 
)

Returns the number of bytes consumed from the input string.