aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/streambuf
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@gcc.gnu.org>2002-01-04 21:27:36 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2002-01-04 21:27:36 +0000
commit54c1bf7801758caf2ff54917e79a8c239643061c (patch)
treef9b7a5cf7ab77ab1aa83870039157784eb5398b3 /libstdc++-v3/include/std/streambuf
parent48180d6890b349f441109459b1575ef819e7651e (diff)
downloadgcc-54c1bf7801758caf2ff54917e79a8c239643061c.zip
gcc-54c1bf7801758caf2ff54917e79a8c239643061c.tar.gz
gcc-54c1bf7801758caf2ff54917e79a8c239643061c.tar.bz2
Makefile.am (std_headers): Remove cXXX from list.
2002-01-04 Benjamin Kosnik <bkoz@redhat.com> * include/Makefile.am (std_headers): Remove cXXX from list. (c_base_srcdir): No bits subdirectory. (c_base_builddir): Same. (c_base_headers): Adjust names, add ciso646. (bits_headers): Remove std_xxx.h headers. * include/Makefile.in: Regenerate. * include/ext/iterator: Adjust includes. * include/ext/ropeimpl.h: Same. * include/ext/stl_hash_fun.h: Same. * include/ext/algorithm: Same. * include/backward/bvector.h: Adjust includes. * include/backward/vector.h: Same. * include/backward/strstream: Same. * include/backward/streambuf.h: Same. * include/backward/stack.h: Same. * include/backward/set.h: Same. * include/backward/queue.h: Same. * include/backward/multiset.h: Same. * include/backward/multimap.h: Same. * include/backward/map.h: Same. * include/backward/list.h: Same. * include/backward/iterator.h: Same. * include/backward/iostream.h: Same. * include/backward/iomanip.h: Same. * include/backward/fstream.h: Same. * include/backward/deque.h: Same. * include/backward/complex.h: Same. * include/bits/std_algorithm.h: Move to... * include/std/algorithm: ...here. * include/bits/std_iosfwd.h, std_locale.h, std_stack.h, std_bitset.h, std_ios.h, std_map.h, std_stdexcept.h, std_complex.h, std_iostream.h, std_memory.h, std_streambuf.h, std_deque.h, std_istream.h, std_numeric.h, std_string.h, std_fstream.h, std_ostream.h, std_utility.h, std_iterator.h, std_queue.h, std_valarray.h, std_functional.h, std_limits.h, std_set.h, std_vector.h, std_iomanip.h, std_list.h, std_sstream.h: Same. * include/c_std/bits/std_cassert.h: Move to... * include/c_std/cassert: Here. * include/c_std/std_cctype.h, std_cerrno.h, std_cfloat.h, std_climits.h, std_clocale.h, std_cmath.h, std_csetjmp.h, std_csignal.h, std_cstdarg.h, std_cstddef.h, std_cstdio.h, std_cstdlib.h, std_cstring.h, std_ctime.h, std_cwchar.h, std_cwctype.h: Same. * include/c_std/cmath: Adjust cmath.tcc include. * include/c_std/cstdlib: Adjust includes. * include/c_std/cwchar: Same. * include/c_std/ctime: Same. * include/c_std/cstring: Same. * include/c_std/cstdio: Same. * include/c_std/bits: Remove directory. * include/c/bits/std_cassert.h: Move to... * include/c/cassert: Here. * include/c/std_cctype.h, std_cerrno.h, std_cfloat.h, std_climits.h, std_clocale.h, std_cmath.h, std_csetjmp.h, std_csignal.h, std_cstdarg.h, std_cstddef.h, std_cstdio.h, std_cstdlib.h, std_cstring.h, std_ctime.h, std_cwchar.h, std_cwctype.h: Same. * include/c/bits: Remove directory. * include/std/cwctype: Remove. * include/std/cwchar: Remove. * include/std/ctime: Remove. * include/std/cstring: Remove. * include/std/cstdlib: Remove. * include/std/cstdio: Remove. * include/std/cstddef: Remove. * include/std/cstdarg: Remove. * include/std/csignal: Remove. * include/std/csetjmp: Remove. * include/std/cmath: Remove. * include/std/clocale: Remove. * include/std/climits: Remove. * include/std/ciso646: Remove. * include/std/cfloat: Remove. * include/std/cerrno: Remove. * include/std/cctype: Remove. * include/std/cassert: Remove. * include/bits/fpos.h: Adjust includes, removing <bits/std_xxx.h> files and subsituting <.xxx> * include/bits/valarray_array.h: Same. * include/bits/stl_uninitialized.h: Same. * include/bits/stl_alloc.h: Same. * include/bits/stl_algobase.h: Same. * include/bits/sstream.tcc: Same. * include/bits/pthread_allocimpl.h: Same. * include/bits/ostream.tcc: Same. * include/bits/localefwd.h: Same. * include/bits/locale_facets.tcc: Same. * include/bits/locale_facets.h: Same. * include/bits/istream.tcc: Same. * include/bits/char_traits.h: Same. * include/bits/boost_concept_check.h: Same. * include/bits/basic_file.h: Same. * include/std/bitset: Same. * include/std/complex: Same. * include/std/fstream: Same. * include/std/functional: Same. * include/std/ios: Same. * include/std/iostream: Same. * include/std/ostream: Same. * include/std/sstream: Same. * include/std/streambuf: Same. * include/std/string: Same. * include/std/iterator: Same. * include/std/valarray: Same. * src/ios.cc: Adjust includes. * src/valarray-inst.cc: Same. * src/string-inst.cc: Same. * src/stl-inst.cc: Same. * src/stdexcept.cc: Same. * src/misc-inst.cc: Same. * src/localename.cc: Same. * src/locale-inst.cc: Same. * src/locale.cc: Same. * src/limits.cc: Same. * src/concept-inst.cc: Same. * src/complex_io.cc: Same. * src/codecvt.cc: Same. * src/bitset.cc: Same. * src/cmath.cc: Same. From-SVN: r48544
Diffstat (limited to 'libstdc++-v3/include/std/streambuf')
-rw-r--r--libstdc++-v3/include/std/streambuf515
1 files changed, 509 insertions, 6 deletions
diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf
index c0f4dd7..59f7070 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -1,6 +1,6 @@
-// -*- C++ -*- std header.
+// Stream buffer classes -*- C++ -*-
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -27,11 +27,514 @@
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
-/** @file streambuf
- * This is a Standard C++ Library file. You should @c #include this file
- * in your programs, rather than any of the "st[dl]_*.h" implementation files.
+//
+// ISO C++ 14882: 27.5 Stream buffers
+//
+
+/** @file std_streambuf.h
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
*/
#ifndef _CPP_STREAMBUF
-#include <bits/std_streambuf.h>
+#define _CPP_STREAMBUF 1
+
+#pragma GCC system_header
+
+#include <bits/c++config.h>
+#include <iosfwd>
+#include <cstdio> // For SEEK_SET, SEEK_CUR, SEEK_END
+#include <bits/localefwd.h>
+#include <bits/ios_base.h>
+
+namespace std
+{
+ template<typename _CharT, typename _Traits>
+ streamsize
+ __copy_streambufs(basic_ios<_CharT, _Traits>& _ios,
+ basic_streambuf<_CharT, _Traits>* __sbin,
+ basic_streambuf<_CharT, _Traits>* __sbout);
+
+ // 27.5.2 Template class basic_streambuf<_CharT, _Traits>
+ template<typename _CharT, typename _Traits>
+ class basic_streambuf
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef typename traits_type::int_type int_type;
+ typedef typename traits_type::pos_type pos_type;
+ typedef typename traits_type::off_type off_type;
+
+ // Non-standard Types:
+ typedef ctype<char_type> __ctype_type;
+ typedef basic_streambuf<char_type, traits_type> __streambuf_type;
+
+ friend class basic_ios<char_type, traits_type>;
+ friend class basic_istream<char_type, traits_type>;
+ friend class basic_ostream<char_type, traits_type>;
+ friend class istreambuf_iterator<char_type, traits_type>;
+ friend class ostreambuf_iterator<char_type, traits_type>;
+
+ friend streamsize
+ __copy_streambufs<>(basic_ios<char_type, traits_type>& __ios,
+ __streambuf_type* __sbin,__streambuf_type* __sbout);
+
+ protected:
+
+ // Pointer to the beginning of internally-allocated
+ // space. Filebuf manually allocates/deallocates this, whereas
+ // stringstreams attempt to use the built-in intelligence of the
+ // string class. If you are managing memory, set this. If not,
+ // leave it NULL.
+ char_type* _M_buf;
+
+ // Actual size of allocated internal buffer, in bytes.
+ int_type _M_buf_size;
+
+ // Optimal or preferred size of internal buffer, in bytes.
+ int_type _M_buf_size_opt;
+
+ // True iff _M_in_* and _M_out_* buffers should always point to
+ // the same place. True for fstreams, false for sstreams.
+ bool _M_buf_unified;
+
+ // This is based on _IO_FILE, just reordered to be more
+ // consistent, and is intended to be the most minimal abstraction
+ // for an internal buffer.
+ // get == input == read
+ // put == output == write
+ 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_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.
+ ios_base::openmode _M_mode;
+
+ // Current locale setting.
+ locale _M_buf_locale;
+
+ // True iff locale is initialized.
+ bool _M_buf_locale_init;
+
+ // 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_in_cur pointer, and bumps the
+ // _M_out_cur pointer as well if necessary.
+ void
+ _M_in_cur_move(off_type __n) // argument needs to be +-
+ {
+ bool __testout = _M_out_cur;
+ _M_in_cur += __n;
+ if (__testout && _M_buf_unified)
+ _M_out_cur += __n;
+ }
+
+ // 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.
+ // Invariant:
+ // __n + _M_out_[cur, end] <= _M_buf + _M_buf_size
+ // Assuming all _M_*_[beg, cur, end] pointers are operating on
+ // the same range:
+ // _M_buf <= _M_*_ <= _M_buf + _M_buf_size
+ void
+ _M_out_cur_move(off_type __n) // argument needs to be +-
+ {
+ bool __testin = _M_in_cur;
+
+ _M_out_cur += __n;
+ if (__testin && _M_buf_unified)
+ _M_in_cur += __n;
+ if (_M_out_cur > _M_out_end)
+ {
+ _M_out_end = _M_out_cur;
+ // NB: in | out buffers drag the _M_in_end pointer along...
+ if (__testin)
+ _M_in_end += __n;
+ }
+ }
+
+ // Return the size of the output buffer. This depends on the
+ // buffer in use: allocated buffers have a stored size in
+ // _M_buf_size and setbuf() buffers don't.
+ off_type
+ _M_out_buf_size()
+ {
+ off_type __ret = 0;
+ if (_M_out_cur)
+ {
+ // Using allocated buffer.
+ if (_M_out_beg == _M_buf)
+ __ret = _M_out_beg + _M_buf_size - _M_out_cur;
+ // Using non-allocated buffer.
+ else
+ __ret = _M_out_end - _M_out_cur;
+ }
+ return __ret;
+ }
+
+ // These three functions are used to clarify internal buffer
+ // maintenance. After an overflow, or after a seekoff call that
+ // started at beg or end, or possibly when the stream becomes
+ // unbuffered, and a myrid other obscure corner cases, the
+ // internal buffer does not truly reflect the contents of the
+ // external buffer. At this point, for whatever reason, it is in
+ // an indeterminate state.
+ void
+ _M_set_indeterminate(void)
+ {
+ if (_M_mode & ios_base::in)
+ this->setg(_M_buf, _M_buf, _M_buf);
+ if (_M_mode & ios_base::out)
+ this->setp(_M_buf, _M_buf);
+ }
+
+ void
+ _M_set_determinate(off_type __off)
+ {
+ bool __testin = _M_mode & ios_base::in;
+ bool __testout = _M_mode & ios_base::out;
+ if (__testin)
+ this->setg(_M_buf, _M_buf, _M_buf + __off);
+ if (__testout)
+ this->setp(_M_buf, _M_buf + __off);
+ }
+
+ bool
+ _M_is_indeterminate(void)
+ {
+ bool __ret = false;
+ // Don't return true if unbuffered.
+ if (_M_buf)
+ {
+ if (_M_mode & ios_base::in)
+ __ret = _M_in_beg == _M_in_cur && _M_in_cur == _M_in_end;
+ if (_M_mode & ios_base::out)
+ __ret = _M_out_beg == _M_out_cur && _M_out_cur == _M_out_end;
+ }
+ return __ret;
+ }
+
+ public:
+ virtual
+ ~basic_streambuf()
+ {
+ _M_buf_unified = false;
+ _M_buf_size = 0;
+ _M_buf_size_opt = 0;
+ _M_mode = ios_base::openmode(0);
+ _M_buf_locale_init = false;
+ }
+
+ // Locales:
+ locale
+ pubimbue(const locale &__loc)
+ {
+ locale __tmp(this->getloc());
+ this->imbue(__loc);
+ return __tmp;
+ }
+
+ locale
+ getloc() const
+ {
+ if (_M_buf_locale_init)
+ return _M_buf_locale;
+ else
+ return locale();
+ }
+
+ // Buffer and positioning:
+ __streambuf_type*
+ pubsetbuf(char_type* __s, streamsize __n)
+ { return this->setbuf(__s, __n); }
+
+ pos_type
+ pubseekoff(off_type __off, ios_base::seekdir __way,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ { return this->seekoff(__off, __way, __mode); }
+
+ pos_type
+ pubseekpos(pos_type __sp,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ { return this->seekpos(__sp, __mode); }
+
+ int
+ pubsync() { return this->sync(); }
+
+ // Get and put areas:
+ // Get area:
+ streamsize
+ in_avail()
+ {
+ streamsize __ret;
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ {
+ 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;
+ __ret = __save_len - __pback_len;
+ }
+ else
+ __ret = this->egptr() - this->gptr();
+ }
+ else
+ __ret = this->showmanyc();
+ return __ret;
+ }
+
+ int_type
+ snextc()
+ {
+ int_type __eof = traits_type::eof();
+ return (this->sbumpc() == __eof ? __eof : this->sgetc());
+ }
+
+ int_type
+ sbumpc();
+
+ int_type
+ sgetc()
+ {
+ int_type __ret;
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ __ret = traits_type::to_int_type(*(this->gptr()));
+ else
+ __ret = this->underflow();
+ return __ret;
+ }
+
+ streamsize
+ sgetn(char_type* __s, streamsize __n)
+ { return this->xsgetn(__s, __n); }
+
+ // Putback:
+ int_type
+ sputbackc(char_type __c);
+
+ int_type
+ sungetc();
+
+ // Put area:
+ int_type
+ sputc(char_type __c);
+
+ streamsize
+ sputn(const char_type* __s, streamsize __n)
+ { return this->xsputn(__s, __n); }
+
+ protected:
+ basic_streambuf()
+ : _M_buf(NULL), _M_buf_size(0),
+ _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)
+ { }
+
+ // Get area:
+ char_type*
+ eback() const { return _M_in_beg; }
+
+ char_type*
+ gptr() const { return _M_in_cur; }
+
+ char_type*
+ egptr() const { return _M_in_end; }
+
+ void
+ gbump(int __n) { _M_in_cur += __n; }
+
+ void
+ setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
+ {
+ _M_in_beg = __gbeg;
+ _M_in_cur = __gnext;
+ _M_in_end = __gend;
+ if (!(_M_mode & ios_base::in) && __gbeg && __gnext && __gend)
+ _M_mode = _M_mode | ios_base::in;
+ }
+
+ // Put area:
+ char_type*
+ pbase() const { return _M_out_beg; }
+
+ char_type*
+ pptr() const { return _M_out_cur; }
+
+ char_type*
+ epptr() const { return _M_out_end; }
+
+ void
+ pbump(int __n) { _M_out_cur += __n; }
+
+ void
+ setp(char_type* __pbeg, char_type* __pend)
+ {
+ _M_out_beg = _M_out_cur = __pbeg;
+ _M_out_end = __pend;
+ if (!(_M_mode & ios_base::out) && __pbeg && __pend)
+ _M_mode = _M_mode | ios_base::out;
+ }
+
+ // Virtual functions:
+ // Locales:
+ virtual void
+ imbue(const locale& __loc)
+ {
+ _M_buf_locale_init = true;
+ if (_M_buf_locale != __loc)
+ _M_buf_locale = __loc;
+ }
+
+ // Buffer management and positioning:
+ virtual basic_streambuf<char_type,_Traits>*
+ setbuf(char_type*, streamsize)
+ { return this; }
+
+ virtual pos_type
+ seekoff(off_type, ios_base::seekdir,
+ ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
+ { return pos_type(off_type(-1)); }
+
+ virtual pos_type
+ seekpos(pos_type,
+ ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
+ { return pos_type(off_type(-1)); }
+
+ virtual int
+ sync() { return 0; }
+
+ // Get area:
+ virtual streamsize
+ showmanyc() { return 0; }
+
+ virtual streamsize
+ xsgetn(char_type* __s, streamsize __n);
+
+ virtual int_type
+ underflow()
+ { return traits_type::eof(); }
+
+ virtual int_type
+ uflow()
+ {
+ int_type __ret = traits_type::eof();
+ bool __testeof = this->underflow() == __ret;
+ bool __testpending = _M_in_cur && _M_in_cur < _M_in_end;
+ if (!__testeof && __testpending)
+ {
+ __ret = traits_type::to_int_type(*_M_in_cur);
+ ++_M_in_cur;
+ if (_M_buf_unified && _M_mode & ios_base::out)
+ ++_M_out_cur;
+ }
+ return __ret;
+ }
+
+ // Putback:
+ virtual int_type
+ pbackfail(int_type /* __c */ = traits_type::eof())
+ { return traits_type::eof(); }
+
+ // Put area:
+ virtual streamsize
+ xsputn(const char_type* __s, streamsize __n);
+
+ virtual int_type
+ overflow(int_type /* __c */ = traits_type::eof())
+ { return traits_type::eof(); }
+
+#ifdef _GLIBCPP_DEPRECATED
+ public:
+ void
+ stossc()
+ {
+ if (_M_in_cur < _M_in_end)
+ ++_M_in_cur;
+ else
+ this->uflow();
+ }
#endif
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Side effect of DR 50.
+ private:
+ basic_streambuf(const __streambuf_type&);
+
+ __streambuf_type&
+ operator=(const __streambuf_type&);
+#endif
+ };
+
+} // namespace std
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+#include <bits/streambuf.tcc>
+#endif
+#endif
+
+#endif /* _CPP_STREAMBUF */
+