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