17 #ifndef ZORBA_TRANSCODE_STREAM_API_H
18 #define ZORBA_TRANSCODE_STREAM_API_H
23 #include <zorba/config.h>
70 class ZORBA_DLL_PUBLIC
streambuf :
public std::streambuf {
80 streambuf(
char const *charset, std::streambuf *orig );
93 return proxy_buf_->original();
97 void imbue( std::locale
const& );
98 pos_type seekoff( off_type, std::ios_base::seekdir, std::ios_base::openmode );
99 pos_type seekpos( pos_type, std::ios_base::openmode );
100 std::streambuf* setbuf( char_type*, std::streamsize );
101 std::streamsize showmanyc();
103 int_type overflow( int_type );
104 int_type pbackfail( int_type );
106 int_type underflow();
107 std::streamsize xsgetn( char_type*, std::streamsize );
108 std::streamsize xsputn( char_type
const*, std::streamsize );
123 namespace transcode {
126 std::streambuf*
alloc_streambuf(
char const *charset, std::streambuf *orig );
134 namespace transcode {
149 template<
typename charT,
typename Traits>
inline
150 void attach( std::basic_ios<charT,Traits> &ios,
char const *charset ) {
152 void *&pword = ios.pword( index );
154 std::streambuf *
const buf =
170 template<
typename charT,
typename Traits>
inline
171 void detach( std::basic_ios<charT,Traits> &ios ) {
173 if (
streambuf *
const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
174 ios.pword( index ) = 0;
175 ios.rdbuf( buf->orig_streambuf() );
186 template<
typename charT,
typename Traits>
inline
197 template<
typename charT,
typename Traits>
inline
199 std::streambuf *
const buf = ios.rdbuf();
200 if (
streambuf *
const tbuf = dynamic_cast<streambuf*>( buf ) )
201 return tbuf->orig_streambuf();
219 template<
class StreamType>
231 attach( stream, charset );
258 template<
class StreamType>
269 # pragma warning( push )
270 # pragma warning( disable : 4355 )
272 tbuf_( charset, this->rdbuf() )
274 # pragma warning( pop )
290 template<
typename StreamArgType>
291 stream(
char const *charset, StreamArgType stream_arg ) :
292 StreamType( stream_arg ),
294 # pragma warning( push )
295 # pragma warning( disable : 4355 )
297 tbuf_( charset, this->rdbuf() )
299 # pragma warning( pop )
316 template<
typename StreamArgType>
317 stream(
char const *charset, StreamArgType stream_arg,
318 std::ios_base::openmode mode ) :
319 StreamType( stream_arg, mode ),
321 # pragma warning( push )
322 # pragma warning( disable : 4355 )
324 tbuf_( charset, this->rdbuf() )
326 # pragma warning( pop )
336 this->std::ios::rdbuf( &tbuf_ );