1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_istream.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,362 @@
1.4 +/*
1.5 + * Copyright (c) 1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +#ifndef _STLP_INTERNAL_ISTREAM
1.22 +#define _STLP_INTERNAL_ISTREAM
1.23 +
1.24 +// this block is included by _ostream.h, we include it here to lower #include level
1.25 +#if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)
1.26 +# include <stl/_cwchar.h>
1.27 +#endif
1.28 +
1.29 +#ifndef _STLP_INTERNAL_IOS_H
1.30 +# include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
1.31 +#endif
1.32 +
1.33 +#ifndef _STLP_INTERNAL_OSTREAM_H
1.34 +# include <stl/_ostream.h> // Needed as a base class of basic_iostream.
1.35 +#endif
1.36 +
1.37 +#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
1.38 +# include <stl/_istreambuf_iterator.h>
1.39 +#endif
1.40 +
1.41 +#include <stl/_ctraits_fns.h> // Helper functions that allow char traits
1.42 + // to be used as function objects.
1.43 +_STLP_BEGIN_NAMESPACE
1.44 +
1.45 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.46 +template <class _CharT, class _Traits>
1.47 +class _Isentry;
1.48 +#endif
1.49 +
1.50 +struct _No_Skip_WS {}; // Dummy class used by sentry.
1.51 +
1.52 +template <class _CharT, class _Traits>
1.53 +bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr);
1.54 +template <class _CharT, class _Traits>
1.55 +bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr);
1.56 +
1.57 +//----------------------------------------------------------------------
1.58 +// Class basic_istream, a class that performs formatted input through
1.59 +// a stream buffer.
1.60 +
1.61 +// The second template parameter, _Traits, defaults to char_traits<_CharT>.
1.62 +// The default is declared in header <iosfwd>, and it isn't declared here
1.63 +// because C++ language rules do not allow it to be declared twice.
1.64 +
1.65 +template <class _CharT, class _Traits>
1.66 +class basic_istream : virtual public basic_ios<_CharT, _Traits> {
1.67 + typedef basic_istream<_CharT, _Traits> _Self;
1.68 +
1.69 +#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
1.70 + //explicitely defined as private to avoid warnings:
1.71 + basic_istream(_Self const&);
1.72 + _Self& operator = (_Self const&);
1.73 +#endif
1.74 +
1.75 +public:
1.76 + // Types
1.77 + typedef _CharT char_type;
1.78 + typedef typename _Traits::int_type int_type;
1.79 + typedef typename _Traits::pos_type pos_type;
1.80 + typedef typename _Traits::off_type off_type;
1.81 + typedef _Traits traits_type;
1.82 + typedef basic_ios<_CharT, _Traits> _Basic_ios;
1.83 +
1.84 + typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
1.85 + typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
1.86 + typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
1.87 +
1.88 +public: // Constructor and destructor.
1.89 + explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
1.90 + basic_ios<_CharT, _Traits>(), _M_gcount(0) {
1.91 + this->init(__buf);
1.92 + }
1.93 + ~basic_istream() {};
1.94 +
1.95 +public: // Nested sentry class.
1.96 +
1.97 +public: // Hooks for manipulators. The arguments are
1.98 + // function pointers.
1.99 + _Self& operator>> (__istream_fn __f) { return __f(*this); }
1.100 + _Self& operator>> (__ios_fn __f) { __f(*this); return *this; }
1.101 + _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
1.102 +
1.103 +public: // Formatted input of numbers.
1.104 + _Self& operator>> (short& __val);
1.105 + _Self& operator>> (int& __val);
1.106 + _Self& operator>> (unsigned short& __val);
1.107 + _Self& operator>> (unsigned int& __val);
1.108 + _Self& operator>> (long& __val);
1.109 + _Self& operator>> (unsigned long& __val);
1.110 +#ifdef _STLP_LONG_LONG
1.111 + _Self& operator>> (_STLP_LONG_LONG& __val);
1.112 + _Self& operator>> (unsigned _STLP_LONG_LONG& __val);
1.113 +#endif
1.114 + _Self& operator>> (float& __val);
1.115 + _Self& operator>> (double& __val);
1.116 +# ifndef _STLP_NO_LONG_DOUBLE
1.117 + _Self& operator>> (long double& __val);
1.118 +# endif
1.119 +# ifndef _STLP_NO_BOOL
1.120 + _Self& operator>> (bool& __val);
1.121 +# endif
1.122 + _Self& operator>> (void*& __val);
1.123 +
1.124 +public: // Copying characters into a streambuf.
1.125 + _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
1.126 +
1.127 +public: // Unformatted input.
1.128 + streamsize gcount() const { return _M_gcount; }
1.129 + int_type peek();
1.130 +
1.131 +public: // get() for single characters
1.132 + int_type get();
1.133 + _Self& get(char_type& __c);
1.134 +
1.135 +public: // get() for character arrays.
1.136 + _Self& get(char_type* __s, streamsize __n, char_type __delim);
1.137 + _Self& get(char_type* __s, streamsize __n)
1.138 + { return get(__s, __n, this->widen('\n')); }
1.139 +
1.140 +public: // get() for streambufs
1.141 + _Self& get(basic_streambuf<_CharT, _Traits>& __buf,
1.142 + char_type __delim);
1.143 + _Self& get(basic_streambuf<_CharT, _Traits>& __buf)
1.144 + { return get(__buf, this->widen('\n')); }
1.145 +
1.146 +public: // getline()
1.147 + _Self& getline(char_type* __s, streamsize __n, char_type delim);
1.148 + _Self& getline(char_type* __s, streamsize __n)
1.149 + { return getline(__s, __n, this->widen('\n')); }
1.150 +
1.151 +public: // read(), readsome(), ignore()
1.152 + _Self& ignore();
1.153 + _Self& ignore(streamsize __n);
1.154 +#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
1.155 + inline
1.156 +#endif
1.157 + _Self& ignore(streamsize __n, int_type __delim);
1.158 +
1.159 + _Self& read(char_type* __s, streamsize __n);
1.160 + streamsize readsome(char_type* __s, streamsize __n);
1.161 +
1.162 +public: // putback
1.163 + _Self& putback(char_type __c);
1.164 + _Self& unget();
1.165 +
1.166 +public: // Positioning and buffer control.
1.167 + int sync();
1.168 +
1.169 + pos_type tellg();
1.170 + _Self& seekg(pos_type __pos);
1.171 + _Self& seekg(off_type, ios_base::seekdir);
1.172 +
1.173 +public: // Helper functions for non-member extractors.
1.174 + void _M_formatted_get(_CharT& __c);
1.175 + void _M_formatted_get(_CharT* __s);
1.176 + void _M_skip_whitespace(bool __set_failbit);
1.177 +
1.178 +private: // Number of characters extracted by the
1.179 + streamsize _M_gcount; // most recent unformatted input function.
1.180 +
1.181 +public:
1.182 +
1.183 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.184 + // If we are using DLL specs, we have not to use inner classes
1.185 + // end class declaration here
1.186 + typedef _Isentry<_CharT, _Traits> sentry;
1.187 +};
1.188 +# define sentry _Isentry
1.189 +template <class _CharT, class _Traits>
1.190 +class _Isentry {
1.191 + typedef _Isentry<_CharT, _Traits> _Self;
1.192 +# else
1.193 + class sentry {
1.194 + typedef sentry _Self;
1.195 +#endif
1.196 +
1.197 + private:
1.198 + const bool _M_ok;
1.199 + // basic_streambuf<_CharT, _Traits>* _M_buf;
1.200 +
1.201 + public:
1.202 + typedef _Traits traits_type;
1.203 +
1.204 + explicit sentry(basic_istream<_CharT, _Traits>& __istr,
1.205 + bool __noskipws = false) :
1.206 + _M_ok((__noskipws || !(__istr.flags() & ios_base::skipws)) ? _M_init_noskip(__istr) : _M_init_skip(__istr) )
1.207 + /* , _M_buf(__istr.rdbuf()) */
1.208 + {}
1.209 +
1.210 + // Calling this constructor is the same as calling the previous one with
1.211 + // __noskipws = true, except that it doesn't require a runtime test.
1.212 + sentry(basic_istream<_CharT, _Traits>& __istr, _No_Skip_WS) : /* _M_buf(__istr.rdbuf()), */
1.213 + _M_ok(_M_init_noskip(__istr)) {}
1.214 +
1.215 + ~sentry() {}
1.216 +
1.217 + operator bool() const { return _M_ok; }
1.218 +
1.219 + private: // Disable assignment and copy constructor.
1.220 + //Implementation is here only to avoid warning with some compilers.
1.221 + sentry(const _Self&) : _M_ok(false) {}
1.222 + _Self& operator=(const _Self&) { return *this; }
1.223 + };
1.224 +
1.225 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
1.226 +# undef sentry
1.227 +# else
1.228 + // close basic_istream class definition here
1.229 +};
1.230 +# endif
1.231 +
1.232 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
1.233 +_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
1.234 +_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
1.235 +# if ! defined (_STLP_NO_WCHAR_T)
1.236 +_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
1.237 +_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
1.238 +# endif
1.239 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
1.240 +
1.241 +// Non-member character and string extractor functions.
1.242 +template <class _CharT, class _Traits>
1.243 +inline basic_istream<_CharT, _Traits>& _STLP_CALL
1.244 +operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT& __c) {
1.245 + __in_str._M_formatted_get(__c);
1.246 + return __in_str;
1.247 +}
1.248 +
1.249 +template <class _Traits>
1.250 +inline basic_istream<char, _Traits>& _STLP_CALL
1.251 +operator>>(basic_istream<char, _Traits>& __in_str, unsigned char& __c) {
1.252 + __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
1.253 + return __in_str;
1.254 +}
1.255 +
1.256 +template <class _Traits>
1.257 +inline basic_istream<char, _Traits>& _STLP_CALL
1.258 +operator>>(basic_istream<char, _Traits>& __in_str, signed char& __c) {
1.259 + __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
1.260 + return __in_str;
1.261 +}
1.262 +
1.263 +template <class _CharT, class _Traits>
1.264 +inline basic_istream<_CharT, _Traits>& _STLP_CALL
1.265 +operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT* __s) {
1.266 + __in_str._M_formatted_get(__s);
1.267 + return __in_str;
1.268 +}
1.269 +
1.270 +template <class _Traits>
1.271 +inline basic_istream<char, _Traits>& _STLP_CALL
1.272 +operator>>(basic_istream<char, _Traits>& __in_str, unsigned char* __s) {
1.273 + __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
1.274 + return __in_str;
1.275 +}
1.276 +
1.277 +template <class _Traits>
1.278 +inline basic_istream<char, _Traits>& _STLP_CALL
1.279 +operator>>(basic_istream<char, _Traits>& __in_str, signed char* __s) {
1.280 + __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
1.281 + return __in_str;
1.282 +}
1.283 +
1.284 +//----------------------------------------------------------------------
1.285 +// istream manipulator.
1.286 +template <class _CharT, class _Traits>
1.287 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.288 +ws(basic_istream<_CharT, _Traits>& __istr) {
1.289 + if (!__istr.eof()) {
1.290 + typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
1.291 + _Sentry __sentry(__istr, _No_Skip_WS()); // Don't skip whitespace.
1.292 + if (__sentry)
1.293 + __istr._M_skip_whitespace(false);
1.294 + }
1.295 + return __istr;
1.296 +}
1.297 +
1.298 +// Helper functions for istream<>::sentry constructor.
1.299 +template <class _CharT, class _Traits>
1.300 +inline bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr) {
1.301 + if (__istr.good()) {
1.302 + if (__istr.tie())
1.303 + __istr.tie()->flush();
1.304 +
1.305 + __istr._M_skip_whitespace(true);
1.306 + }
1.307 +
1.308 + if (!__istr.good()) {
1.309 + __istr.setstate(ios_base::failbit);
1.310 + return false;
1.311 + } else
1.312 + return true;
1.313 +}
1.314 +
1.315 +template <class _CharT, class _Traits>
1.316 +inline bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr) {
1.317 + if (__istr.good()) {
1.318 + if (__istr.tie())
1.319 + __istr.tie()->flush();
1.320 +
1.321 + if (!__istr.rdbuf())
1.322 + __istr.setstate(ios_base::badbit);
1.323 + }
1.324 + else
1.325 + __istr.setstate(ios_base::failbit);
1.326 + return __istr.good();
1.327 +}
1.328 +
1.329 +//----------------------------------------------------------------------
1.330 +// Class iostream.
1.331 +template <class _CharT, class _Traits>
1.332 +class basic_iostream
1.333 + : public basic_istream<_CharT, _Traits>,
1.334 + public basic_ostream<_CharT, _Traits>
1.335 +{
1.336 +public:
1.337 + typedef basic_ios<_CharT, _Traits> _Basic_ios;
1.338 +
1.339 + explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
1.340 + virtual ~basic_iostream();
1.341 +};
1.342 +
1.343 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
1.344 +_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
1.345 +
1.346 +# if ! defined (_STLP_NO_WCHAR_T)
1.347 +_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
1.348 +# endif
1.349 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
1.350 +
1.351 +template <class _CharT, class _Traits>
1.352 +basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __istr)
1.353 +{ return __istr.rdbuf(); }
1.354 +
1.355 +_STLP_END_NAMESPACE
1.356 +
1.357 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
1.358 +# include <stl/_istream.c>
1.359 +#endif
1.360 +
1.361 +#endif /* _STLP_INTERNAL_ISTREAM */
1.362 +
1.363 +// Local Variables:
1.364 +// mode:C++
1.365 +// End: