summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/std/std_fstream.h
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-24 13:48:11 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-24 13:48:11 +0000
commita6bfe6ae16c3434339604742dae6bf0a7d5a955c (patch)
tree4181362da88e74433fa135cb0546217d62cdae22 /libstdc++-v3/include/std/std_fstream.h
parent92b2ed3fae6bd2fd6861f0cb89f04b94d710c1ca (diff)
downloadppe42-gcc-a6bfe6ae16c3434339604742dae6bf0a7d5a955c.tar.gz
ppe42-gcc-a6bfe6ae16c3434339604742dae6bf0a7d5a955c.zip
2003-06-24 Paolo Carlini <pcarlini@unitus.it>
Nathan C. Myers <ncm-nospam@cantrip.org> * include/std/std_fstream.h (_M_filepos): Remove. (_M_reading, _M_writing): New, encode the various I/O modes: 'read', 'write' and 'uncommitted'. (sync): If there is something to flush, do it, then go to 'uncommitted' mode. * include/bits/fstream.tcc (_M_set_buffer): Overhaul to deal with three different cases: __off > 0 (upon underflow), __off == 0 (upon overflow), __off == -1 (upon open, setbuf, seekoff/pos). (_M_underflow): Don't call overflow, set _M_reading to true on success, tweak. (pbackfail): Set _M_reading to true on pback creation, tweak. (overflow): Don't seek, deal with overflow in 'uncommitted' mode, set _M_writing to true on success, tweak. (seekoff): Simplify, set _M_reading, _M_writing to false, call _M_set_buffer(-1) ('uncommitted'). (open, close, setbuf): Set _M_reading, _M_writing to false and call _M_set_buffer(-1), tweak. (basic_filebuf): Don't set _M_buf_unified. (_M_destroy_internal_buffer): Don't call setg and setp. * include/ext/stdio_filebuf.h (stdio_filebuf): Use _M_reading, _M_writing and _M_set_buffer(-1). * include/std/std_streambuf.h (_M_move_out_cur, _M_move_in_cur, _M_out_lim, _M_buf_unified): Remove. (basic_streambuf): Don't set _M_out_lim and _M_buf_unified. (setp): Don't set _M_out_lim. * testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: Fix for the new logic ('read', 'write' and 'uncommitted' modes): e.g., upon open the mode is 'uncommitted' and therefore the put area pointers are null. * testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc: Ditto. * testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc: Ditto. * testsuite/27_io/basic_filebuf/setbuf/char/1.cc: Ditto. * testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc: Ditto. * testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: Ditto. * testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc: Ditto. * testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc: Ditto. * testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc: Ditto. * include/bits/fstream.tcc (showmanyc): Use only the documented derivation interface to basic_streambuf (gptr(), setg(), etc.) to work right with user specializations. * include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc, xsgetn, xsputn, __copy_streambufs): Likewise. * include/std/std_streambuf.h (in_avail, sgetc, uflow, stossc): Likewise. * include/std/std_fstream.h (_M_create_pback, _M_destroy_pback, xsgetn): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@68420 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/std_fstream.h')
-rw-r--r--libstdc++-v3/include/std/std_fstream.h76
1 files changed, 40 insertions, 36 deletions
diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h
index 7cc0dbd8e1f..605fad22b3e 100644
--- a/libstdc++-v3/include/std/std_fstream.h
+++ b/libstdc++-v3/include/std/std_fstream.h
@@ -137,19 +137,18 @@ namespace std
* @endif
*/
bool _M_buf_allocated;
-
+
+ // _M_reading == false && _M_writing == false for 'uncommitted' mode;
+ // _M_reading == true for 'read' mode;
+ // _M_writing == true for 'write' mode;
+ //
+ // NB: _M_reading == true && _M_writing == true is unused.
+ bool _M_reading;
+ bool _M_writing;
+
// XXX Needed?
bool _M_last_overflowed;
- // The position in the buffer corresponding to the external file
- // pointer.
- /**
- * @if maint
- * @doctodo
- * @endif
- */
- char_type* _M_filepos;
-
//@{
/**
* @if maint
@@ -175,8 +174,8 @@ namespace std
{
if (!_M_pback_init)
{
- _M_pback_cur_save = this->_M_in_cur;
- _M_pback_end_save = this->_M_in_end;
+ _M_pback_cur_save = this->gptr();
+ _M_pback_end_save = this->egptr();
this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
_M_pback_init = true;
}
@@ -191,7 +190,7 @@ namespace std
if (_M_pback_init)
{
// Length _M_in_cur moved in the pback buffer.
- _M_pback_cur_save += this->_M_in_cur != this->_M_in_beg;
+ _M_pback_cur_save += this->gptr() != this->eback();
this->setg(this->_M_buf, _M_pback_cur_save, _M_pback_end_save);
_M_pback_init = false;
}
@@ -365,23 +364,23 @@ namespace std
sync()
{
int __ret = 0;
- const bool __testput = this->_M_out_beg < this->_M_out_lim;
// Make sure that the internal buffer resyncs its idea of
// the file position with the external file.
- if (__testput)
+ // NB: _M_file.sync() will be called within.
+ if (this->pbase() < this->pptr())
{
- // Need to restore current position after the write.
- const off_type __off = this->_M_out_cur - this->_M_out_lim;
-
- // _M_file.sync() will be called within.
- if (traits_type::eq_int_type(this->overflow(), traits_type::eof()))
+ int_type __tmp = this->overflow();
+ if (traits_type::eq_int_type(__tmp, traits_type::eof()))
__ret = -1;
- else if (__off)
- _M_file.seekoff(__off, ios_base::cur);
+ else
+ {
+ _M_set_buffer(-1);
+ _M_reading = false;
+ _M_writing = false;
+ }
}
- else
- _M_file.sync();
+
_M_last_overflowed = false;
return __ret;
}
@@ -398,9 +397,10 @@ namespace std
streamsize __ret = 0;
if (this->_M_pback_init)
{
- if (__n && this->_M_in_cur == this->_M_in_beg)
+ if (__n && this->gptr() == this->eback())
{
- *__s++ = *this->_M_in_cur++;
+ *__s++ = *this->gptr();
+ this->gbump(1);
__ret = 1;
}
_M_destroy_pback();
@@ -427,10 +427,13 @@ namespace std
_M_output_unshift();
// This function sets the pointers of the internal buffer, both get
- // and put areas. Typically, __off == _M_in_end - _M_in_beg upon
- // _M_underflow; __off == 0 upon overflow, seekoff, open, setbuf.
+ // and put areas. Typically:
+ //
+ // __off == egptr() - eback() upon underflow/uflow ('read' mode);
+ // __off == 0 upon overflow ('write' mode);
+ // __off == -1 upon open, setbuf, seekoff/pos ('uncommitted' mode).
//
- // NB: _M_out_end - _M_out_beg == _M_buf_size - 1, since _M_buf_size
+ // NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size
// reflects the actual allocated memory and the last cell is reserved
// for the overflow char of a full put area.
void
@@ -439,14 +442,15 @@ namespace std
const bool __testin = this->_M_mode & ios_base::in;
const bool __testout = this->_M_mode & ios_base::out;
- if (__testin)
+ if (__testin && __off > 0)
this->setg(this->_M_buf, this->_M_buf, this->_M_buf + __off);
- if (__testout && this->_M_buf_size > 1)
- {
- this->setp(this->_M_buf, this->_M_buf + this->_M_buf_size - 1);
- this->_M_out_lim += __off;
- }
- _M_filepos = this->_M_buf + __off;
+ else
+ this->setg(this->_M_buf, this->_M_buf, this->_M_buf);
+
+ if (__testout && __off == 0 && this->_M_buf_size > 1 )
+ this->setp(this->_M_buf, this->_M_buf + this->_M_buf_size - 1);
+ else
+ this->setp(NULL, NULL);
}
};
OpenPOWER on IntegriCloud