00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef cxxtools_BasicTextStream_h
00030 #define cxxtools_BasicTextStream_h
00031
00032 #include <cxxtools/api.h>
00033 #include <cxxtools/string.h>
00034 #include <cxxtools/textbuffer.h>
00035 #include <iostream>
00036
00037 namespace cxxtools {
00038
00061 template <typename CharT, typename ByteT>
00062 class BasicTextIStream : public std::basic_istream<CharT>
00063 {
00064 public:
00065 typedef ByteT extern_type;
00066 typedef CharT intern_type;
00067 typedef CharT char_type;
00068 typedef typename std::char_traits<CharT> traits_type;
00069 typedef typename traits_type::int_type int_type;
00070 typedef typename traits_type::pos_type pos_type;
00071 typedef typename traits_type::off_type off_type;
00072 typedef std::basic_istream<extern_type> StreamType;
00073 typedef TextCodec<char_type, extern_type> CodecType;
00074
00075 public:
00083 BasicTextIStream(StreamType& is, CodecType* codec)
00084 : std::basic_istream<intern_type>(0)
00085 , _buffer( &is, codec )
00086 {
00087 init(&_buffer);
00088 }
00089
00090 explicit BasicTextIStream(CodecType* codec)
00091 : std::basic_istream<intern_type>(0)
00092 , _buffer( 0, codec )
00093 {
00094 init(&_buffer);
00095 }
00096
00098 ~BasicTextIStream()
00099 { }
00100
00101 void attach(StreamType& is)
00102 {
00103 _buffer.attach( is );
00104 this->clear();
00105 }
00106
00107 void detach()
00108 {
00109 _buffer.detach();
00110 this->clear();
00111 }
00112
00113 void terminate()
00114 {
00115 _buffer.terminate();
00116 }
00117
00118 BasicTextBuffer<intern_type, extern_type>& buffer()
00119 { return _buffer; }
00120
00121 private:
00122 BasicTextBuffer<intern_type, extern_type> _buffer;
00123 };
00124
00125
00148 template <typename CharT, typename ByteT>
00149 class BasicTextOStream : public std::basic_ostream<CharT>
00150 {
00151 public:
00152 typedef ByteT extern_type;
00153 typedef CharT intern_type;
00154 typedef CharT char_type;
00155 typedef typename std::char_traits<CharT> traits_type;
00156 typedef typename traits_type::int_type int_type;
00157 typedef typename traits_type::pos_type pos_type;
00158 typedef typename traits_type::off_type off_type;
00159 typedef std::basic_ostream<extern_type> StreamType;
00160 typedef TextCodec<char_type, extern_type> CodecType;
00161
00162 public:
00170 BasicTextOStream(StreamType& os, CodecType* codec)
00171 : std::basic_ostream<intern_type>(0)
00172 , _buffer( &os , codec )
00173 { init(&_buffer); }
00174
00175 explicit BasicTextOStream(CodecType* codec)
00176 : std::basic_ostream<intern_type>(0)
00177 , _buffer( 0 , codec )
00178 { init(&_buffer); }
00179
00181 ~BasicTextOStream()
00182 { }
00183
00184 void attach(StreamType& os)
00185 {
00186 _buffer.attach( os );
00187 this->clear();
00188 }
00189
00190 void detach()
00191 {
00192 _buffer.detach();
00193 this->clear();
00194 }
00195
00196 void terminate()
00197 {
00198 _buffer.terminate();
00199 }
00200
00201 BasicTextBuffer<intern_type, extern_type>& buffer()
00202 { return _buffer; }
00203
00204 private:
00205 BasicTextBuffer<intern_type, extern_type> _buffer;
00206 };
00207
00230 template <typename CharT, typename ByteT>
00231 class BasicTextStream : public std::basic_iostream<CharT>
00232 {
00233 public:
00234 typedef ByteT extern_type;
00235 typedef CharT intern_type;
00236 typedef CharT char_type;
00237 typedef typename std::char_traits<CharT> traits_type;
00238 typedef typename traits_type::int_type int_type;
00239 typedef typename traits_type::pos_type pos_type;
00240 typedef typename traits_type::off_type off_type;
00241 typedef std::basic_iostream<extern_type> StreamType;
00242 typedef TextCodec<char_type, extern_type> CodecType;
00243
00244 public:
00253 BasicTextStream(StreamType& ios, CodecType* codec)
00254 : std::basic_iostream<intern_type>(0)
00255 , _buffer( &ios, codec)
00256 { init(&_buffer); }
00257
00258 explicit BasicTextStream(CodecType* codec)
00259 : std::basic_iostream<intern_type>(0)
00260 , _buffer(0, codec)
00261 { init(&_buffer); }
00262
00264 ~BasicTextStream()
00265 { }
00266
00267 void attach(StreamType& ios)
00268 {
00269 _buffer.attach( ios );
00270 this->clear();
00271 }
00272
00273 void detach()
00274 {
00275 _buffer.detach();
00276 this->clear();
00277 }
00278
00279 void terminate()
00280 {
00281 _buffer.terminate();
00282 }
00283
00284 BasicTextBuffer<intern_type, extern_type>& buffer()
00285 { return _buffer; }
00286
00287 private:
00288 BasicTextBuffer<intern_type, extern_type> _buffer;
00289 };
00290
00291
00294 class CXXTOOLS_API TextIStream : public BasicTextIStream<Char, char>
00295 {
00296 public:
00297 typedef TextCodec<cxxtools::Char, char> Codec;
00298
00299 public:
00307 TextIStream(std::istream& is, Codec* codec);
00308
00309 explicit TextIStream(Codec* codec);
00310
00311 ~TextIStream();
00312 };
00313
00314
00317 class CXXTOOLS_API TextOStream : public BasicTextOStream<Char, char>
00318 {
00319 public:
00320 typedef TextCodec<cxxtools::Char, char> Codec;
00321
00322 public:
00330 TextOStream(std::ostream& os, Codec* codec);
00331
00332 explicit TextOStream(Codec* codec);
00333
00334 ~TextOStream();
00335 };
00336
00337
00340 class CXXTOOLS_API TextStream : public BasicTextStream<Char, char>
00341 {
00342 public:
00343 typedef TextCodec<cxxtools::Char, char> Codec;
00344
00345 public:
00353 TextStream(std::iostream& ios, Codec* codec);
00354
00355 explicit TextStream(Codec* codec);
00356
00357 ~TextStream();
00358 };
00359
00360 }
00361
00362 #endif
00363