00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _STLP_INTERNAL_ISTREAM_H
00019 #define _STLP_INTERNAL_ISTREAM_H
00020
00021
00022 # if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_CWCHAR)
00023 # include <cwchar>
00024 # endif
00025
00026 # ifndef _STLP_INTERNAL_IOS_H
00027 # include <stl/_ios.h>
00028 # endif
00029
00030 #ifndef _STLP_INTERNAL_OSTREAM_H
00031 # include <stl/_ostream.h>
00032 #endif
00033
00034 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
00035 # include <stl/_istreambuf_iterator.h>
00036 #endif
00037
00038 #include <stl/_ctraits_fns.h>
00039
00040 _STLP_BEGIN_NAMESPACE
00041
00042 template <class _CharT, class _Traits, class _Number>
00043 ios_base::iostate _STLP_CALL
00044 _M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val);
00045
00046 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00047 template <class _CharT, class _Traits>
00048 class _Isentry;
00049 #endif
00050
00051 struct _No_Skip_WS {};
00052
00053 template <class _CharT, class _Traits>
00054 bool _M_init_skip(basic_istream<_CharT, _Traits>& __is);
00055 template <class _CharT, class _Traits>
00056 bool _M_init_noskip(basic_istream<_CharT, _Traits>& __is);
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 template <class _CharT, class _Traits>
00067 class basic_istream : virtual public basic_ios<_CharT, _Traits> {
00068 public:
00069
00070 typedef _CharT char_type;
00071 typedef typename _Traits::int_type int_type;
00072 typedef typename _Traits::pos_type pos_type;
00073 typedef typename _Traits::off_type off_type;
00074 typedef _Traits traits_type;
00075 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00076 typedef basic_istream<_CharT, _Traits> _Self;
00077
00078 typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
00079 typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
00080 typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
00081
00082 public:
00083 explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
00084 basic_ios<_CharT, _Traits>(), _M_gcount(0) {
00085 this->init(__buf);
00086 }
00087 ~basic_istream() {};
00088
00089 public:
00090
00091 public:
00092
00093 _Self& operator>> (__istream_fn __f) { return __f(*this); }
00094 _Self& operator>> (__ios_fn __f) { __f(*this); return *this; }
00095 _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
00096
00097 public:
00098 _Self& operator>> (short& __val) {
00099 long __lval;
00100 unsigned short __uval;
00101 _M_get_num(*this, __lval);
00102 __val = __STATIC_CAST(short, __lval);
00103 __uval = __lval;
00104
00105
00106 if ((__val != __lval) && ((long)__uval != __lval))
00107 this->setstate(ios_base::failbit);
00108 return *this;
00109 }
00110 _Self& operator>> (int& __val) {
00111 long __lval;
00112 unsigned int __uval;
00113 _M_get_num(*this, __lval);
00114 __val = __lval;
00115 __uval = __lval;
00116
00117
00118 if ((__val != __lval) && ((long)__uval != __lval))
00119 this->setstate(ios_base::failbit);
00120 return *this;
00121 }
00122 _Self& operator>> (unsigned short& __val) { _M_get_num(*this, __val); return *this; }
00123 _Self& operator>> (unsigned int& __val) { _M_get_num(*this, __val); return *this; }
00124 _Self& operator>> (long& __val) { _M_get_num(*this, __val); return *this; }
00125 _Self& operator>> (unsigned long& __val) { _M_get_num(*this, __val); return *this; }
00126 #ifdef _STLP_LONG_LONG
00127 _Self& operator>> (_STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
00128 _Self& operator>> (unsigned _STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
00129 #endif
00130 _Self& operator>> (float& __val) { _M_get_num(*this, __val); return *this; }
00131 _Self& operator>> (double& __val) { _M_get_num(*this, __val); return *this; }
00132 # ifndef _STLP_NO_LONG_DOUBLE
00133 _Self& operator>> (long double& __val) { _M_get_num(*this, __val); return *this; }
00134 # endif
00135 # ifndef _STLP_NO_BOOL
00136 _Self& operator>> (bool& __val) { _M_get_num(*this, __val); return *this; }
00137 # endif
00138 _Self& operator>> (void*& __val) { _M_get_num(*this, __val); return *this; }
00139
00140 public:
00141 _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
00142
00143 public:
00144 streamsize gcount() const { return _M_gcount; }
00145 int_type peek();
00146
00147 public:
00148 int_type get();
00149 _Self& get(char_type& __c);
00150
00151 public:
00152 _Self& get(char_type* __s, streamsize __n, char_type __delim);
00153 _Self& get(char_type* __s, streamsize __n)
00154 { return get(__s, __n, this->widen('\n')); }
00155
00156 public:
00157 _Self& get(basic_streambuf<_CharT, _Traits>& __buf,
00158 char_type __delim);
00159 _Self& get(basic_streambuf<_CharT, _Traits>& __buf)
00160 { return get(__buf, this->widen('\n')); }
00161
00162 public:
00163 _Self& getline(char_type* __s, streamsize __n, char_type delim);
00164 _Self& getline(char_type* __s, streamsize __n)
00165 { return getline(__s, __n, this->widen('\n')); }
00166
00167 public:
00168 _Self& ignore();
00169 _Self& ignore(streamsize __n);
00170 #if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
00171 inline
00172 #endif
00173 _Self& ignore(streamsize __n, int_type __delim);
00174
00175 _Self& read(char_type* __s, streamsize __n);
00176 streamsize readsome(char_type* __s, streamsize __n);
00177
00178 public:
00179 _Self& putback(char_type __c);
00180 _Self& unget();
00181
00182 public:
00183 int sync();
00184
00185 pos_type tellg();
00186 _Self& seekg(pos_type __pos);
00187 _Self& seekg(off_type, ios_base::seekdir);
00188
00189 public:
00190 void _M_formatted_get(_CharT& __c);
00191 void _M_formatted_get(_CharT* __s);
00192 void _M_skip_whitespace(bool __set_failbit);
00193
00194 private:
00195 streamsize _M_gcount;
00196
00197 public:
00198
00199 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00200
00201
00202 typedef _Isentry<_CharT, _Traits> sentry;
00203 };
00204 # define sentry _Isentry
00205 template <class _CharT, class _Traits>
00206 class _Isentry {
00207 typedef _Isentry<_CharT, _Traits> _Self;
00208 # else
00209 class sentry {
00210 typedef sentry _Self;
00211 #endif
00212
00213 private:
00214 const bool _M_ok;
00215
00216
00217 public:
00218 typedef _Traits traits_type;
00219
00220 explicit sentry(basic_istream<_CharT, _Traits>& __is,
00221 bool __noskipws = false) :
00222 _M_ok((__noskipws || !(__is.flags() & ios_base::skipws)) ? _M_init_noskip(__is) : _M_init_skip(__is) )
00223
00224 {}
00225
00226
00227
00228 sentry(basic_istream<_CharT, _Traits>& __is, _No_Skip_WS) :
00229 _M_ok(_M_init_noskip(__is)) {}
00230
00231 ~sentry() {}
00232
00233 operator bool() const { return _M_ok; }
00234
00235 private:
00236 sentry(const _Self&) : _M_ok(false) {}
00237 void operator=(const _Self&) {}
00238 };
00239
00240 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00241 # undef sentry
00242 # else
00243
00244 };
00245 # endif
00246
00247 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00248 _STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
00249 _STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
00250 # if ! defined (_STLP_NO_WCHAR_T)
00251 _STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
00252 _STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
00253 # endif
00254 # endif
00255
00256
00257
00258 template <class _CharT, class _Traits>
00259 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00260 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) {
00261 __in._M_formatted_get(__c);
00262 return __in;
00263 }
00264
00265 template <class _Traits>
00266 inline basic_istream<char, _Traits>& _STLP_CALL
00267 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) {
00268 __in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
00269 return __in;
00270 }
00271
00272 template <class _Traits>
00273 inline basic_istream<char, _Traits>& _STLP_CALL
00274 operator>>(basic_istream<char, _Traits>& __in, signed char& __c) {
00275 __in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
00276 return __in;
00277 }
00278
00279 template <class _CharT, class _Traits>
00280 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00281 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) {
00282 __in._M_formatted_get(__s);
00283 return __in;
00284 }
00285
00286 template <class _Traits>
00287 inline basic_istream<char, _Traits>& _STLP_CALL
00288 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) {
00289 __in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
00290 return __in;
00291 }
00292
00293 template <class _Traits>
00294 inline basic_istream<char, _Traits>& _STLP_CALL
00295 operator>>(basic_istream<char, _Traits>& __in, signed char* __s) {
00296 __in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
00297 return __in;
00298 }
00299
00300
00301
00302 template <class _CharT, class _Traits>
00303 basic_istream<_CharT, _Traits>& _STLP_CALL
00304 ws(basic_istream<_CharT, _Traits>& __is);
00305
00306
00307
00308
00309 template <class _CharT, class _Traits>
00310 class basic_iostream
00311 : public basic_istream<_CharT, _Traits>,
00312 public basic_ostream<_CharT, _Traits>
00313 {
00314 public:
00315 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00316
00317 explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
00318 virtual ~basic_iostream();
00319 };
00320
00321 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00322 _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
00323 # if ! defined (_STLP_NO_WCHAR_T)
00324 _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
00325 # endif
00326 # endif
00327
00328 template <class _CharT, class _Traits>
00329 basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __is)
00330 {
00331 return __is.rdbuf();
00332 }
00333
00334 _STLP_END_NAMESPACE
00335
00336 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00337 # include <stl/_istream.c>
00338 # endif
00339
00340 #endif
00341
00342
00343
00344