1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_streambuf.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,301 @@
1.4 +/*
1.5 + * Copyright (c) 1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +#ifndef _STLP_INTERNAL_STREAMBUF
1.22 +#define _STLP_INTERNAL_STREAMBUF
1.23 +
1.24 +#ifndef _STLP_IOS_BASE_H
1.25 +# include <stl/_ios_base.h> // Needed for ios_base bitfield members.
1.26 +#endif // <ios_base> includes <iosfwd>.
1.27 +
1.28 +_STLP_BEGIN_NAMESPACE
1.29 +
1.30 +//----------------------------------------------------------------------
1.31 +// Class basic_streambuf<>, the base class of the streambuf hierarchy.
1.32 +
1.33 +// A basic_streambuf<> manages an input (get) area and an output (put)
1.34 +// area. Each is described by three pointers: a beginning, an end, and a
1.35 +// current position. basic_streambuf<> contains some very simple member
1.36 +// functions that manipulate those six pointers, but almost all of the real
1.37 +// functionality gets delegated to protected virtual member functions.
1.38 +// All of the public member functions are inline, and most of the protected
1.39 +// member functions are virtual.
1.40 +
1.41 +// Although basic_streambuf<> is not abstract, it is useful only as a base
1.42 +// class. Its virtual member functions have default definitions such that
1.43 +// reading from a basic_streambuf<> will always yield EOF, and writing to a
1.44 +// basic_streambuf<> will always fail.
1.45 +
1.46 +// The second template parameter, _Traits, defaults to char_traits<_CharT>.
1.47 +// The default is declared in header <iosfwd>, and it isn't declared here
1.48 +// because C++ language rules do not allow it to be declared twice.
1.49 +
1.50 +template <class _CharT, class _Traits>
1.51 +class basic_streambuf {
1.52 + friend class basic_istream<_CharT, _Traits>;
1.53 + friend class basic_ostream<_CharT, _Traits>;
1.54 +
1.55 +public: // Typedefs.
1.56 + typedef _CharT char_type;
1.57 + typedef typename _Traits::int_type int_type;
1.58 + typedef typename _Traits::pos_type pos_type;
1.59 + typedef typename _Traits::off_type off_type;
1.60 + typedef _Traits traits_type;
1.61 +
1.62 +private: // Data members.
1.63 +
1.64 + char_type* _M_gbegin; // Beginning of get area
1.65 + char_type* _M_gnext; // Current position within the get area
1.66 + char_type* _M_gend; // End of get area
1.67 +
1.68 + char_type* _M_pbegin; // Beginning of put area
1.69 + char_type* _M_pnext; // Current position within the put area
1.70 + char_type* _M_pend; // End of put area
1.71 +
1.72 + locale _M_locale; // The streambuf's locale object
1.73 +
1.74 +//public: // Extension: locking, for thread safety.
1.75 +// _STLP_mutex _M_lock;
1.76 +
1.77 +public: // Destructor.
1.78 + virtual ~basic_streambuf();
1.79 +
1.80 +protected: // The default constructor.
1.81 + basic_streambuf()
1.82 +#if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB)
1.83 + //We make it inline to avoid unresolved symbol.
1.84 + : _M_gbegin(0), _M_gnext(0), _M_gend(0),
1.85 + _M_pbegin(0), _M_pnext(0), _M_pend(0),
1.86 + _M_locale()
1.87 + {}
1.88 +#else
1.89 + ;
1.90 +#endif
1.91 +
1.92 +protected: // Protected interface to the get area.
1.93 + char_type* eback() const { return _M_gbegin; } // Beginning
1.94 + char_type* gptr() const { return _M_gnext; } // Current position
1.95 + char_type* egptr() const { return _M_gend; } // End
1.96 +
1.97 + void gbump(int __n) { _M_gnext += __n; }
1.98 + void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) {
1.99 + _M_gbegin = __gbegin;
1.100 + _M_gnext = __gnext;
1.101 + _M_gend = __gend;
1.102 + }
1.103 +
1.104 +public:
1.105 + // An alternate public interface to the above functions
1.106 + // which allows us to avoid using templated friends which
1.107 + // are not supported on some compilers.
1.108 + char_type* _M_eback() const { return eback(); }
1.109 + char_type* _M_gptr() const { return gptr(); }
1.110 + char_type* _M_egptr() const { return egptr(); }
1.111 + void _M_gbump(int __n) { gbump(__n); }
1.112 + void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
1.113 + { this->setg(__gbegin, __gnext, __gend); }
1.114 +
1.115 +protected: // Protected interface to the put area
1.116 +
1.117 + char_type* pbase() const { return _M_pbegin; } // Beginning
1.118 + char_type* pptr() const { return _M_pnext; } // Current position
1.119 + char_type* epptr() const { return _M_pend; } // End
1.120 +
1.121 + void pbump(int __n) { _M_pnext += __n; }
1.122 + void setp(char_type* __pbegin, char_type* __pend) {
1.123 + _M_pbegin = __pbegin;
1.124 + _M_pnext = __pbegin;
1.125 + _M_pend = __pend;
1.126 + }
1.127 +
1.128 +protected: // Virtual buffer management functions.
1.129 +
1.130 + virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
1.131 +
1.132 + // Alters the stream position, using an integer offset. In this
1.133 + // class seekoff does nothing; subclasses are expected to override it.
1.134 + virtual pos_type seekoff(off_type, ios_base::seekdir,
1.135 + ios_base::openmode = ios_base::in | ios_base::out);
1.136 +
1.137 + // Alters the stream position, using a previously obtained streampos. In
1.138 + // this class seekpos does nothing; subclasses are expected to override it.
1.139 + virtual pos_type
1.140 + seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
1.141 +
1.142 + // Synchronizes (i.e. flushes) the buffer. All subclasses are expected to
1.143 + // override this virtual member function.
1.144 + virtual int sync();
1.145 +
1.146 +
1.147 +public: // Buffer management.
1.148 + basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
1.149 + { return this->setbuf(__s, __n); }
1.150 +
1.151 + pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
1.152 + ios_base::openmode __mod = ios_base::in | ios_base::out)
1.153 + { return this->seekoff(__offset, __way, __mod); }
1.154 +
1.155 + pos_type pubseekpos(pos_type __sp,
1.156 + ios_base::openmode __mod = ios_base::in | ios_base::out)
1.157 + { return this->seekpos(__sp, __mod); }
1.158 +
1.159 + int pubsync() { return this->sync(); }
1.160 +
1.161 +protected: // Virtual get area functions, as defined in
1.162 + // 17.5.2.4.3 and 17.5.2.4.4 of the standard.
1.163 + // Returns a lower bound on the number of characters that we can read,
1.164 + // with underflow, before reaching end of file. (-1 is a special value:
1.165 + // it means that underflow will fail.) Most subclasses should probably
1.166 + // override this virtual member function.
1.167 + virtual streamsize showmanyc();
1.168 +
1.169 + // Reads up to __n characters. Return value is the number of
1.170 + // characters read.
1.171 + virtual streamsize xsgetn(char_type* __s, streamsize __n);
1.172 +
1.173 + // Called when there is no read position, i.e. when gptr() is null
1.174 + // or when gptr() >= egptr(). Subclasses are expected to override
1.175 + // this virtual member function.
1.176 + virtual int_type underflow();
1.177 +
1.178 + // Similar to underflow(), but used for unbuffered input. Most
1.179 + // subclasses should probably override this virtual member function.
1.180 + virtual int_type uflow();
1.181 +
1.182 + // Called when there is no putback position, i.e. when gptr() is null
1.183 + // or when gptr() == eback(). All subclasses are expected to override
1.184 + // this virtual member function.
1.185 + virtual int_type pbackfail(int_type = traits_type::eof());
1.186 +
1.187 +protected: // Virtual put area functions, as defined in
1.188 + // 27.5.2.4.5 of the standard.
1.189 +
1.190 + // Writes up to __n characters. Return value is the number of characters
1.191 + // written.
1.192 + virtual streamsize xsputn(const char_type* __s, streamsize __n);
1.193 +
1.194 + // Extension: writes up to __n copies of __c. Return value is the number
1.195 + // of characters written.
1.196 + virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
1.197 +
1.198 + // Called when there is no write position. All subclasses are expected to
1.199 + // override this virtual member function.
1.200 + virtual int_type overflow(int_type = traits_type::eof());
1.201 +
1.202 +public: // Public members for writing characters.
1.203 + // Write a single character.
1.204 + int_type sputc(char_type __c) {
1.205 + return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
1.206 + : this->overflow(_Traits::to_int_type(__c)));
1.207 + }
1.208 +
1.209 + // Write __n characters.
1.210 + streamsize sputn(const char_type* __s, streamsize __n)
1.211 + { return this->xsputn(__s, __n); }
1.212 +
1.213 + // Extension: write __n copies of __c.
1.214 + streamsize _M_sputnc(char_type __c, streamsize __n)
1.215 + { return this->_M_xsputnc(__c, __n); }
1.216 +
1.217 +private: // Helper functions.
1.218 + int_type _M_snextc_aux();
1.219 +
1.220 +public: // Public members for reading characters.
1.221 + streamsize in_avail() {
1.222 + return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc();
1.223 + }
1.224 +
1.225 + // Advance to the next character and return it.
1.226 + int_type snextc() {
1.227 + return ( _M_gend - _M_gnext > 1 ?
1.228 + _Traits::to_int_type(*++_M_gnext) :
1.229 + this->_M_snextc_aux());
1.230 + }
1.231 +
1.232 + // Return the current character and advance to the next.
1.233 + int_type sbumpc() {
1.234 + return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++)
1.235 + : this->uflow();
1.236 + }
1.237 +
1.238 + // Return the current character without advancing to the next.
1.239 + int_type sgetc() {
1.240 + return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext)
1.241 + : this->underflow();
1.242 + }
1.243 +
1.244 + streamsize sgetn(char_type* __s, streamsize __n)
1.245 + { return this->xsgetn(__s, __n); }
1.246 +
1.247 + int_type sputbackc(char_type __c) {
1.248 + return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1)))
1.249 + ? _Traits::to_int_type(*--_M_gnext)
1.250 + : this->pbackfail(_Traits::to_int_type(__c));
1.251 + }
1.252 +
1.253 + int_type sungetc() {
1.254 + return (_M_gbegin < _M_gnext)
1.255 + ? _Traits::to_int_type(*--_M_gnext)
1.256 + : this->pbackfail();
1.257 + }
1.258 +
1.259 +protected: // Virtual locale functions.
1.260 +
1.261 + // This is a hook, called by pubimbue() just before pubimbue()
1.262 + // sets the streambuf's locale to __loc. Note that imbue should
1.263 + // not (and cannot, since it has no access to streambuf's private
1.264 + // members) set the streambuf's locale itself.
1.265 + virtual void imbue(const locale&);
1.266 +
1.267 +public: // Locale-related functions.
1.268 + locale pubimbue(const locale&);
1.269 + locale getloc() const { return _M_locale; }
1.270 +
1.271 +#if !defined (_STLP_NO_ANACHRONISMS)
1.272 + void stossc() { this->sbumpc(); }
1.273 +#endif
1.274 +#if defined (__MVS__) || defined (__OS400__)
1.275 +private: // Data members.
1.276 +
1.277 + char_type* _M_gbegin; // Beginning of get area
1.278 + char_type* _M_gnext; // Current position within the get area
1.279 + char_type* _M_gend; // End of get area
1.280 +
1.281 + char_type* _M_pbegin; // Beginning of put area
1.282 + char_type* _M_pnext; // Current position within the put area
1.283 + char_type* _M_pend; // End of put area
1.284 +#endif
1.285 +};
1.286 +
1.287 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.288 +_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<char, char_traits<char> >;
1.289 +# if !defined (_STLP_NO_WCHAR_T)
1.290 +_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >;
1.291 +# endif // _STLP_NO_WCHAR_T
1.292 +#endif // _STLP_USE_TEMPLATE_EXPORT
1.293 +
1.294 +_STLP_END_NAMESPACE
1.295 +
1.296 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
1.297 +# include <stl/_streambuf.c>
1.298 +#endif
1.299 +
1.300 +#endif
1.301 +
1.302 +// Local Variables:
1.303 +// mode:C++
1.304 +// End: