TextCodec< CharT, ByteT > Class Template Reference

#include <Pt/TextCodec.h>

Converts between character encodings. More...

Inherits codecvt< T, B, Pt::MBState >.

Public Types

typedef ByteT extern_type
 External character type.
typedef CharT intern_type
 Internal character type.
typedef MBState state_type
 Conversion state type.

Public Member Functions

 TextCodec (std::size_t ref=0)
 Constructs with reference count. More...
virtual ~TextCodec ()
bool always_noconv () const
 Returns true if no conversion is required.
int encoding () const
 Returns the encoding rate.
result in (MBState &s, const ByteT *fbeg, const ByteT *fend, const ByteT *&fnext, CharT *tbeg, CharT *tend, CharT *&tnext) const
 Decodes a character sequence.
int length (MBState &state, const ByteT *from, const ByteT *end, std::size_t max) const
 Returns the number of the decoded characters.
int max_length () const
 Maximum length of an external sequence if one character is encoded.
result out (MBState &state, const CharT *fbeg, const CharT *fend, const CharT *&fnext, ByteT *tbeg, ByteT *tend, ByteT *&tnext) const
 Encodes a character sequence.
result unshift (MBState &state, ByteT *to, ByteT *to_end, ByteT *&to_next) const
 Unshifts a character sequence.

Detailed Description

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

A Pt::TextCodec is used by text converters to encode and decode external byte sequences, hence the name codec. It implements the std::codecvt facet interface, on systems provide the std::locale facilities. Codecs are stateless, which means that one codec can be used with multiple text converters. A TextCodec is constructed with a reference counter that indicates whether the converter or locale manages the lifetime of the codec. If that value is 0, as it is the case if the TextCodec is default constructed, the text converter or locale will delete the codec.

Therefore, a default constructed TextCodec has to be cretaed with new, as it is the rule for all localization facets. This can be avoided by passing a value different from 0 to the codecs constructor, in which case the codec must exist at least as long as the stream that uses it:

Pt::Utf8Codec codec(1);
Pt::TextOStream tos(codec);

Constructor & Destructor Documentation

TextCodec ( std::size_t  ref = 0)

If ref is 0 the stream, stream buffer or locale deletes the facet.