diff options
author | Benjamin Kosnik <bkoz@cygnus.com> | 2000-07-21 00:06:51 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2000-07-21 00:06:51 +0000 |
commit | 7be50fd30fa08028f2ea7ac281cd0a310151d3b9 (patch) | |
tree | 86a931a543012a803c455f39850cd161f1c52185 /libstdc++-v3/bits/std_streambuf.h | |
parent | 4dbf4496573255460757de76bb8347669196587c (diff) | |
download | gcc-7be50fd30fa08028f2ea7ac281cd0a310151d3b9.zip gcc-7be50fd30fa08028f2ea7ac281cd0a310151d3b9.tar.gz gcc-7be50fd30fa08028f2ea7ac281cd0a310151d3b9.tar.bz2 |
[multiple changes]
2000-07-20 Benjamin Kosnik <bkoz@cygnus.com>
* bits/std_streambuf.h: Add bits for pback buffers here, so that
in_avail, etc can use them.
* bits/std_fstream.h: Ditto.
* bits/fstream.tcc: Ditto.
* testsuite/27_io/filebuf.cc: Tweaks.
* testsuite/27_io/filebuf-3.tst: Correct for pbackfail bits.
2000-07-19 Benjamin Kosnik <bkoz@cygnus.com>
* src/localename.cc: Same.
* src/locale.cc: Same.
* bits/localefwd.h: _M_init_facet to _M_facet_init.
* bits/locale_facets.h: _M_init_boolnames to _M_boolnames_init.
* bits/std_sstream.h: Change _M_init_stringbuf to _M_stringbuf_init.
* bits/fstream.tcc: Change _M_init_filebuf to _M_filebuf_init.
* bits/std_fstream.h: Same.
* bits/basic_string.h: Tweaks.
From-SVN: r35157
Diffstat (limited to 'libstdc++-v3/bits/std_streambuf.h')
-rw-r--r-- | libstdc++-v3/bits/std_streambuf.h | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/libstdc++-v3/bits/std_streambuf.h b/libstdc++-v3/bits/std_streambuf.h index 23bdd5c..35e214c 100644 --- a/libstdc++-v3/bits/std_streambuf.h +++ b/libstdc++-v3/bits/std_streambuf.h @@ -98,11 +98,11 @@ namespace std { // for an internal buffer. // get == input == read // put == output == write - char_type* _M_in_cur; // Current read area. char_type* _M_in_beg; // Start of get area. + char_type* _M_in_cur; // Current read area. char_type* _M_in_end; // End of get area. - char_type* _M_out_cur; // Current put area. char_type* _M_out_beg; // Start of put area. + char_type* _M_out_cur; // Current put area. char_type* _M_out_end; // End of put area. // Place to stash in || out || in | out settings for current streambuf. @@ -117,6 +117,61 @@ namespace std { // Cached use_facet<ctype>, which is based on the current locale info. const __ctype_type* _M_buf_fctype; + // Necessary bits for putback buffer management. Only used in + // the basic_filebuf class, as necessary for the standard + // requirements. The only basic_streambuf member function that + // needs access to these data members is in_avail... + // NB: pbacks of over one character are not currently supported. + int_type _M_pback_size; + char_type* _M_pback; + char_type* _M_pback_cur_save; + char_type* _M_pback_end_save; + bool _M_pback_init; + + // Initializes pback buffers, and moves normal buffers to safety. + // Assumptions: + // _M_in_cur has already been moved back + void + _M_pback_create() + { + if (!_M_pback_init) + { + int_type __dist = _M_in_end - _M_in_cur; + int_type __len = min(_M_pback_size, __dist); + traits_type::copy(_M_pback, _M_in_cur, __len); + _M_pback_cur_save = _M_in_cur; + _M_pback_end_save = _M_in_end; + this->setg(_M_pback, _M_pback, _M_pback + __len); + _M_pback_init = true; + } + } + + // Deactivates pback buffer contents, and restores normal buffer. + // Assumptions: + // The pback buffer has only moved forward. + void + _M_pback_destroy() + { + if (_M_pback_init) + { + // Length _M_in_cur moved in the pback buffer. + int_type __off_cur = _M_in_cur - _M_pback; + + // For in | out buffers, the end can be pushed back... + int_type __off_end = 0; + int_type __pback_len = _M_in_end - _M_pback; + int_type __save_len = _M_pback_end_save - _M_buf; + if (__pback_len > __save_len) + __off_end = __pback_len - __save_len; + + this->setg(_M_buf, _M_pback_cur_save + __off_cur, + _M_pback_end_save + __off_end); + _M_pback_cur_save = NULL; + _M_pback_end_save = NULL; + _M_pback_init = false; + } + } + // Correctly sets the _M_out_cur pointer, and bumps the // appropriate _M_*_end pointers as well. Necessary for the // un-tied stringbufs, in in|out mode. @@ -195,6 +250,7 @@ namespace std { _M_mode = ios_base::openmode(0); _M_buf_fctype = NULL; _M_buf_locale_init = false; + } // Locales: @@ -240,7 +296,16 @@ namespace std { { streamsize __retval; if (_M_in_cur && _M_in_cur < _M_in_end) - __retval = this->egptr() - this->gptr(); + { + if (_M_pback_init) + { + int_type __save_len = _M_pback_end_save - _M_pback_cur_save; + int_type __pback_len = _M_in_cur - _M_pback; + __retval = __save_len - __pback_len; + } + else + __retval = this->egptr() - this->gptr(); + } else __retval = this->showmanyc(); return __retval; @@ -289,13 +354,12 @@ namespace std { protected: basic_streambuf() : _M_buf(NULL), _M_buf_size(0), - _M_buf_size_opt(static_cast<int_type>(BUFSIZ * sizeof(char_type))), - _M_buf_unified(false), _M_in_cur(0), _M_in_beg(0), _M_in_end(0), - _M_out_cur(0), _M_out_beg(0), _M_out_end(0), - _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()), - _M_buf_locale_init(false) - - { _M_buf_fctype = &use_facet<__ctype_type>(this->getloc()); } + _M_buf_size_opt(static_cast<int_type>(BUFSIZ)), _M_buf_unified(false), + _M_in_beg(0), _M_in_cur(0), _M_in_end(0), _M_out_beg(0), _M_out_cur(0), + _M_out_end(0), _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()), + _M_buf_locale_init(false), _M_pback_size(1), _M_pback(NULL), + _M_pback_cur_save(NULL), _M_pback_end_save(NULL), _M_pback_init(false) + { _M_buf_fctype = &use_facet<__ctype_type>(this->getloc()); } // Get area: char_type* |