]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/istream
* many: Replace uses of __GXX_EXPERIMENTAL_CXX0X__ with __cplusplus.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / istream
CommitLineData
54c1bf78 1// Input streams -*- C++ -*-
de96ac46 2
f4e39278 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
d632488a 4// 2006, 2007, 2008, 2009, 2010, 2011, 2012
d29cc32f 5// Free Software Foundation, Inc.
de96ac46
BK
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
748086b7 10// Free Software Foundation; either version 3, or (at your option)
de96ac46
BK
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
748086b7
JJ
18// Under Section 7 of GPL version 3, you are granted additional
19// permissions described in the GCC Runtime Library Exception, version
20// 3.1, as published by the Free Software Foundation.
21
22// You should have received a copy of the GNU General Public License and
23// a copy of the GCC Runtime Library Exception along with this program;
24// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25// <http://www.gnu.org/licenses/>.
de96ac46 26
54c1bf78
BK
27//
28// ISO C++ 14882: 27.6.1 Input streams
29//
30
f910786b 31/** @file include/istream
0aa06b18 32 * This is a Standard C++ Library header.
2f9d51b8
PE
33 */
34
1143680e
SE
35#ifndef _GLIBCXX_ISTREAM
36#define _GLIBCXX_ISTREAM 1
54c1bf78
BK
37
38#pragma GCC system_header
39
40#include <ios>
f4e39278 41#include <ostream>
54c1bf78 42
12ffa228
BK
43namespace std _GLIBCXX_VISIBILITY(default)
44{
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 46
840ceb34 47 /**
7897a1c0 48 * @brief Template class basic_istream.
5b9daa7e 49 * @ingroup io
840ceb34 50 *
d632488a
BK
51 * @tparam _CharT Type of character stream.
52 * @tparam _Traits Traits for character type, defaults to
53 * char_traits<_CharT>.
54 *
840ceb34
PE
55 * This is the base class for all input streams. It provides text
56 * formatting of all builtin types, and communicates with any class
57 * derived from basic_streambuf to do the actual input.
58 */
54c1bf78
BK
59 template<typename _CharT, typename _Traits>
60 class basic_istream : virtual public basic_ios<_CharT, _Traits>
61 {
62 public:
63 // Types (inherited from basic_ios (27.4.4)):
7897a1c0 64 typedef _CharT char_type;
54c1bf78
BK
65 typedef typename _Traits::int_type int_type;
66 typedef typename _Traits::pos_type pos_type;
67 typedef typename _Traits::off_type off_type;
7897a1c0
BK
68 typedef _Traits traits_type;
69
54c1bf78
BK
70 // Non-standard Types:
71 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
72 typedef basic_ios<_CharT, _Traits> __ios_type;
73 typedef basic_istream<_CharT, _Traits> __istream_type;
7897a1c0 74 typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
2803847d 75 __num_get_type;
7897a1c0 76 typedef ctype<_CharT> __ctype_type;
54c1bf78
BK
77
78 protected:
79 // Data Members:
840ceb34 80 /**
840ceb34
PE
81 * The number of characters extracted in the previous unformatted
82 * function; see gcount().
840ceb34 83 */
54c1bf78
BK
84 streamsize _M_gcount;
85
86 public:
840ceb34
PE
87 /**
88 * @brief Base constructor.
89 *
90 * This ctor is almost never called by the user directly, rather from
91 * derived classes' initialization lists, which pass a pointer to
92 * their own stream buffer.
93 */
b3aaa617
PC
94 explicit
95 basic_istream(__streambuf_type* __sb)
96 : _M_gcount(streamsize(0))
d29cc32f 97 { this->init(__sb); }
54c1bf78 98
840ceb34
PE
99 /**
100 * @brief Base destructor.
101 *
102 * This does very little apart from providing a virtual base dtor.
103 */
7897a1c0
BK
104 virtual
105 ~basic_istream()
54c1bf78
BK
106 { _M_gcount = streamsize(0); }
107
7897a1c0 108 /// Safe prefix/suffix operations.
54c1bf78
BK
109 class sentry;
110 friend class sentry;
111
840ceb34
PE
112 //@{
113 /**
114 * @brief Interface for manipulators.
115 *
28dac70a 116 * Manipulators such as @c std::ws and @c std::dec use these
7897a1c0
BK
117 * functions in constructs like
118 * <code>std::cin >> std::ws</code>.
2a60a9f6 119 * For more information, see the iomanip header.
840ceb34 120 */
f7ab3fd1
PC
121 __istream_type&
122 operator>>(__istream_type& (*__pf)(__istream_type&))
123 { return __pf(*this); }
54c1bf78 124
f7ab3fd1
PC
125 __istream_type&
126 operator>>(__ios_type& (*__pf)(__ios_type&))
7897a1c0 127 {
f7ab3fd1
PC
128 __pf(*this);
129 return *this;
130 }
54c1bf78 131
f7ab3fd1
PC
132 __istream_type&
133 operator>>(ios_base& (*__pf)(ios_base&))
134 {
135 __pf(*this);
136 return *this;
137 }
840ceb34 138 //@}
7897a1c0
BK
139
140 //@{
840ceb34 141 /**
7897a1c0 142 * @name Extractors
840ceb34
PE
143 *
144 * All the @c operator>> functions (aka <em>formatted input
145 * functions</em>) have some common behavior. Each starts by
146 * constructing a temporary object of type std::basic_istream::sentry
147 * with the second argument (noskipws) set to false. This has several
148 * effects, concluding with the setting of a status flag; see the
149 * sentry documentation for more.
150 *
151 * If the sentry status is good, the function tries to extract
152 * whatever data is appropriate for the type of the argument.
153 *
154 * If an exception is thrown during extraction, ios_base::badbit
155 * will be turned on in the stream's error state without causing an
156 * ios_base::failure to be thrown. The original exception will then
157 * be rethrown.
158 */
7897a1c0 159
840ceb34
PE
160 //@{
161 /**
7897a1c0
BK
162 * @brief Integer arithmetic extractors
163 * @param __n A variable of builtin integral type.
840ceb34
PE
164 * @return @c *this if successful
165 *
166 * These functions use the stream's current locale (specifically, the
167 * @c num_get facet) to parse the input data.
168 */
7897a1c0 169 __istream_type&
49d5c016
PC
170 operator>>(bool& __n)
171 { return _M_extract(__n); }
7897a1c0
BK
172
173 __istream_type&
e7968bd8 174 operator>>(short& __n);
7897a1c0
BK
175
176 __istream_type&
49d5c016
PC
177 operator>>(unsigned short& __n)
178 { return _M_extract(__n); }
54c1bf78 179
7897a1c0 180 __istream_type&
e7968bd8 181 operator>>(int& __n);
7897a1c0
BK
182
183 __istream_type&
49d5c016
PC
184 operator>>(unsigned int& __n)
185 { return _M_extract(__n); }
54c1bf78 186
7897a1c0 187 __istream_type&
49d5c016
PC
188 operator>>(long& __n)
189 { return _M_extract(__n); }
7897a1c0
BK
190
191 __istream_type&
49d5c016
PC
192 operator>>(unsigned long& __n)
193 { return _M_extract(__n); }
54c1bf78 194
3d7c150e 195#ifdef _GLIBCXX_USE_LONG_LONG
7897a1c0 196 __istream_type&
49d5c016
PC
197 operator>>(long long& __n)
198 { return _M_extract(__n); }
54c1bf78 199
7897a1c0 200 __istream_type&
49d5c016
PC
201 operator>>(unsigned long long& __n)
202 { return _M_extract(__n); }
725dc051 203#endif
7897a1c0 204 //@}
54c1bf78 205
7897a1c0
BK
206 //@{
207 /**
208 * @brief Floating point arithmetic extractors
209 * @param __f A variable of builtin floating point type.
210 * @return @c *this if successful
211 *
212 * These functions use the stream's current locale (specifically, the
213 * @c num_get facet) to parse the input data.
214 */
215 __istream_type&
49d5c016
PC
216 operator>>(float& __f)
217 { return _M_extract(__f); }
54c1bf78 218
7897a1c0 219 __istream_type&
49d5c016
PC
220 operator>>(double& __f)
221 { return _M_extract(__f); }
54c1bf78 222
7897a1c0 223 __istream_type&
49d5c016
PC
224 operator>>(long double& __f)
225 { return _M_extract(__f); }
7897a1c0 226 //@}
54c1bf78 227
7897a1c0
BK
228 /**
229 * @brief Basic arithmetic extractors
230 * @param __p A variable of pointer type.
231 * @return @c *this if successful
232 *
233 * These functions use the stream's current locale (specifically, the
234 * @c num_get facet) to parse the input data.
235 */
236 __istream_type&
49d5c016
PC
237 operator>>(void*& __p)
238 { return _M_extract(__p); }
54c1bf78 239
840ceb34
PE
240 /**
241 * @brief Extracting into another streambuf.
93c66bc6 242 * @param __sb A pointer to a streambuf
840ceb34
PE
243 *
244 * This function behaves like one of the basic arithmetic extractors,
0f35d192 245 * in that it also constructs a sentry object and has the same error
840ceb34
PE
246 * handling behavior.
247 *
7897a1c0 248 * If @p __sb is NULL, the stream will set failbit in its error state.
840ceb34
PE
249 *
250 * Characters are extracted from this stream and inserted into the
7897a1c0 251 * @p __sb streambuf until one of the following occurs:
840ceb34
PE
252 *
253 * - the input stream reaches end-of-file,
254 * - insertion into the output buffer fails (in this case, the
255 * character that would have been inserted is not extracted), or
256 * - an exception occurs (and in this case is caught)
257 *
258 * If the function inserts no characters, failbit is set.
259 */
7897a1c0 260 __istream_type&
54c1bf78 261 operator>>(__streambuf_type* __sb);
840ceb34 262 //@}
7897a1c0 263
840ceb34
PE
264 // [27.6.1.3] unformatted input
265 /**
266 * @brief Character counting
267 * @return The number of characters extracted by the previous
268 * unformatted input function dispatched for this stream.
269 */
7897a1c0
BK
270 streamsize
271 gcount() const
54c1bf78 272 { return _M_gcount; }
7897a1c0
BK
273
274 //@{
840ceb34
PE
275 /**
276 * @name Unformatted Input Functions
277 *
278 * All the unformatted input functions have some common behavior.
279 * Each starts by constructing a temporary object of type
280 * std::basic_istream::sentry with the second argument (noskipws)
281 * set to true. This has several effects, concluding with the
282 * setting of a status flag; see the sentry documentation for more.
283 *
284 * If the sentry status is good, the function tries to extract
285 * whatever data is appropriate for the type of the argument.
286 *
287 * The number of characters extracted is stored for later retrieval
288 * by gcount().
289 *
290 * If an exception is thrown during extraction, ios_base::badbit
291 * will be turned on in the stream's error state without causing an
292 * ios_base::failure to be thrown. The original exception will then
293 * be rethrown.
294 */
7897a1c0 295
840ceb34
PE
296 /**
297 * @brief Simple extraction.
298 * @return A character, or eof().
299 *
300 * Tries to extract a character. If none are available, sets failbit
301 * and returns traits::eof().
302 */
7897a1c0 303 int_type
840ceb34
PE
304 get();
305
306 /**
307 * @brief Simple extraction.
93c66bc6 308 * @param __c The character in which to store data.
840ceb34
PE
309 * @return *this
310 *
93c66bc6 311 * Tries to extract a character and store it in @a __c. If none are
840ceb34
PE
312 * available, sets failbit and returns traits::eof().
313 *
314 * @note This function is not overloaded on signed char and
315 * unsigned char.
316 */
7897a1c0 317 __istream_type&
54c1bf78
BK
318 get(char_type& __c);
319
840ceb34
PE
320 /**
321 * @brief Simple multiple-character extraction.
93c66bc6
BK
322 * @param __s Pointer to an array.
323 * @param __n Maximum number of characters to store in @a __s.
324 * @param __delim A "stop" character.
840ceb34
PE
325 * @return *this
326 *
93c66bc6 327 * Characters are extracted and stored into @a __s until one of the
840ceb34
PE
328 * following happens:
329 *
93c66bc6 330 * - @c __n-1 characters are stored
840ceb34 331 * - the input sequence reaches EOF
93c66bc6 332 * - the next character equals @a __delim, in which case the character
840ceb34
PE
333 * is not extracted
334 *
335 * If no characters are stored, failbit is set in the stream's error
336 * state.
337 *
338 * In any case, a null character is stored into the next location in
339 * the array.
340 *
341 * @note This function is not overloaded on signed char and
342 * unsigned char.
343 */
7897a1c0 344 __istream_type&
54c1bf78
BK
345 get(char_type* __s, streamsize __n, char_type __delim);
346
840ceb34
PE
347 /**
348 * @brief Simple multiple-character extraction.
93c66bc6
BK
349 * @param __s Pointer to an array.
350 * @param __n Maximum number of characters to store in @a s.
840ceb34
PE
351 * @return *this
352 *
93c66bc6 353 * Returns @c get(__s,__n,widen(&apos;\\n&apos;)).
840ceb34 354 */
7897a1c0 355 __istream_type&
54c1bf78
BK
356 get(char_type* __s, streamsize __n)
357 { return this->get(__s, __n, this->widen('\n')); }
358
840ceb34
PE
359 /**
360 * @brief Extraction into another streambuf.
93c66bc6
BK
361 * @param __sb A streambuf in which to store data.
362 * @param __delim A "stop" character.
840ceb34
PE
363 * @return *this
364 *
93c66bc6 365 * Characters are extracted and inserted into @a __sb until one of the
840ceb34
PE
366 * following happens:
367 *
368 * - the input sequence reaches EOF
369 * - insertion into the output buffer fails (in this case, the
370 * character that would have been inserted is not extracted)
93c66bc6 371 * - the next character equals @a __delim (in this case, the character
840ceb34
PE
372 * is not extracted)
373 * - an exception occurs (and in this case is caught)
374 *
375 * If no characters are stored, failbit is set in the stream's error
376 * state.
377 */
54c1bf78
BK
378 __istream_type&
379 get(__streambuf_type& __sb, char_type __delim);
380
840ceb34
PE
381 /**
382 * @brief Extraction into another streambuf.
93c66bc6 383 * @param __sb A streambuf in which to store data.
840ceb34
PE
384 * @return *this
385 *
93c66bc6 386 * Returns @c get(__sb,widen(&apos;\\n&apos;)).
840ceb34 387 */
f7ab3fd1 388 __istream_type&
54c1bf78
BK
389 get(__streambuf_type& __sb)
390 { return this->get(__sb, this->widen('\n')); }
391
840ceb34
PE
392 /**
393 * @brief String extraction.
93c66bc6
BK
394 * @param __s A character array in which to store the data.
395 * @param __n Maximum number of characters to extract.
396 * @param __delim A "stop" character.
840ceb34
PE
397 * @return *this
398 *
93c66bc6 399 * Extracts and stores characters into @a __s until one of the
840ceb34
PE
400 * following happens. Note that these criteria are required to be
401 * tested in the order listed here, to allow an input line to exactly
93c66bc6 402 * fill the @a __s array without setting failbit.
840ceb34
PE
403 *
404 * -# the input sequence reaches end-of-file, in which case eofbit
405 * is set in the stream error state
93c66bc6 406 * -# the next character equals @c __delim, in which case the character
840ceb34 407 * is extracted (and therefore counted in @c gcount()) but not stored
93c66bc6 408 * -# @c __n-1 characters are stored, in which case failbit is set
840ceb34
PE
409 * in the stream error state
410 *
411 * If no characters are extracted, failbit is set. (An empty line of
412 * input should therefore not cause failbit to be set.)
413 *
414 * In any case, a null character is stored in the next location in
415 * the array.
416 */
7897a1c0 417 __istream_type&
54c1bf78
BK
418 getline(char_type* __s, streamsize __n, char_type __delim);
419
840ceb34
PE
420 /**
421 * @brief String extraction.
93c66bc6
BK
422 * @param __s A character array in which to store the data.
423 * @param __n Maximum number of characters to extract.
840ceb34
PE
424 * @return *this
425 *
93c66bc6 426 * Returns @c getline(__s,__n,widen(&apos;\\n&apos;)).
840ceb34 427 */
7897a1c0 428 __istream_type&
54c1bf78
BK
429 getline(char_type* __s, streamsize __n)
430 { return this->getline(__s, __n, this->widen('\n')); }
431
840ceb34
PE
432 /**
433 * @brief Discarding characters
93c66bc6
BK
434 * @param __n Number of characters to discard.
435 * @param __delim A "stop" character.
840ceb34
PE
436 * @return *this
437 *
438 * Extracts characters and throws them away until one of the
439 * following happens:
93c66bc6 440 * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
840ceb34
PE
441 * characters are extracted
442 * - the input sequence reaches end-of-file
93c66bc6 443 * - the next character equals @a __delim (in this case, the character
840ceb34 444 * is extracted); note that this condition will never occur if
93c66bc6 445 * @a __delim equals @c traits::eof().
80dddedc
PC
446 *
447 * NB: Provide three overloads, instead of the single function
448 * (with defaults) mandated by the Standard: this leads to a
449 * better performing implementation, while still conforming to
450 * the Standard.
840ceb34 451 */
7897a1c0 452 __istream_type&
93c66bc6 453 ignore(streamsize __n, int_type __delim);
80dddedc 454
7897a1c0 455 __istream_type&
80dddedc
PC
456 ignore(streamsize __n);
457
7897a1c0 458 __istream_type&
93c66bc6
BK
459 ignore();
460
840ceb34
PE
461 /**
462 * @brief Looking ahead in the stream
463 * @return The next character, or eof().
464 *
465 * If, after constructing the sentry object, @c good() is false,
466 * returns @c traits::eof(). Otherwise reads but does not extract
467 * the next input character.
468 */
7897a1c0 469 int_type
840ceb34 470 peek();
7897a1c0 471
840ceb34
PE
472 /**
473 * @brief Extraction without delimiters.
93c66bc6
BK
474 * @param __s A character array.
475 * @param __n Maximum number of characters to store.
840ceb34
PE
476 * @return *this
477 *
478 * If the stream state is @c good(), extracts characters and stores
93c66bc6
BK
479 * them into @a __s until one of the following happens:
480 * - @a __n characters are stored
840ceb34
PE
481 * - the input sequence reaches end-of-file, in which case the error
482 * state is set to @c failbit|eofbit.
483 *
484 * @note This function is not overloaded on signed char and
485 * unsigned char.
486 */
7897a1c0 487 __istream_type&
54c1bf78
BK
488 read(char_type* __s, streamsize __n);
489
840ceb34
PE
490 /**
491 * @brief Extraction until the buffer is exhausted, but no more.
93c66bc6
BK
492 * @param __s A character array.
493 * @param __n Maximum number of characters to store.
840ceb34
PE
494 * @return The number of characters extracted.
495 *
93c66bc6 496 * Extracts characters and stores them into @a __s depending on the
840ceb34
PE
497 * number of characters remaining in the streambuf's buffer,
498 * @c rdbuf()->in_avail(), called @c A here:
499 * - if @c A @c == @c -1, sets eofbit and extracts no characters
500 * - if @c A @c == @c 0, extracts no characters
501 * - if @c A @c > @c 0, extracts @c min(A,n)
502 *
503 * The goal is to empty the current buffer, and to not request any
504 * more from the external input sequence controlled by the streambuf.
505 */
7897a1c0 506 streamsize
54c1bf78 507 readsome(char_type* __s, streamsize __n);
7897a1c0 508
840ceb34
PE
509 /**
510 * @brief Unextracting a single character.
93c66bc6 511 * @param __c The character to push back into the input stream.
840ceb34
PE
512 * @return *this
513 *
514 * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
515 *
516 * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
517 * the error state.
518 *
b3b66298
PC
519 * @note This function first clears eofbit. Since no characters
520 * are extracted, the next call to @c gcount() will return 0,
521 * as required by DR 60.
840ceb34 522 */
7897a1c0 523 __istream_type&
54c1bf78
BK
524 putback(char_type __c);
525
840ceb34
PE
526 /**
527 * @brief Unextracting the previous character.
528 * @return *this
529 *
530 * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
531 *
532 * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
533 * the error state.
534 *
b3b66298
PC
535 * @note This function first clears eofbit. Since no characters
536 * are extracted, the next call to @c gcount() will return 0,
537 * as required by DR 60.
840ceb34 538 */
7897a1c0 539 __istream_type&
840ceb34
PE
540 unget();
541
542 /**
543 * @brief Synchronizing the stream buffer.
544 * @return 0 on success, -1 on failure
545 *
546 * If @c rdbuf() is a null pointer, returns -1.
547 *
548 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
549 * sets badbit and returns -1.
550 *
551 * Otherwise, returns 0.
552 *
553 * @note This function does not count the number of characters
554 * extracted, if any, and therefore does not affect the next
555 * call to @c gcount().
840ceb34 556 */
7897a1c0 557 int
840ceb34
PE
558 sync();
559
560 /**
561 * @brief Getting the current read position.
562 * @return A file position object.
563 *
564 * If @c fail() is not false, returns @c pos_type(-1) to indicate
565 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
566 *
567 * @note This function does not count the number of characters
568 * extracted, if any, and therefore does not affect the next
b3b66298
PC
569 * call to @c gcount(). At variance with putback, unget and
570 * seekg, eofbit is not cleared first.
840ceb34 571 */
b3b66298 572 pos_type
840ceb34
PE
573 tellg();
574
575 /**
576 * @brief Changing the current read position.
93c66bc6 577 * @param __pos A file position object.
840ceb34
PE
578 * @return *this
579 *
93c66bc6 580 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
840ceb34
PE
581 * that function fails, sets failbit.
582 *
b3b66298
PC
583 * @note This function first clears eofbit. It does not count the
584 * number of characters extracted, if any, and therefore does
585 * not affect the next call to @c gcount().
840ceb34 586 */
b3b66298 587 __istream_type&
54c1bf78
BK
588 seekg(pos_type);
589
840ceb34
PE
590 /**
591 * @brief Changing the current read position.
93c66bc6
BK
592 * @param __off A file offset object.
593 * @param __dir The direction in which to seek.
840ceb34
PE
594 * @return *this
595 *
93c66bc6 596 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
840ceb34
PE
597 * If that function fails, sets failbit.
598 *
b3b66298
PC
599 * @note This function first clears eofbit. It does not count the
600 * number of characters extracted, if any, and therefore does
601 * not affect the next call to @c gcount().
840ceb34 602 */
7897a1c0 603 __istream_type&
54c1bf78 604 seekg(off_type, ios_base::seekdir);
840ceb34 605 //@}
d29cc32f
BK
606
607 protected:
b3aaa617
PC
608 basic_istream()
609 : _M_gcount(streamsize(0))
610 { this->init(0); }
49d5c016
PC
611
612 template<typename _ValueT>
7897a1c0
BK
613 __istream_type&
614 _M_extract(_ValueT& __v);
54c1bf78 615 };
adb31ad6 616
7897a1c0
BK
617 /// Explicit specialization declarations, defined in src/istream.cc.
618 template<>
619 basic_istream<char>&
adb31ad6
PC
620 basic_istream<char>::
621 getline(char_type* __s, streamsize __n, char_type __delim);
7897a1c0 622
adb31ad6
PC
623 template<>
624 basic_istream<char>&
625 basic_istream<char>::
626 ignore(streamsize __n);
7897a1c0 627
adb31ad6
PC
628 template<>
629 basic_istream<char>&
630 basic_istream<char>::
631 ignore(streamsize __n, int_type __delim);
632
633#ifdef _GLIBCXX_USE_WCHAR_T
7897a1c0
BK
634 template<>
635 basic_istream<wchar_t>&
adb31ad6
PC
636 basic_istream<wchar_t>::
637 getline(char_type* __s, streamsize __n, char_type __delim);
638
639 template<>
640 basic_istream<wchar_t>&
641 basic_istream<wchar_t>::
642 ignore(streamsize __n);
7897a1c0 643
adb31ad6
PC
644 template<>
645 basic_istream<wchar_t>&
646 basic_istream<wchar_t>::
647 ignore(streamsize __n, int_type __delim);
648#endif
649
840ceb34
PE
650 /**
651 * @brief Performs setup work for input streams.
652 *
653 * Objects of this class are created before all of the standard
2a60a9f6
BK
654 * extractors are run. It is responsible for <em>exception-safe
655 * prefix and suffix operations,</em> although only prefix actions
656 * are currently required by the standard.
840ceb34 657 */
54c1bf78
BK
658 template<typename _CharT, typename _Traits>
659 class basic_istream<_CharT, _Traits>::sentry
660 {
d29d4507
BK
661 // Data Members.
662 bool _M_ok;
663
54c1bf78 664 public:
840ceb34 665 /// Easy access to dependant types.
54c1bf78
BK
666 typedef _Traits traits_type;
667 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
668 typedef basic_istream<_CharT, _Traits> __istream_type;
669 typedef typename __istream_type::__ctype_type __ctype_type;
670 typedef typename _Traits::int_type __int_type;
671
840ceb34
PE
672 /**
673 * @brief The constructor performs all the work.
93c66bc6
BK
674 * @param __is The input stream to guard.
675 * @param __noskipws Whether to consume whitespace or not.
840ceb34 676 *
93c66bc6 677 * If the stream state is good (@a __is.good() is true), then the
2a60a9f6
BK
678 * following actions are performed, otherwise the sentry state
679 * is false (<em>not okay</em>) and failbit is set in the
680 * stream state.
840ceb34
PE
681 *
682 * The sentry's preparatory actions are:
683 *
684 * -# if the stream is tied to an output stream, @c is.tie()->flush()
685 * is called to synchronize the output sequence
93c66bc6 686 * -# if @a __noskipws is false, and @c ios_base::skipws is set in
840ceb34
PE
687 * @c is.flags(), the sentry extracts and discards whitespace
688 * characters from the stream. The currently imbued locale is
689 * used to determine whether each character is whitespace.
690 *
691 * If the stream state is still good, then the sentry state becomes
2a60a9f6 692 * true (@a okay).
840ceb34 693 */
b3aaa617 694 explicit
54c1bf78
BK
695 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
696
840ceb34
PE
697 /**
698 * @brief Quick status checking.
699 * @return The sentry state.
700 *
701 * For ease of use, sentries may be converted to booleans. The
702 * return value is that of the sentry state (true == okay).
703 */
734f5023 704#if __cplusplus >= 201103L
d29d4507
BK
705 explicit
706#endif
f7ab3fd1
PC
707 operator bool() const
708 { return _M_ok; }
54c1bf78
BK
709 };
710
840ceb34
PE
711 //@{
712 /**
713 * @brief Character extractors
93c66bc6
BK
714 * @param __in An input stream.
715 * @param __c A character reference.
840ceb34
PE
716 * @return in
717 *
718 * Behaves like one of the formatted arithmetic extractors described in
719 * std::basic_istream. After constructing a sentry object with good
720 * status, this function extracts a character (if one is available) and
93c66bc6 721 * stores it in @a __c. Otherwise, sets failbit in the input stream.
840ceb34 722 */
54c1bf78
BK
723 template<typename _CharT, typename _Traits>
724 basic_istream<_CharT, _Traits>&
725 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
726
727 template<class _Traits>
f7ab3fd1 728 inline basic_istream<char, _Traits>&
54c1bf78
BK
729 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
730 { return (__in >> reinterpret_cast<char&>(__c)); }
731
732 template<class _Traits>
f7ab3fd1 733 inline basic_istream<char, _Traits>&
54c1bf78
BK
734 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
735 { return (__in >> reinterpret_cast<char&>(__c)); }
840ceb34
PE
736 //@}
737
738 //@{
739 /**
740 * @brief Character string extractors
93c66bc6
BK
741 * @param __in An input stream.
742 * @param __s A pointer to a character array.
743 * @return __in
840ceb34
PE
744 *
745 * Behaves like one of the formatted arithmetic extractors described in
746 * std::basic_istream. After constructing a sentry object with good
747 * status, this function extracts up to @c n characters and stores them
93c66bc6 748 * into the array starting at @a __s. @c n is defined as:
840ceb34 749 *
2a60a9f6
BK
750 * - if @c width() is greater than zero, @c n is width() otherwise
751 * - @c n is <em>the number of elements of the largest array of *
752 * - @c char_type that can store a terminating @c eos.</em>
753 * - [27.6.1.2.3]/6
840ceb34
PE
754 *
755 * Characters are extracted and stored until one of the following happens:
756 * - @c n-1 characters are stored
757 * - EOF is reached
758 * - the next character is whitespace according to the current locale
759 * - the next character is a null byte (i.e., @c charT() )
760 *
761 * @c width(0) is then called for the input stream.
762 *
763 * If no characters are extracted, sets failbit.
764 */
54c1bf78
BK
765 template<typename _CharT, typename _Traits>
766 basic_istream<_CharT, _Traits>&
767 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
ceed88b1
PC
768
769 // Explicit specialization declaration, defined in src/istream.cc.
770 template<>
771 basic_istream<char>&
772 operator>>(basic_istream<char>& __in, char* __s);
773
54c1bf78 774 template<class _Traits>
f7ab3fd1 775 inline basic_istream<char, _Traits>&
adb31ad6 776 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
54c1bf78
BK
777 { return (__in >> reinterpret_cast<char*>(__s)); }
778
779 template<class _Traits>
f7ab3fd1 780 inline basic_istream<char, _Traits>&
adb31ad6 781 operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
54c1bf78 782 { return (__in >> reinterpret_cast<char*>(__s)); }
840ceb34 783 //@}
54c1bf78 784
840ceb34 785 /**
7897a1c0 786 * @brief Template class basic_iostream
5b9daa7e 787 * @ingroup io
840ceb34 788 *
d632488a
BK
789 * @tparam _CharT Type of character stream.
790 * @tparam _Traits Traits for character type, defaults to
791 * char_traits<_CharT>.
792 *
840ceb34
PE
793 * This class multiply inherits from the input and output stream classes
794 * simply to provide a single interface.
795 */
54c1bf78
BK
796 template<typename _CharT, typename _Traits>
797 class basic_iostream
7897a1c0 798 : public basic_istream<_CharT, _Traits>,
54c1bf78
BK
799 public basic_ostream<_CharT, _Traits>
800 {
801 public:
f5677b15
PC
802 // _GLIBCXX_RESOLVE_LIB_DEFECTS
803 // 271. basic_iostream missing typedefs
bcc6a03a 804 // Types (inherited):
7897a1c0 805 typedef _CharT char_type;
bcc6a03a
BK
806 typedef typename _Traits::int_type int_type;
807 typedef typename _Traits::pos_type pos_type;
808 typedef typename _Traits::off_type off_type;
7897a1c0 809 typedef _Traits traits_type;
bcc6a03a 810
54c1bf78
BK
811 // Non-standard Types:
812 typedef basic_istream<_CharT, _Traits> __istream_type;
813 typedef basic_ostream<_CharT, _Traits> __ostream_type;
814
840ceb34
PE
815 /**
816 * @brief Constructor does nothing.
817 *
818 * Both of the parent classes are initialized with the same
819 * streambuf pointer passed to this constructor.
820 */
b3aaa617 821 explicit
54c1bf78 822 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
b3aaa617 823 : __istream_type(__sb), __ostream_type(__sb) { }
54c1bf78 824
840ceb34
PE
825 /**
826 * @brief Destructor does nothing.
827 */
7897a1c0 828 virtual
54c1bf78 829 ~basic_iostream() { }
d29cc32f
BK
830
831 protected:
b3aaa617
PC
832 basic_iostream()
833 : __istream_type(), __ostream_type() { }
54c1bf78
BK
834 };
835
840ceb34
PE
836 /**
837 * @brief Quick and easy way to eat whitespace
838 *
839 * This manipulator extracts whitespace characters, stopping when the
840 * next character is non-whitespace, or when the input sequence is empty.
841 * If the sequence is empty, @c eofbit is set in the stream, but not
842 * @c failbit.
843 *
844 * The current locale is used to distinguish whitespace characters.
845 *
846 * Example:
847 * @code
848 * MyClass mc;
849 *
850 * std::cin >> std::ws >> mc;
851 * @endcode
852 * will skip leading whitespace before calling operator>> on cin and your
853 * object. Note that the same effect can be achieved by creating a
854 * std::basic_istream::sentry inside your definition of operator>>.
855 */
54c1bf78 856 template<typename _CharT, typename _Traits>
7897a1c0 857 basic_istream<_CharT, _Traits>&
54c1bf78 858 ws(basic_istream<_CharT, _Traits>& __is);
3cbc7af0 859
734f5023 860#if __cplusplus >= 201103L
e7f1930f
JM
861 // [27.7.1.6] Rvalue stream extraction
862 /**
863 * @brief Generic extractor for rvalue stream
93c66bc6
BK
864 * @param __is An input stream.
865 * @param __x A reference to the extraction target.
e7f1930f
JM
866 * @return is
867 *
868 * This is just a forwarding function to allow extraction from
869 * rvalue streams since they won't bind to the extractor functions
870 * that take an lvalue reference.
871 */
872 template<typename _CharT, typename _Traits, typename _Tp>
53a381dc
PC
873 inline basic_istream<_CharT, _Traits>&
874 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
875 { return (__is >> __x); }
734f5023 876#endif // C++11
e7f1930f 877
12ffa228
BK
878_GLIBCXX_END_NAMESPACE_VERSION
879} // namespace
54c1bf78 880
ee3ee948 881#include <bits/istream.tcc>
54c1bf78 882
1143680e 883#endif /* _GLIBCXX_ISTREAM */