libstdc++
streambuf
Go to the documentation of this file.
1 // Stream buffer classes -*- C++ -*-
2 
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010, 2011, 2013 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20 
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25 
26 /** @file include/streambuf
27  * This is a Standard C++ Library header.
28  */
29 
30 //
31 // ISO C++ 14882: 27.5 Stream buffers
32 //
33 
34 #ifndef _GLIBXX_STREAMBUF
35 #define _GLIBXX_STREAMBUF 1
36 
37 #pragma GCC system_header
38 
39 #include <bits/c++config.h>
40 #include <iosfwd>
41 #include <bits/localefwd.h>
42 #include <bits/ios_base.h>
43 #include <bits/cpp_type_traits.h>
44 #include <ext/type_traits.h>
45 
46 namespace std _GLIBCXX_VISIBILITY(default)
47 {
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 
50  template<typename _CharT, typename _Traits>
52  __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>*,
53  basic_streambuf<_CharT, _Traits>*, bool&);
54 
55  /**
56  * @brief The actual work of input and output (interface).
57  * @ingroup io
58  *
59  * This is a base class. Derived stream buffers each control a
60  * pair of character sequences: one for input, and one for output.
61  *
62  * Section [27.5.1] of the standard describes the requirements and
63  * behavior of stream buffer classes. That section (three paragraphs)
64  * is reproduced here, for simplicity and accuracy.
65  *
66  * -# Stream buffers can impose various constraints on the sequences
67  * they control. Some constraints are:
68  * - The controlled input sequence can be not readable.
69  * - The controlled output sequence can be not writable.
70  * - The controlled sequences can be associated with the contents of
71  * other representations for character sequences, such as external
72  * files.
73  * - The controlled sequences can support operations @e directly to or
74  * from associated sequences.
75  * - The controlled sequences can impose limitations on how the
76  * program can read characters from a sequence, write characters to
77  * a sequence, put characters back into an input sequence, or alter
78  * the stream position.
79  * .
80  * -# Each sequence is characterized by three pointers which, if non-null,
81  * all point into the same @c charT array object. The array object
82  * represents, at any moment, a (sub)sequence of characters from the
83  * sequence. Operations performed on a sequence alter the values
84  * stored in these pointers, perform reads and writes directly to or
85  * from associated sequences, and alter <em>the stream position</em> and
86  * conversion state as needed to maintain this subsequence relationship.
87  * The three pointers are:
88  * - the <em>beginning pointer</em>, or lowest element address in the
89  * array (called @e xbeg here);
90  * - the <em>next pointer</em>, or next element address that is a
91  * current candidate for reading or writing (called @e xnext here);
92  * - the <em>end pointer</em>, or first element address beyond the
93  * end of the array (called @e xend here).
94  * .
95  * -# The following semantic constraints shall always apply for any set
96  * of three pointers for a sequence, using the pointer names given
97  * immediately above:
98  * - If @e xnext is not a null pointer, then @e xbeg and @e xend shall
99  * also be non-null pointers into the same @c charT array, as
100  * described above; otherwise, @e xbeg and @e xend shall also be null.
101  * - If @e xnext is not a null pointer and @e xnext < @e xend for an
102  * output sequence, then a <em>write position</em> is available.
103  * In this case, @e *xnext shall be assignable as the next element
104  * to write (to put, or to store a character value, into the sequence).
105  * - If @e xnext is not a null pointer and @e xbeg < @e xnext for an
106  * input sequence, then a <em>putback position</em> is available.
107  * In this case, @e xnext[-1] shall have a defined value and is the
108  * next (preceding) element to store a character that is put back
109  * into the input sequence.
110  * - If @e xnext is not a null pointer and @e xnext< @e xend for an
111  * input sequence, then a <em>read position</em> is available.
112  * In this case, @e *xnext shall have a defined value and is the
113  * next element to read (to get, or to obtain a character value,
114  * from the sequence).
115  */
116  template<typename _CharT, typename _Traits>
117  class basic_streambuf
118  {
119  public:
120  //@{
121  /**
122  * These are standard types. They permit a standardized way of
123  * referring to names of (or names dependant on) the template
124  * parameters, which are specific to the implementation.
125  */
126  typedef _CharT char_type;
127  typedef _Traits traits_type;
128  typedef typename traits_type::int_type int_type;
129  typedef typename traits_type::pos_type pos_type;
130  typedef typename traits_type::off_type off_type;
131  //@}
132 
133  //@{
134  /// This is a non-standard type.
136  //@}
137 
138  friend class basic_ios<char_type, traits_type>;
139  friend class basic_istream<char_type, traits_type>;
140  friend class basic_ostream<char_type, traits_type>;
143 
144  friend streamsize
145  __copy_streambufs_eof<>(__streambuf_type*, __streambuf_type*, bool&);
146 
147  template<bool _IsMove, typename _CharT2>
148  friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
149  _CharT2*>::__type
150  __copy_move_a2(istreambuf_iterator<_CharT2>,
151  istreambuf_iterator<_CharT2>, _CharT2*);
152 
153  template<typename _CharT2>
154  friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
157  const _CharT2&);
158 
159  template<typename _CharT2, typename _Traits2>
162 
163  template<typename _CharT2, typename _Traits2, typename _Alloc>
167 
168  template<typename _CharT2, typename _Traits2, typename _Alloc>
172 
173  protected:
174  /*
175  * This is based on _IO_FILE, just reordered to be more consistent,
176  * and is intended to be the most minimal abstraction for an
177  * internal buffer.
178  * - get == input == read
179  * - put == output == write
180  */
181  char_type* _M_in_beg; ///< Start of get area.
182  char_type* _M_in_cur; ///< Current read area.
183  char_type* _M_in_end; ///< End of get area.
184  char_type* _M_out_beg; ///< Start of put area.
185  char_type* _M_out_cur; ///< Current put area.
186  char_type* _M_out_end; ///< End of put area.
187 
188  /// Current locale setting.
190 
191  public:
192  /// Destructor deallocates no buffer space.
193  virtual
195  { }
196 
197  // [27.5.2.2.1] locales
198  /**
199  * @brief Entry point for imbue().
200  * @param __loc The new locale.
201  * @return The previous locale.
202  *
203  * Calls the derived imbue(__loc).
204  */
205  locale
206  pubimbue(const locale& __loc)
207  {
208  locale __tmp(this->getloc());
209  this->imbue(__loc);
210  _M_buf_locale = __loc;
211  return __tmp;
212  }
213 
214  /**
215  * @brief Locale access.
216  * @return The current locale in effect.
217  *
218  * If pubimbue(loc) has been called, then the most recent @c loc
219  * is returned. Otherwise the global locale in effect at the time
220  * of construction is returned.
221  */
222  locale
223  getloc() const
224  { return _M_buf_locale; }
225 
226  // [27.5.2.2.2] buffer management and positioning
227  //@{
228  /**
229  * @brief Entry points for derived buffer functions.
230  *
231  * The public versions of @c pubfoo dispatch to the protected
232  * derived @c foo member functions, passing the arguments (if any)
233  * and returning the result unchanged.
234  */
237  { return this->setbuf(__s, __n); }
238 
239  /**
240  * @brief Alters the stream position.
241  * @param __off Offset.
242  * @param __way Value for ios_base::seekdir.
243  * @param __mode Value for ios_base::openmode.
244  *
245  * Calls virtual seekoff function.
246  */
247  pos_type
248  pubseekoff(off_type __off, ios_base::seekdir __way,
249  ios_base::openmode __mode = ios_base::in | ios_base::out)
250  { return this->seekoff(__off, __way, __mode); }
251 
252  /**
253  * @brief Alters the stream position.
254  * @param __sp Position
255  * @param __mode Value for ios_base::openmode.
256  *
257  * Calls virtual seekpos function.
258  */
259  pos_type
261  ios_base::openmode __mode = ios_base::in | ios_base::out)
262  { return this->seekpos(__sp, __mode); }
263 
264  /**
265  * @brief Calls virtual sync function.
266  */
267  int
268  pubsync() { return this->sync(); }
269  //@}
270 
271  // [27.5.2.2.3] get area
272  /**
273  * @brief Looking ahead into the stream.
274  * @return The number of characters available.
275  *
276  * If a read position is available, returns the number of characters
277  * available for reading before the buffer must be refilled.
278  * Otherwise returns the derived @c showmanyc().
279  */
280  streamsize
282  {
283  const streamsize __ret = this->egptr() - this->gptr();
284  return __ret ? __ret : this->showmanyc();
285  }
286 
287  /**
288  * @brief Getting the next character.
289  * @return The next character, or eof.
290  *
291  * Calls @c sbumpc(), and if that function returns
292  * @c traits::eof(), so does this function. Otherwise, @c sgetc().
293  */
294  int_type
296  {
297  int_type __ret = traits_type::eof();
298  if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
299  __ret), true))
300  __ret = this->sgetc();
301  return __ret;
302  }
303 
304  /**
305  * @brief Getting the next character.
306  * @return The next character, or eof.
307  *
308  * If the input read position is available, returns that character
309  * and increments the read pointer, otherwise calls and returns
310  * @c uflow().
311  */
312  int_type
314  {
315  int_type __ret;
316  if (__builtin_expect(this->gptr() < this->egptr(), true))
317  {
318  __ret = traits_type::to_int_type(*this->gptr());
319  this->gbump(1);
320  }
321  else
322  __ret = this->uflow();
323  return __ret;
324  }
325 
326  /**
327  * @brief Getting the next character.
328  * @return The next character, or eof.
329  *
330  * If the input read position is available, returns that character,
331  * otherwise calls and returns @c underflow(). Does not move the
332  * read position after fetching the character.
333  */
334  int_type
336  {
337  int_type __ret;
338  if (__builtin_expect(this->gptr() < this->egptr(), true))
339  __ret = traits_type::to_int_type(*this->gptr());
340  else
341  __ret = this->underflow();
342  return __ret;
343  }
344 
345  /**
346  * @brief Entry point for xsgetn.
347  * @param __s A buffer area.
348  * @param __n A count.
349  *
350  * Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through
351  * @a __s[__n-1] with characters from the input sequence, if possible.
352  */
353  streamsize
355  { return this->xsgetn(__s, __n); }
356 
357  // [27.5.2.2.4] putback
358  /**
359  * @brief Pushing characters back into the input stream.
360  * @param __c The character to push back.
361  * @return The previous character, if possible.
362  *
363  * Similar to sungetc(), but @a __c is pushed onto the stream
364  * instead of <em>the previous character.</em> If successful,
365  * the next character fetched from the input stream will be @a
366  * __c.
367  */
368  int_type
370  {
371  int_type __ret;
372  const bool __testpos = this->eback() < this->gptr();
373  if (__builtin_expect(!__testpos ||
374  !traits_type::eq(__c, this->gptr()[-1]), false))
375  __ret = this->pbackfail(traits_type::to_int_type(__c));
376  else
377  {
378  this->gbump(-1);
379  __ret = traits_type::to_int_type(*this->gptr());
380  }
381  return __ret;
382  }
383 
384  /**
385  * @brief Moving backwards in the input stream.
386  * @return The previous character, if possible.
387  *
388  * If a putback position is available, this function decrements
389  * the input pointer and returns that character. Otherwise,
390  * calls and returns pbackfail(). The effect is to @a unget
391  * the last character @a gotten.
392  */
393  int_type
395  {
396  int_type __ret;
397  if (__builtin_expect(this->eback() < this->gptr(), true))
398  {
399  this->gbump(-1);
400  __ret = traits_type::to_int_type(*this->gptr());
401  }
402  else
403  __ret = this->pbackfail();
404  return __ret;
405  }
406 
407  // [27.5.2.2.5] put area
408  /**
409  * @brief Entry point for all single-character output functions.
410  * @param __c A character to output.
411  * @return @a __c, if possible.
412  *
413  * One of two public output functions.
414  *
415  * If a write position is available for the output sequence (i.e.,
416  * the buffer is not full), stores @a __c in that position, increments
417  * the position, and returns @c traits::to_int_type(__c). If a write
418  * position is not available, returns @c overflow(__c).
419  */
420  int_type
422  {
423  int_type __ret;
424  if (__builtin_expect(this->pptr() < this->epptr(), true))
425  {
426  *this->pptr() = __c;
427  this->pbump(1);
428  __ret = traits_type::to_int_type(__c);
429  }
430  else
431  __ret = this->overflow(traits_type::to_int_type(__c));
432  return __ret;
433  }
434 
435  /**
436  * @brief Entry point for all single-character output functions.
437  * @param __s A buffer read area.
438  * @param __n A count.
439  *
440  * One of two public output functions.
441  *
442  *
443  * Returns xsputn(__s,__n). The effect is to write @a __s[0] through
444  * @a __s[__n-1] to the output sequence, if possible.
445  */
446  streamsize
447  sputn(const char_type* __s, streamsize __n)
448  { return this->xsputn(__s, __n); }
449 
450  protected:
451  /**
452  * @brief Base constructor.
453  *
454  * Only called from derived constructors, and sets up all the
455  * buffer data to zero, including the pointers described in the
456  * basic_streambuf class description. Note that, as a result,
457  * - the class starts with no read nor write positions available,
458  * - this is not an error
459  */
461  : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
462  _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
464  { }
465 
466  // [27.5.2.3.1] get area access
467  //@{
468  /**
469  * @brief Access to the get area.
470  *
471  * These functions are only available to other protected functions,
472  * including derived classes.
473  *
474  * - eback() returns the beginning pointer for the input sequence
475  * - gptr() returns the next pointer for the input sequence
476  * - egptr() returns the end pointer for the input sequence
477  */
478  char_type*
479  eback() const { return _M_in_beg; }
480 
481  char_type*
482  gptr() const { return _M_in_cur; }
483 
484  char_type*
485  egptr() const { return _M_in_end; }
486  //@}
487 
488  /**
489  * @brief Moving the read position.
490  * @param __n The delta by which to move.
491  *
492  * This just advances the read position without returning any data.
493  */
494  void
495  gbump(int __n) { _M_in_cur += __n; }
496 
497  /**
498  * @brief Setting the three read area pointers.
499  * @param __gbeg A pointer.
500  * @param __gnext A pointer.
501  * @param __gend A pointer.
502  * @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and
503  * @a __gend == @c egptr()
504  */
505  void
506  setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
507  {
508  _M_in_beg = __gbeg;
509  _M_in_cur = __gnext;
510  _M_in_end = __gend;
511  }
512 
513  // [27.5.2.3.2] put area access
514  //@{
515  /**
516  * @brief Access to the put area.
517  *
518  * These functions are only available to other protected functions,
519  * including derived classes.
520  *
521  * - pbase() returns the beginning pointer for the output sequence
522  * - pptr() returns the next pointer for the output sequence
523  * - epptr() returns the end pointer for the output sequence
524  */
525  char_type*
526  pbase() const { return _M_out_beg; }
527 
528  char_type*
529  pptr() const { return _M_out_cur; }
530 
531  char_type*
532  epptr() const { return _M_out_end; }
533  //@}
534 
535  /**
536  * @brief Moving the write position.
537  * @param __n The delta by which to move.
538  *
539  * This just advances the write position without returning any data.
540  */
541  void
542  pbump(int __n) { _M_out_cur += __n; }
543 
544  /**
545  * @brief Setting the three write area pointers.
546  * @param __pbeg A pointer.
547  * @param __pend A pointer.
548  * @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and
549  * @a __pend == @c epptr()
550  */
551  void
552  setp(char_type* __pbeg, char_type* __pend)
553  {
554  _M_out_beg = _M_out_cur = __pbeg;
555  _M_out_end = __pend;
556  }
557 
558  // [27.5.2.4] virtual functions
559  // [27.5.2.4.1] locales
560  /**
561  * @brief Changes translations.
562  * @param __loc A new locale.
563  *
564  * Translations done during I/O which depend on the current
565  * locale are changed by this call. The standard adds,
566  * <em>Between invocations of this function a class derived
567  * from streambuf can safely cache results of calls to locale
568  * functions and to members of facets so obtained.</em>
569  *
570  * @note Base class version does nothing.
571  */
572  virtual void
573  imbue(const locale& __loc)
574  { }
575 
576  // [27.5.2.4.2] buffer management and positioning
577  /**
578  * @brief Manipulates the buffer.
579  *
580  * Each derived class provides its own appropriate behavior. See
581  * the next-to-last paragraph of
582  * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html
583  * for more on this function.
584  *
585  * @note Base class version does nothing, returns @c this.
586  */
589  { return this; }
590 
591  /**
592  * @brief Alters the stream positions.
593  *
594  * Each derived class provides its own appropriate behavior.
595  * @note Base class version does nothing, returns a @c pos_type
596  * that represents an invalid stream position.
597  */
598  virtual pos_type
599  seekoff(off_type, ios_base::seekdir,
600  ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
601  { return pos_type(off_type(-1)); }
602 
603  /**
604  * @brief Alters the stream positions.
605  *
606  * Each derived class provides its own appropriate behavior.
607  * @note Base class version does nothing, returns a @c pos_type
608  * that represents an invalid stream position.
609  */
610  virtual pos_type
612  ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
613  { return pos_type(off_type(-1)); }
614 
615  /**
616  * @brief Synchronizes the buffer arrays with the controlled sequences.
617  * @return -1 on failure.
618  *
619  * Each derived class provides its own appropriate behavior,
620  * including the definition of @a failure.
621  * @note Base class version does nothing, returns zero.
622  */
623  virtual int
624  sync() { return 0; }
625 
626  // [27.5.2.4.3] get area
627  /**
628  * @brief Investigating the data available.
629  * @return An estimate of the number of characters available in the
630  * input sequence, or -1.
631  *
632  * <em>If it returns a positive value, then successive calls to
633  * @c underflow() will not return @c traits::eof() until at
634  * least that number of characters have been supplied. If @c
635  * showmanyc() returns -1, then calls to @c underflow() or @c
636  * uflow() will fail.</em> [27.5.2.4.3]/1
637  *
638  * @note Base class version does nothing, returns zero.
639  * @note The standard adds that <em>the intention is not only that the
640  * calls [to underflow or uflow] will not return @c eof() but
641  * that they will return immediately.</em>
642  * @note The standard adds that <em>the morphemes of @c showmanyc are
643  * @b es-how-many-see, not @b show-manic.</em>
644  */
645  virtual streamsize
646  showmanyc() { return 0; }
647 
648  /**
649  * @brief Multiple character extraction.
650  * @param __s A buffer area.
651  * @param __n Maximum number of characters to assign.
652  * @return The number of characters assigned.
653  *
654  * Fills @a __s[0] through @a __s[__n-1] with characters from the input
655  * sequence, as if by @c sbumpc(). Stops when either @a __n characters
656  * have been copied, or when @c traits::eof() would be copied.
657  *
658  * It is expected that derived classes provide a more efficient
659  * implementation by overriding this definition.
660  */
661  virtual streamsize
662  xsgetn(char_type* __s, streamsize __n);
663 
664  /**
665  * @brief Fetches more data from the controlled sequence.
666  * @return The first character from the <em>pending sequence</em>.
667  *
668  * Informally, this function is called when the input buffer is
669  * exhausted (or does not exist, as buffering need not actually be
670  * done). If a buffer exists, it is @a refilled. In either case, the
671  * next available character is returned, or @c traits::eof() to
672  * indicate a null pending sequence.
673  *
674  * For a formal definition of the pending sequence, see a good text
675  * such as Langer & Kreft, or [27.5.2.4.3]/7-14.
676  *
677  * A functioning input streambuf can be created by overriding only
678  * this function (no buffer area will be used). For an example, see
679  * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25.html
680  *
681  * @note Base class version does nothing, returns eof().
682  */
683  virtual int_type
685  { return traits_type::eof(); }
686 
687  /**
688  * @brief Fetches more data from the controlled sequence.
689  * @return The first character from the <em>pending sequence</em>.
690  *
691  * Informally, this function does the same thing as @c underflow(),
692  * and in fact is required to call that function. It also returns
693  * the new character, like @c underflow() does. However, this
694  * function also moves the read position forward by one.
695  */
696  virtual int_type
697  uflow()
698  {
699  int_type __ret = traits_type::eof();
700  const bool __testeof = traits_type::eq_int_type(this->underflow(),
701  __ret);
702  if (!__testeof)
703  {
704  __ret = traits_type::to_int_type(*this->gptr());
705  this->gbump(1);
706  }
707  return __ret;
708  }
709 
710  // [27.5.2.4.4] putback
711  /**
712  * @brief Tries to back up the input sequence.
713  * @param __c The character to be inserted back into the sequence.
714  * @return eof() on failure, <em>some other value</em> on success
715  * @post The constraints of @c gptr(), @c eback(), and @c pptr()
716  * are the same as for @c underflow().
717  *
718  * @note Base class version does nothing, returns eof().
719  */
720  virtual int_type
721  pbackfail(int_type __c = traits_type::eof())
722  { return traits_type::eof(); }
723 
724  // Put area:
725  /**
726  * @brief Multiple character insertion.
727  * @param __s A buffer area.
728  * @param __n Maximum number of characters to write.
729  * @return The number of characters written.
730  *
731  * Writes @a __s[0] through @a __s[__n-1] to the output sequence, as if
732  * by @c sputc(). Stops when either @a n characters have been
733  * copied, or when @c sputc() would return @c traits::eof().
734  *
735  * It is expected that derived classes provide a more efficient
736  * implementation by overriding this definition.
737  */
738  virtual streamsize
739  xsputn(const char_type* __s, streamsize __n);
740 
741  /**
742  * @brief Consumes data from the buffer; writes to the
743  * controlled sequence.
744  * @param __c An additional character to consume.
745  * @return eof() to indicate failure, something else (usually
746  * @a __c, or not_eof())
747  *
748  * Informally, this function is called when the output buffer
749  * is full (or does not exist, as buffering need not actually
750  * be done). If a buffer exists, it is @a consumed, with
751  * <em>some effect</em> on the controlled sequence.
752  * (Typically, the buffer is written out to the sequence
753  * verbatim.) In either case, the character @a c is also
754  * written out, if @a __c is not @c eof().
755  *
756  * For a formal definition of this function, see a good text
757  * such as Langer & Kreft, or [27.5.2.4.5]/3-7.
758  *
759  * A functioning output streambuf can be created by overriding only
760  * this function (no buffer area will be used).
761  *
762  * @note Base class version does nothing, returns eof().
763  */
764  virtual int_type
765  overflow(int_type __c = traits_type::eof())
766  { return traits_type::eof(); }
767 
768 #if _GLIBCXX_USE_DEPRECATED
769  // Annex D.6
770  public:
771  /**
772  * @brief Tosses a character.
773  *
774  * Advances the read pointer, ignoring the character that would have
775  * been read.
776  *
777  * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
778  */
779  void
780  stossc()
781  {
782  if (this->gptr() < this->egptr())
783  this->gbump(1);
784  else
785  this->uflow();
786  }
787 #endif
788 
789  // Also used by specializations for char and wchar_t in src.
790  void
791  __safe_gbump(streamsize __n) { _M_in_cur += __n; }
792 
793  void
794  __safe_pbump(streamsize __n) { _M_out_cur += __n; }
795 
796  private:
797  // _GLIBCXX_RESOLVE_LIB_DEFECTS
798  // Side effect of DR 50.
799  basic_streambuf(const __streambuf_type& __sb)
800  : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
804  { }
805 
807  operator=(const __streambuf_type&) { return *this; };
808  };
809 
810  // Explicit specialization declarations, defined in src/streambuf.cc.
811  template<>
812  streamsize
813  __copy_streambufs_eof(basic_streambuf<char>* __sbin,
814  basic_streambuf<char>* __sbout, bool& __ineof);
815 #ifdef _GLIBCXX_USE_WCHAR_T
816  template<>
817  streamsize
818  __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin,
819  basic_streambuf<wchar_t>* __sbout, bool& __ineof);
820 #endif
821 
822 _GLIBCXX_END_NAMESPACE_VERSION
823 } // namespace
824 
825 #include <bits/streambuf.tcc>
826 
827 #endif /* _GLIBCXX_STREAMBUF */
virtual pos_type seekpos(pos_type, ios_base::openmode=ios_base::in|ios_base::out)
Alters the stream positions.
Definition: streambuf:611
_Traits traits_type
Definition: streambuf:127
char_type * pptr() const
Access to the put area.
Definition: streambuf:529
char_type * epptr() const
Access to the put area.
Definition: streambuf:532
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
Definition: streambuf:552
streamsize in_avail()
Looking ahead into the stream.
Definition: streambuf:281
locale pubimbue(const locale &__loc)
Entry point for imbue().
Definition: streambuf:206
locale _M_buf_locale
Current locale setting.
Definition: streambuf:189
virtual basic_streambuf< char_type, _Traits > * setbuf(char_type *, streamsize)
Manipulates the buffer.
Definition: streambuf:588
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
Definition: streambuf:765
char_type * eback() const
Access to the get area.
Definition: streambuf:479
int_type sbumpc()
Getting the next character.
Definition: streambuf:313
char_type * _M_in_end
End of get area.
Definition: streambuf:183
int_type snextc()
Getting the next character.
Definition: streambuf:295
basic_streambuf< char_type, traits_type > __streambuf_type
This is a non-standard type.
Definition: streambuf:135
Virtual base class for all stream classes.Most of the member functions called dispatched on stream ob...
Definition: iosfwd:79
Class representing stream positions.
Definition: postypes.h:114
void pbump(int __n)
Moving the write position.
Definition: streambuf:542
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
Definition: iosfwd:88
virtual ~basic_streambuf()
Destructor deallocates no buffer space.
Definition: streambuf:194
char_type * _M_out_end
End of put area.
Definition: streambuf:186
locale getloc() const
Locale access.
Definition: streambuf:223
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
Definition: streambuf:624
char_type * _M_in_cur
Current read area.
Definition: streambuf:182
char_type * _M_in_beg
Start of get area.
Definition: streambuf:181
pos_type pubseekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream position.
Definition: streambuf:248
Container class for localization functionality.The locale class is first a class wrapper for C librar...
traits_type::int_type int_type
Definition: streambuf:128
static const openmode out
Open for output. Default for ofstream and fstream.
Definition: ios_base.h:380
char_type * _M_out_beg
Start of put area.
Definition: streambuf:184
char_type * _M_out_cur
Current put area.
Definition: streambuf:185
int_type sputc(char_type __c)
Entry point for all single-character output functions.
Definition: streambuf:421
virtual int_type underflow()
Fetches more data from the controlled sequence.
Definition: streambuf:684
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
Definition: streambuf:506
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Definition: postypes.h:100
Template class basic_istream.This is the base class for all input streams. It provides text formattin...
Definition: iosfwd:85
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
streamsize sgetn(char_type *__s, streamsize __n)
Entry point for xsgetn.
Definition: streambuf:354
Managing sequences of characters and character-like objects.
Definition: basic_string.h:109
static const openmode in
Open for input. Default for ifstream and fstream.
Definition: ios_base.h:377
21.1.3.1 char_traits specializations
Definition: char_traits.h:235
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
Definition: streambuf:447
char_type * pbase() const
Access to the put area.
Definition: streambuf:526
virtual int_type uflow()
Fetches more data from the controlled sequence.
Definition: streambuf:697
virtual void imbue(const locale &__loc)
Changes translations.
Definition: streambuf:573
int_type sputbackc(char_type __c)
Pushing characters back into the input stream.
Definition: streambuf:369
char_type * egptr() const
Access to the get area.
Definition: streambuf:485
int pubsync()
Calls virtual sync function.
Definition: streambuf:268
virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode=ios_base::in|ios_base::out)
Alters the stream positions.
Definition: streambuf:599
void gbump(int __n)
Moving the read position.
Definition: streambuf:495
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
Definition: streambuf.tcc:81
bitset< _Nb > operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
Definition: bitset:1345
char_type * gptr() const
Access to the get area.
Definition: streambuf:482
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
Definition: streambuf:721
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
Definition: streambuf.tcc:47
traits_type::pos_type pos_type
Definition: streambuf:129
The actual work of input and output (interface).This is a base class. Derived stream buffers each con...
Definition: iosfwd:82
pos_type pubseekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream position.
Definition: streambuf:260
basic_streambuf()
Base constructor.
Definition: streambuf:460
traits_type::off_type off_type
Definition: streambuf:130
__streambuf_type * pubsetbuf(char_type *__s, streamsize __n)
Entry points for derived buffer functions.
Definition: streambuf:236
Provides input iterator semantics for streambufs.
Definition: iosfwd:122
Provides output iterator semantics for streambufs.
Definition: iosfwd:125
virtual streamsize showmanyc()
Investigating the data available.
Definition: streambuf:646
int_type sungetc()
Moving backwards in the input stream.
Definition: streambuf:394
int_type sgetc()
Getting the next character.
Definition: streambuf:335