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