17 #ifndef ZORBA_TRANSCODE_STREAM_API_H
18 #define ZORBA_TRANSCODE_STREAM_API_H
20 #include <zorba/config.h>
63 class ZORBA_DLL_PUBLIC
streambuf :
public std::streambuf {
73 streambuf(
char const *charset, std::streambuf *orig );
86 return proxy_buf_->original();
90 void imbue( std::locale
const& );
91 pos_type seekoff( off_type, std::ios_base::seekdir, std::ios_base::openmode );
92 pos_type seekpos( pos_type, std::ios_base::openmode );
93 std::streambuf* setbuf( char_type*, std::streamsize );
94 std::streamsize showmanyc();
96 int_type overflow( int_type );
97 int_type pbackfail( int_type );
100 std::streamsize xsgetn( char_type*, std::streamsize );
101 std::streamsize xsputn( char_type
const*, std::streamsize );
116 namespace transcode {
119 std::streambuf*
alloc_streambuf(
char const *charset, std::streambuf *orig );
127 namespace transcode {
142 template<
typename charT,
class Traits>
inline
143 void attach( std::basic_ios<charT,Traits> &ios,
char const *charset ) {
145 void *&pword = ios.pword( index );
147 std::streambuf *
const buf =
163 template<
typename charT,
class Traits>
inline
164 void detach( std::basic_ios<charT,Traits> &ios ) {
166 if (
streambuf *
const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
167 ios.pword( index ) = 0;
168 ios.rdbuf( buf->orig_streambuf() );
179 template<
typename charT,
class Traits>
inline
190 template<
typename charT,
class Traits>
inline
192 std::streambuf *
const buf = ios.rdbuf();
193 if (
streambuf *
const tbuf = dynamic_cast<streambuf*>( buf ) )
194 return tbuf->orig_streambuf();
212 template<
class StreamType>
224 attach( stream, charset );
251 template<
class StreamType>
262 # pragma warning( push )
263 # pragma warning( disable : 4355 )
265 tbuf_( charset, this->rdbuf() )
267 # pragma warning( pop )
283 template<
typename StreamArgType>
284 stream(
char const *charset, StreamArgType stream_arg ) :
285 StreamType( stream_arg ),
287 # pragma warning( push )
288 # pragma warning( disable : 4355 )
290 tbuf_( charset, this->rdbuf() )
292 # pragma warning( pop )
309 template<
typename StreamArgType>
310 stream(
char const *charset, StreamArgType stream_arg,
311 std::ios_base::openmode mode ) :
312 StreamType( stream_arg, mode ),
314 # pragma warning( push )
315 # pragma warning( disable : 4355 )
317 tbuf_( charset, this->rdbuf() )
319 # pragma warning( pop )
329 this->std::ios::rdbuf( &tbuf_ );
ZORBA_DLL_PUBLIC bool is_necessary(char const *charset)
Checks whether it would be necessary to transcode from the given character encoding to UTF-8...
~auto_attach()
Destroys this auto_attach object calling detach() on the previously attached stream.
ZORBA_DLL_PUBLIC std::streambuf * alloc_streambuf(char const *charset, std::streambuf *orig)
stream(char const *charset)
Constructs a transcode::stream.
A transcode::auto_attach is a class that attaches a transcode::streambuf to a stream and automaticall...
auto_attach(StreamType &stream, char const *charset)
Constructs an auto_attach object calling attach() on the given stream.
A transcode::stream is used to wrap a C++ standard I/O stream with a transcode::streambuf so that tra...
std::streambuf * orig_streambuf(std::basic_ios< charT, Traits > &ios)
Gets the original streambuf of the given iostream.
ZORBA_DLL_PUBLIC bool is_supported(char const *charset)
Checks whether the given character set is supported for transcoding.
stream(char const *charset, StreamArgType stream_arg)
Constructs a stream.
void detach(std::basic_ios< charT, Traits > &ios)
Detaches a previously attached transcode::streambuf from a stream.
bool is_attached(std::basic_ios< charT, Traits > &ios)
Checks whether the given stream has a transcode::streambuf attached.
std::streambuf * orig_streambuf() const
Gets the original streambuf.
ZORBA_DLL_PUBLIC int get_streambuf_index()
stream(char const *charset, StreamArgType stream_arg, std::ios_base::openmode mode)
Constructs a transcode::stream.
void attach(std::basic_ios< charT, Traits > &ios, char const *charset)
Attaches a transcode::streambuf to a stream.
ZORBA_DLL_PUBLIC void stream_callback(std::ios_base::event, std::ios_base &, int index)
ZORBA_DLL_PUBLIC void dealloc_streambuf(std::streambuf *)
A transcode::streambuf is-a std::streambuf for transcoding character encodings from/to UTF-8 on-the-f...