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