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