OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [include/] [std/] [std_streambuf.h] - Blame information for rev 17

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.