3
* Silicon Graphics Computer Systems, Inc.
8
* This material is provided "as is", with absolutely no warranty expressed
9
* or implied. Any use is at your own risk.
11
* Permission to use or copy this software for any purpose is hereby granted
12
* without fee, provided the above notices are retained on all copies.
13
* Permission to modify the code and to distribute modified code is granted,
14
* provided the above notices are retained, and a notice that the code was
15
* modified is included with the above copyright notice.
18
#ifndef _STLP_INTERNAL_ISTREAM_H
19
#define _STLP_INTERNAL_ISTREAM_H
21
// this block is included by _ostream.h, we include it here to lower #include level
22
# if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_CWCHAR_H)
23
# include <stl/_cwchar.h>
26
# ifndef _STLP_INTERNAL_IOS_H
27
# include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
30
#ifndef _STLP_INTERNAL_OSTREAM_H
31
# include <stl/_ostream.h> // Needed as a base class of basic_iostream.
34
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
35
# include <stl/_istreambuf_iterator.h>
38
#include <stl/_ctraits_fns.h> // Helper functions that allow char traits
39
// to be used as function objects.
42
template <class _CharT, class _Traits, class _Number>
43
ios_base::iostate _STLP_CALL
44
_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val);
46
#if defined (_STLP_USE_TEMPLATE_EXPORT)
47
template <class _CharT, class _Traits>
51
struct _No_Skip_WS {}; // Dummy class used by sentry.
53
template <class _CharT, class _Traits>
54
bool _M_init_skip(basic_istream<_CharT, _Traits>& __is);
55
template <class _CharT, class _Traits>
56
bool _M_init_noskip(basic_istream<_CharT, _Traits>& __is);
58
//----------------------------------------------------------------------
59
// Class basic_istream, a class that performs formatted input through
62
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
63
// The default is declared in header <iosfwd>, and it isn't declared here
64
// because C++ language rules do not allow it to be declared twice.
66
template <class _CharT, class _Traits>
67
class basic_istream : virtual public basic_ios<_CharT, _Traits> {
70
typedef _CharT char_type;
71
typedef typename _Traits::int_type int_type;
72
typedef typename _Traits::pos_type pos_type;
73
typedef typename _Traits::off_type off_type;
74
typedef _Traits traits_type;
75
typedef basic_ios<_CharT, _Traits> _Basic_ios;
76
typedef basic_istream<_CharT, _Traits> _Self;
78
typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
79
typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
80
typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
82
public: // Constructor and destructor.
83
explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
84
basic_ios<_CharT, _Traits>(), _M_gcount(0) {
89
public: // Nested sentry class.
91
public: // Hooks for manipulators. The arguments are
93
_Self& operator>> (__istream_fn __f) { return __f(*this); }
94
_Self& operator>> (__ios_fn __f) { __f(*this); return *this; }
95
_Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
97
public: // Formatted input of numbers.
98
_Self& operator>> (short& __val) {
100
unsigned short __uval;
101
_M_get_num(*this, __lval);
102
__val = __STATIC_CAST(short, __lval);
104
// check if we lose digits
105
// if ((__val != __lval) && ((unsigned short)__val != __lval))
106
if ((__val != __lval) && ((long)__uval != __lval))
107
this->setstate(ios_base::failbit);
110
_Self& operator>> (int& __val) {
113
_M_get_num(*this, __lval);
116
// check if we lose digits
117
// if ((__val != __lval) && ((unsigned int)__val != __lval))
118
if ((__val != __lval) && ((long)__uval != __lval))
119
this->setstate(ios_base::failbit);
122
_Self& operator>> (unsigned short& __val) { _M_get_num(*this, __val); return *this; }
123
_Self& operator>> (unsigned int& __val) { _M_get_num(*this, __val); return *this; }
124
_Self& operator>> (long& __val) { _M_get_num(*this, __val); return *this; }
125
_Self& operator>> (unsigned long& __val) { _M_get_num(*this, __val); return *this; }
126
#ifdef _STLP_LONG_LONG
127
_Self& operator>> (_STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
128
_Self& operator>> (unsigned _STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
130
_Self& operator>> (float& __val) { _M_get_num(*this, __val); return *this; }
131
_Self& operator>> (double& __val) { _M_get_num(*this, __val); return *this; }
132
# ifndef _STLP_NO_LONG_DOUBLE
133
_Self& operator>> (long double& __val) { _M_get_num(*this, __val); return *this; }
135
# ifndef _STLP_NO_BOOL
136
_Self& operator>> (bool& __val) { _M_get_num(*this, __val); return *this; }
138
_Self& operator>> (void*& __val) { _M_get_num(*this, __val); return *this; }
140
public: // Copying characters into a streambuf.
141
_Self& operator>>(basic_streambuf<_CharT, _Traits>*);
143
public: // Unformatted input.
144
streamsize gcount() const { return _M_gcount; }
147
public: // get() for single characters
149
_Self& get(char_type& __c);
151
public: // get() for character arrays.
152
_Self& get(char_type* __s, streamsize __n, char_type __delim);
153
_Self& get(char_type* __s, streamsize __n)
154
{ return get(__s, __n, this->widen('\n')); }
156
public: // get() for streambufs
157
_Self& get(basic_streambuf<_CharT, _Traits>& __buf,
159
_Self& get(basic_streambuf<_CharT, _Traits>& __buf)
160
{ return get(__buf, this->widen('\n')); }
163
_Self& getline(char_type* __s, streamsize __n, char_type delim);
164
_Self& getline(char_type* __s, streamsize __n)
165
{ return getline(__s, __n, this->widen('\n')); }
167
public: // read(), readsome(), ignore()
169
_Self& ignore(streamsize __n);
170
#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
173
_Self& ignore(streamsize __n, int_type __delim);
175
_Self& read(char_type* __s, streamsize __n);
176
streamsize readsome(char_type* __s, streamsize __n);
179
_Self& putback(char_type __c);
182
public: // Positioning and buffer control.
186
_Self& seekg(pos_type __pos);
187
_Self& seekg(off_type, ios_base::seekdir);
189
public: // Helper functions for non-member extractors.
190
void _M_formatted_get(_CharT& __c);
191
void _M_formatted_get(_CharT* __s);
192
void _M_skip_whitespace(bool __set_failbit);
194
private: // Number of characters extracted by the
195
streamsize _M_gcount; // most recent unformatted input function.
199
#if defined (_STLP_USE_TEMPLATE_EXPORT)
200
// If we are using DLL specs, we have not to use inner classes
201
// end class declaration here
202
typedef _Isentry<_CharT, _Traits> sentry;
204
# define sentry _Isentry
205
template <class _CharT, class _Traits>
207
typedef _Isentry<_CharT, _Traits> _Self;
210
typedef sentry _Self;
215
// basic_streambuf<_CharT, _Traits>* _M_buf;
218
typedef _Traits traits_type;
220
explicit sentry(basic_istream<_CharT, _Traits>& __is,
221
bool __noskipws = false) :
222
_M_ok((__noskipws || !(__is.flags() & ios_base::skipws)) ? _M_init_noskip(__is) : _M_init_skip(__is) )
223
/* , _M_buf(__is.rdbuf()) */
226
// Calling this constructor is the same as calling the previous one with
227
// __noskipws = true, except that it doesn't require a runtime test.
228
sentry(basic_istream<_CharT, _Traits>& __is, _No_Skip_WS) : /* _M_buf(__is.rdbuf()), */
229
_M_ok(_M_init_noskip(__is)) {}
233
operator bool() const { return _M_ok; }
235
private: // Disable assignment and copy constructor.
236
sentry(const _Self&) : _M_ok(false) {}
237
void operator=(const _Self&) {}
240
# if defined (_STLP_USE_TEMPLATE_EXPORT)
243
// close basic_istream class definition here
247
# if defined (_STLP_USE_TEMPLATE_EXPORT)
248
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
249
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
250
# if ! defined (_STLP_NO_WCHAR_T)
251
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
252
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
254
# endif /* _STLP_USE_TEMPLATE_EXPORT */
256
// Non-member character and string extractor functions.
258
template <class _CharT, class _Traits>
259
inline basic_istream<_CharT, _Traits>& _STLP_CALL
260
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) {
261
__in._M_formatted_get(__c);
265
template <class _Traits>
266
inline basic_istream<char, _Traits>& _STLP_CALL
267
operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) {
268
__in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
272
template <class _Traits>
273
inline basic_istream<char, _Traits>& _STLP_CALL
274
operator>>(basic_istream<char, _Traits>& __in, signed char& __c) {
275
__in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
279
template <class _CharT, class _Traits>
280
inline basic_istream<_CharT, _Traits>& _STLP_CALL
281
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) {
282
__in._M_formatted_get(__s);
286
template <class _Traits>
287
inline basic_istream<char, _Traits>& _STLP_CALL
288
operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) {
289
__in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
293
template <class _Traits>
294
inline basic_istream<char, _Traits>& _STLP_CALL
295
operator>>(basic_istream<char, _Traits>& __in, signed char* __s) {
296
__in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
300
//----------------------------------------------------------------------
301
// istream manipulator.
302
template <class _CharT, class _Traits>
303
basic_istream<_CharT, _Traits>& _STLP_CALL
304
ws(basic_istream<_CharT, _Traits>& __is);
306
//----------------------------------------------------------------------
309
template <class _CharT, class _Traits>
311
: public basic_istream<_CharT, _Traits>,
312
public basic_ostream<_CharT, _Traits>
315
typedef basic_ios<_CharT, _Traits> _Basic_ios;
317
explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
318
virtual ~basic_iostream();
321
# if defined (_STLP_USE_TEMPLATE_EXPORT)
322
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
323
# if ! defined (_STLP_NO_WCHAR_T)
324
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
326
# endif /* _STLP_USE_TEMPLATE_EXPORT */
328
template <class _CharT, class _Traits>
329
basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __is)
336
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
337
# include <stl/_istream.c>
340
#endif /* _STLP_INTERNAL_ISTREAM_H */