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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [streambuf] - Blame information for rev 35

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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