williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@4
|
3 |
* Copyright (c) 1999
|
williamr@4
|
4 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1999
|
williamr@4
|
7 |
* Boris Fomitchev
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
10 |
* or implied. Any use is at your own risk.
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
13 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
14 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
15 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
16 |
* modified is included with the above copyright notice.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
*/
|
williamr@4
|
19 |
#ifndef _STLP_INTERNAL_ISTREAM_H
|
williamr@4
|
20 |
#define _STLP_INTERNAL_ISTREAM_H
|
williamr@4
|
21 |
|
williamr@4
|
22 |
// this block is included by _ostream.h, we include it here to lower #include level
|
williamr@4
|
23 |
# if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_CWCHAR_H)
|
williamr@4
|
24 |
# include <stl/_cwchar.h>
|
williamr@4
|
25 |
# endif
|
williamr@4
|
26 |
|
williamr@4
|
27 |
# ifndef _STLP_INTERNAL_IOS_H
|
williamr@4
|
28 |
# include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
|
williamr@4
|
29 |
# endif
|
williamr@4
|
30 |
|
williamr@4
|
31 |
#ifndef _STLP_INTERNAL_OSTREAM_H
|
williamr@4
|
32 |
# include <stl/_ostream.h> // Needed as a base class of basic_iostream.
|
williamr@4
|
33 |
#endif
|
williamr@4
|
34 |
|
williamr@4
|
35 |
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
|
williamr@4
|
36 |
# include <stl/_istreambuf_iterator.h>
|
williamr@4
|
37 |
#endif
|
williamr@4
|
38 |
|
williamr@4
|
39 |
#include <stl/_ctraits_fns.h> // Helper functions that allow char traits
|
williamr@4
|
40 |
// to be used as function objects.
|
williamr@4
|
41 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
42 |
|
williamr@4
|
43 |
template <class _CharT, class _Traits, class _Number>
|
williamr@4
|
44 |
ios_base::iostate _STLP_CALL
|
williamr@4
|
45 |
_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val);
|
williamr@4
|
46 |
|
williamr@4
|
47 |
#if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@4
|
48 |
template <class _CharT, class _Traits>
|
williamr@4
|
49 |
class _Isentry;
|
williamr@4
|
50 |
#endif
|
williamr@4
|
51 |
|
williamr@4
|
52 |
struct _No_Skip_WS {}; // Dummy class used by sentry.
|
williamr@4
|
53 |
|
williamr@4
|
54 |
template <class _CharT, class _Traits>
|
williamr@4
|
55 |
bool _M_init_skip(basic_istream<_CharT, _Traits>& __is);
|
williamr@4
|
56 |
template <class _CharT, class _Traits>
|
williamr@4
|
57 |
bool _M_init_noskip(basic_istream<_CharT, _Traits>& __is);
|
williamr@4
|
58 |
|
williamr@4
|
59 |
//----------------------------------------------------------------------
|
williamr@4
|
60 |
// Class basic_istream, a class that performs formatted input through
|
williamr@4
|
61 |
// a stream buffer.
|
williamr@4
|
62 |
|
williamr@4
|
63 |
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
|
williamr@4
|
64 |
// The default is declared in header <iosfwd>, and it isn't declared here
|
williamr@4
|
65 |
// because C++ language rules do not allow it to be declared twice.
|
williamr@4
|
66 |
|
williamr@4
|
67 |
template <class _CharT, class _Traits>
|
williamr@4
|
68 |
class basic_istream : virtual public basic_ios<_CharT, _Traits> {
|
williamr@4
|
69 |
public:
|
williamr@4
|
70 |
// Types
|
williamr@4
|
71 |
typedef _CharT char_type;
|
williamr@4
|
72 |
typedef typename _Traits::int_type int_type;
|
williamr@4
|
73 |
typedef typename _Traits::pos_type pos_type;
|
williamr@4
|
74 |
typedef typename _Traits::off_type off_type;
|
williamr@4
|
75 |
typedef _Traits traits_type;
|
williamr@4
|
76 |
typedef basic_ios<_CharT, _Traits> _Basic_ios;
|
williamr@4
|
77 |
typedef basic_istream<_CharT, _Traits> _Self;
|
williamr@4
|
78 |
|
williamr@4
|
79 |
typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
|
williamr@4
|
80 |
typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
|
williamr@4
|
81 |
typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
|
williamr@4
|
82 |
|
williamr@4
|
83 |
public: // Constructor and destructor.
|
williamr@4
|
84 |
_STLP_DECLSPEC explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf);
|
williamr@4
|
85 |
_STLP_DECLSPEC ~basic_istream();
|
williamr@4
|
86 |
|
williamr@4
|
87 |
public: // Nested sentry class.
|
williamr@4
|
88 |
|
williamr@4
|
89 |
public: // Hooks for manipulators. The arguments are
|
williamr@4
|
90 |
// function pointers.
|
williamr@4
|
91 |
_Self& operator>> (__istream_fn __f) { return __f(*this); }
|
williamr@4
|
92 |
_Self& operator>> (__ios_fn __f) { __f(*this); return *this; }
|
williamr@4
|
93 |
_Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
|
williamr@4
|
94 |
|
williamr@4
|
95 |
public: // Formatted input of numbers.
|
williamr@4
|
96 |
_Self& operator>> (short& __val) {
|
williamr@4
|
97 |
long __lval = __val;
|
williamr@4
|
98 |
unsigned short __uval;
|
williamr@4
|
99 |
_M_get_num(*this, __lval);
|
williamr@4
|
100 |
__val = __STATIC_CAST(short, __lval);
|
williamr@4
|
101 |
__uval = __lval;
|
williamr@4
|
102 |
// check if we lose digits
|
williamr@4
|
103 |
// if ((__val != __lval) && ((unsigned short)__val != __lval))
|
williamr@4
|
104 |
if ((__val != __lval) && ((long)__uval != __lval))
|
williamr@4
|
105 |
this->setstate(ios_base::failbit);
|
williamr@4
|
106 |
return *this;
|
williamr@4
|
107 |
}
|
williamr@4
|
108 |
_Self& operator>> (int& __val) {
|
williamr@4
|
109 |
long __lval = __val;
|
williamr@4
|
110 |
unsigned int __uval;
|
williamr@4
|
111 |
_M_get_num(*this, __lval);
|
williamr@4
|
112 |
__val = __lval;
|
williamr@4
|
113 |
__uval = __lval;
|
williamr@4
|
114 |
// check if we lose digits
|
williamr@4
|
115 |
// if ((__val != __lval) && ((unsigned int)__val != __lval))
|
williamr@4
|
116 |
if ((__val != __lval) && ((long)__uval != __lval))
|
williamr@4
|
117 |
this->setstate(ios_base::failbit);
|
williamr@4
|
118 |
return *this;
|
williamr@4
|
119 |
}
|
williamr@4
|
120 |
_Self& operator>> (unsigned short& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
121 |
_Self& operator>> (unsigned int& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
122 |
_Self& operator>> (long& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
123 |
_Self& operator>> (unsigned long& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
124 |
#ifdef _STLP_LONG_LONG
|
williamr@4
|
125 |
_Self& operator>> (_STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
126 |
_Self& operator>> (unsigned _STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
127 |
#endif
|
williamr@4
|
128 |
_Self& operator>> (float& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
129 |
_Self& operator>> (double& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
130 |
# ifndef _STLP_NO_LONG_DOUBLE
|
williamr@4
|
131 |
_Self& operator>> (long double& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
132 |
# endif
|
williamr@4
|
133 |
# ifndef _STLP_NO_BOOL
|
williamr@4
|
134 |
_Self& operator>> (bool& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
135 |
# endif
|
williamr@4
|
136 |
_Self& operator>> (void*& __val) { _M_get_num(*this, __val); return *this; }
|
williamr@4
|
137 |
|
williamr@4
|
138 |
public: // Copying characters into a streambuf.
|
williamr@4
|
139 |
_Self& operator>>(basic_streambuf<_CharT, _Traits>*);
|
williamr@4
|
140 |
|
williamr@4
|
141 |
public: // Unformatted input.
|
williamr@4
|
142 |
streamsize gcount() const { return _M_gcount; }
|
williamr@4
|
143 |
int_type peek();
|
williamr@4
|
144 |
|
williamr@4
|
145 |
public: // get() for single characters
|
williamr@4
|
146 |
int_type get();
|
williamr@4
|
147 |
_Self& get(char_type& __c);
|
williamr@4
|
148 |
|
williamr@4
|
149 |
public: // get() for character arrays.
|
williamr@4
|
150 |
_Self& get(char_type* __s, streamsize __n, char_type __delim);
|
williamr@4
|
151 |
_Self& get(char_type* __s, streamsize __n)
|
williamr@4
|
152 |
{ return get(__s, __n, this->widen('\n')); }
|
williamr@4
|
153 |
|
williamr@4
|
154 |
public: // get() for streambufs
|
williamr@4
|
155 |
_Self& get(basic_streambuf<_CharT, _Traits>& __buf,
|
williamr@4
|
156 |
char_type __delim);
|
williamr@4
|
157 |
_Self& get(basic_streambuf<_CharT, _Traits>& __buf)
|
williamr@4
|
158 |
{ return get(__buf, this->widen('\n')); }
|
williamr@4
|
159 |
|
williamr@4
|
160 |
public: // getline()
|
williamr@4
|
161 |
_Self& getline(char_type* __s, streamsize __n, char_type delim);
|
williamr@4
|
162 |
_Self& getline(char_type* __s, streamsize __n)
|
williamr@4
|
163 |
{ return getline(__s, __n, this->widen('\n')); }
|
williamr@4
|
164 |
|
williamr@4
|
165 |
public: // read(), readsome(), ignore()
|
williamr@4
|
166 |
_Self& ignore();
|
williamr@4
|
167 |
_Self& ignore(streamsize __n);
|
williamr@4
|
168 |
#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
|
williamr@4
|
169 |
inline
|
williamr@4
|
170 |
#endif
|
williamr@4
|
171 |
_Self& ignore(streamsize __n, int_type __delim);
|
williamr@4
|
172 |
|
williamr@4
|
173 |
_Self& read(char_type* __s, streamsize __n);
|
williamr@4
|
174 |
streamsize readsome(char_type* __s, streamsize __n);
|
williamr@4
|
175 |
|
williamr@4
|
176 |
public: // putback
|
williamr@4
|
177 |
_Self& putback(char_type __c);
|
williamr@4
|
178 |
_Self& unget();
|
williamr@4
|
179 |
|
williamr@4
|
180 |
public: // Positioning and buffer control.
|
williamr@4
|
181 |
int sync();
|
williamr@4
|
182 |
|
williamr@4
|
183 |
pos_type tellg();
|
williamr@4
|
184 |
_Self& seekg(pos_type __pos);
|
williamr@4
|
185 |
_Self& seekg(off_type, ios_base::seekdir);
|
williamr@4
|
186 |
|
williamr@4
|
187 |
public: // Helper functions for non-member extractors.
|
williamr@4
|
188 |
void _M_formatted_get(_CharT& __c);
|
williamr@4
|
189 |
void _M_formatted_get(_CharT* __s);
|
williamr@4
|
190 |
void _M_skip_whitespace(bool __set_failbit);
|
williamr@4
|
191 |
|
williamr@4
|
192 |
private: // Number of characters extracted by the
|
williamr@4
|
193 |
streamsize _M_gcount; // most recent unformatted input function.
|
williamr@4
|
194 |
|
williamr@4
|
195 |
public:
|
williamr@4
|
196 |
|
williamr@4
|
197 |
#if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@4
|
198 |
// If we are using DLL specs, we have not to use inner classes
|
williamr@4
|
199 |
// end class declaration here
|
williamr@4
|
200 |
typedef _Isentry<_CharT, _Traits> sentry;
|
williamr@4
|
201 |
};
|
williamr@4
|
202 |
# define sentry _Isentry
|
williamr@4
|
203 |
template <class _CharT, class _Traits>
|
williamr@4
|
204 |
class _Isentry {
|
williamr@4
|
205 |
typedef _Isentry<_CharT, _Traits> _Self;
|
williamr@4
|
206 |
# else
|
williamr@4
|
207 |
class sentry {
|
williamr@4
|
208 |
typedef sentry _Self;
|
williamr@4
|
209 |
#endif
|
williamr@4
|
210 |
|
williamr@4
|
211 |
private:
|
williamr@4
|
212 |
const bool _M_ok;
|
williamr@4
|
213 |
// basic_streambuf<_CharT, _Traits>* _M_buf;
|
williamr@4
|
214 |
|
williamr@4
|
215 |
public:
|
williamr@4
|
216 |
typedef _Traits traits_type;
|
williamr@4
|
217 |
|
williamr@4
|
218 |
explicit sentry(basic_istream<_CharT, _Traits>& __is,
|
williamr@4
|
219 |
bool __noskipws = false) :
|
williamr@4
|
220 |
_M_ok((__noskipws || !(__is.flags() & ios_base::skipws)) ? _M_init_noskip(__is) : _M_init_skip(__is) )
|
williamr@4
|
221 |
/* , _M_buf(__is.rdbuf()) */
|
williamr@4
|
222 |
{}
|
williamr@4
|
223 |
|
williamr@4
|
224 |
// Calling this constructor is the same as calling the previous one with
|
williamr@4
|
225 |
// __noskipws = true, except that it doesn't require a runtime test.
|
williamr@4
|
226 |
sentry(basic_istream<_CharT, _Traits>& __is, _No_Skip_WS) : /* _M_buf(__is.rdbuf()), */
|
williamr@4
|
227 |
_M_ok(_M_init_noskip(__is)) {}
|
williamr@4
|
228 |
|
williamr@4
|
229 |
~sentry() {}
|
williamr@4
|
230 |
|
williamr@4
|
231 |
operator bool() const { return _M_ok; }
|
williamr@4
|
232 |
|
williamr@4
|
233 |
private: // Disable assignment and copy constructor.
|
williamr@4
|
234 |
sentry(const _Self&) : _M_ok(false) {}
|
williamr@4
|
235 |
void operator=(const _Self&) {}
|
williamr@4
|
236 |
};
|
williamr@4
|
237 |
|
williamr@4
|
238 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@4
|
239 |
# undef sentry
|
williamr@4
|
240 |
# else
|
williamr@4
|
241 |
// close basic_istream class definition here
|
williamr@4
|
242 |
};
|
williamr@4
|
243 |
# endif
|
williamr@4
|
244 |
|
williamr@4
|
245 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@4
|
246 |
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
|
williamr@4
|
247 |
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
|
williamr@4
|
248 |
# if ! defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
249 |
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
|
williamr@4
|
250 |
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
|
williamr@4
|
251 |
# endif
|
williamr@4
|
252 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@4
|
253 |
|
williamr@4
|
254 |
// Non-member character and string extractor functions.
|
williamr@4
|
255 |
|
williamr@4
|
256 |
template <class _CharT, class _Traits>
|
williamr@4
|
257 |
inline basic_istream<_CharT, _Traits>& _STLP_CALL
|
williamr@4
|
258 |
operator>>(basic_istream<_CharT, _Traits>& __stl_in, _CharT& __c) {
|
williamr@4
|
259 |
__stl_in._M_formatted_get(__c);
|
williamr@4
|
260 |
return __stl_in;
|
williamr@4
|
261 |
}
|
williamr@4
|
262 |
|
williamr@4
|
263 |
template <class _Traits>
|
williamr@4
|
264 |
inline basic_istream<char, _Traits>& _STLP_CALL
|
williamr@4
|
265 |
operator>>(basic_istream<char, _Traits>& __stl_in, unsigned char& __c) {
|
williamr@4
|
266 |
__stl_in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
|
williamr@4
|
267 |
return __stl_in;
|
williamr@4
|
268 |
}
|
williamr@4
|
269 |
|
williamr@4
|
270 |
template <class _Traits>
|
williamr@4
|
271 |
inline basic_istream<char, _Traits>& _STLP_CALL
|
williamr@4
|
272 |
operator>>(basic_istream<char, _Traits>& __stl_in, signed char& __c) {
|
williamr@4
|
273 |
__stl_in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
|
williamr@4
|
274 |
return __stl_in;
|
williamr@4
|
275 |
}
|
williamr@4
|
276 |
|
williamr@4
|
277 |
template <class _CharT, class _Traits>
|
williamr@4
|
278 |
inline basic_istream<_CharT, _Traits>& _STLP_CALL
|
williamr@4
|
279 |
operator>>(basic_istream<_CharT, _Traits>& __stl_in, _CharT* __s) {
|
williamr@4
|
280 |
__stl_in._M_formatted_get(__s);
|
williamr@4
|
281 |
return __stl_in;
|
williamr@4
|
282 |
}
|
williamr@4
|
283 |
|
williamr@4
|
284 |
template <class _Traits>
|
williamr@4
|
285 |
inline basic_istream<char, _Traits>& _STLP_CALL
|
williamr@4
|
286 |
operator>>(basic_istream<char, _Traits>& __stl_in, unsigned char* __s) {
|
williamr@4
|
287 |
__stl_in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
|
williamr@4
|
288 |
return __stl_in;
|
williamr@4
|
289 |
}
|
williamr@4
|
290 |
|
williamr@4
|
291 |
template <class _Traits>
|
williamr@4
|
292 |
inline basic_istream<char, _Traits>& _STLP_CALL
|
williamr@4
|
293 |
operator>>(basic_istream<char, _Traits>& __stl_in, signed char* __s) {
|
williamr@4
|
294 |
__stl_in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
|
williamr@4
|
295 |
return __stl_in;
|
williamr@4
|
296 |
}
|
williamr@4
|
297 |
|
williamr@4
|
298 |
//----------------------------------------------------------------------
|
williamr@4
|
299 |
// istream manipulator.
|
williamr@4
|
300 |
template <class _CharT, class _Traits>
|
williamr@4
|
301 |
basic_istream<_CharT, _Traits>& _STLP_CALL
|
williamr@4
|
302 |
ws(basic_istream<_CharT, _Traits>& __is);
|
williamr@4
|
303 |
|
williamr@4
|
304 |
//----------------------------------------------------------------------
|
williamr@4
|
305 |
// Class iostream.
|
williamr@4
|
306 |
|
williamr@4
|
307 |
template <class _CharT, class _Traits>
|
williamr@4
|
308 |
class basic_iostream
|
williamr@4
|
309 |
: public basic_istream<_CharT, _Traits>,
|
williamr@4
|
310 |
public basic_ostream<_CharT, _Traits>
|
williamr@4
|
311 |
{
|
williamr@4
|
312 |
public:
|
williamr@4
|
313 |
typedef basic_ios<_CharT, _Traits> _Basic_ios;
|
williamr@4
|
314 |
|
williamr@4
|
315 |
_STLP_DECLSPEC explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
|
williamr@4
|
316 |
_STLP_DECLSPEC virtual ~basic_iostream();
|
williamr@4
|
317 |
};
|
williamr@4
|
318 |
|
williamr@4
|
319 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@4
|
320 |
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
|
williamr@4
|
321 |
# if ! defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
322 |
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
|
williamr@4
|
323 |
# endif
|
williamr@4
|
324 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@4
|
325 |
|
williamr@4
|
326 |
template <class _CharT, class _Traits>
|
williamr@4
|
327 |
basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __is)
|
williamr@4
|
328 |
{
|
williamr@4
|
329 |
return __is.rdbuf();
|
williamr@4
|
330 |
}
|
williamr@4
|
331 |
|
williamr@4
|
332 |
_STLP_END_NAMESPACE
|
williamr@4
|
333 |
|
williamr@4
|
334 |
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@4
|
335 |
# include <stl/_istream.c>
|
williamr@4
|
336 |
# endif
|
williamr@4
|
337 |
|
williamr@4
|
338 |
#endif /* _STLP_INTERNAL_ISTREAM_H */
|
williamr@4
|
339 |
|
williamr@4
|
340 |
// Local Variables:
|
williamr@4
|
341 |
// mode:C++
|
williamr@4
|
342 |
// End:
|