diff -r e1b950c65cb4 -r 837f303aceeb epoc32/include/stdapis/stlportv5/stl/_streambuf.h --- a/epoc32/include/stdapis/stlportv5/stl/_streambuf.h Wed Mar 31 12:27:01 2010 +0100 +++ b/epoc32/include/stdapis/stlportv5/stl/_streambuf.h Wed Mar 31 12:33:34 2010 +0100 @@ -1,34 +1,26 @@ /* - * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. - * * Copyright (c) 1999 * Silicon Graphics Computer Systems, Inc. * - * Copyright (c) 1999 + * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * - * Permission to use or copy this software for any purpose is hereby granted + * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * - */ + */ #ifndef _STLP_INTERNAL_STREAMBUF #define _STLP_INTERNAL_STREAMBUF #ifndef _STLP_IOS_BASE_H -#include // Needed for ios_base bitfield members. - // includes . -#endif - -#ifndef _STLP_STDIO_FILE_H -#include // Declaration of struct FILE, and of - // functions to manipulate it. -#endif +# include // Needed for ios_base bitfield members. +#endif // includes . _STLP_BEGIN_NAMESPACE @@ -50,15 +42,10 @@ // The second template parameter, _Traits, defaults to char_traits<_CharT>. // The default is declared in header , and it isn't declared here -// because C++ language rules do not allow it to be declared twice. +// because C++ language rules do not allow it to be declared twice. template -#ifdef __SYMBIAN32__ -class basic_streambuf -#else -class basic_streambuf -#endif -{ +class basic_streambuf { friend class basic_istream<_CharT, _Traits>; friend class basic_ostream<_CharT, _Traits>; @@ -81,20 +68,29 @@ locale _M_locale; // The streambuf's locale object -public: // Extension: locking, for thread safety. - _STLP_mutex _M_lock; +//public: // Extension: locking, for thread safety. +// _STLP_mutex _M_lock; public: // Destructor. - _STLP_DECLSPEC virtual ~basic_streambuf(); + virtual ~basic_streambuf(); protected: // The default constructor. - _STLP_DECLSPEC basic_streambuf(); + basic_streambuf() +#if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB) + //We make it inline to avoid unresolved symbol. + : _M_gbegin(0), _M_gnext(0), _M_gend(0), + _M_pbegin(0), _M_pnext(0), _M_pend(0), + _M_locale() + {} +#else + ; +#endif protected: // Protected interface to the get area. char_type* eback() const { return _M_gbegin; } // Beginning char_type* gptr() const { return _M_gnext; } // Current position char_type* egptr() const { return _M_gend; } // End - + void gbump(int __n) { _M_gnext += __n; } void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) { _M_gbegin = __gbegin; @@ -106,13 +102,12 @@ // An alternate public interface to the above functions // which allows us to avoid using templated friends which // are not supported on some compilers. - char_type* _M_eback() const { return eback(); } char_type* _M_gptr() const { return gptr(); } char_type* _M_egptr() const { return egptr(); } void _M_gbump(int __n) { gbump(__n); } void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) - { setg(__gbegin, __gnext, __gend); } + { this->setg(__gbegin, __gnext, __gend); } protected: // Protected interface to the put area @@ -129,34 +124,34 @@ protected: // Virtual buffer management functions. - _STLP_DECLSPEC virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize); + virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize); // Alters the stream position, using an integer offset. In this // class seekoff does nothing; subclasses are expected to override it. - _STLP_DECLSPEC virtual pos_type seekoff(off_type, ios_base::seekdir, + virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out); // Alters the stream position, using a previously obtained streampos. In // this class seekpos does nothing; subclasses are expected to override it. - _STLP_DECLSPEC virtual pos_type + virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out); - // Synchronizes (i.e. flushes) the buffer. All subclasses are expected to + // Synchronizes (i.e. flushes) the buffer. All subclasses are expected to // override this virtual member function. - _STLP_DECLSPEC virtual int sync(); + virtual int sync(); public: // Buffer management. - basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n) - { return this->setbuf(__s, __n); } + basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n) + { return this->setbuf(__s, __n); } pos_type pubseekoff(off_type __offset, ios_base::seekdir __way, ios_base::openmode __mod = ios_base::in | ios_base::out) - { return this->seekoff(__offset, __way, __mod); } + { return this->seekoff(__offset, __way, __mod); } pos_type pubseekpos(pos_type __sp, ios_base::openmode __mod = ios_base::in | ios_base::out) - { return this->seekpos(__sp, __mod); } + { return this->seekpos(__sp, __mod); } int pubsync() { return this->sync(); } @@ -166,40 +161,40 @@ // with underflow, before reaching end of file. (-1 is a special value: // it means that underflow will fail.) Most subclasses should probably // override this virtual member function. - _STLP_DECLSPEC virtual streamsize showmanyc(); + virtual streamsize showmanyc(); - // Reads up to __n characters. Return value is the number of + // Reads up to __n characters. Return value is the number of // characters read. - _STLP_DECLSPEC virtual streamsize xsgetn(char_type* __s, streamsize __n); + virtual streamsize xsgetn(char_type* __s, streamsize __n); // Called when there is no read position, i.e. when gptr() is null // or when gptr() >= egptr(). Subclasses are expected to override // this virtual member function. - _STLP_DECLSPEC virtual int_type underflow(); + virtual int_type underflow(); - // Similar to underflow(), but used for unbuffered input. Most + // Similar to underflow(), but used for unbuffered input. Most // subclasses should probably override this virtual member function. - _STLP_DECLSPEC virtual int_type uflow(); + virtual int_type uflow(); // Called when there is no putback position, i.e. when gptr() is null // or when gptr() == eback(). All subclasses are expected to override // this virtual member function. - _STLP_DECLSPEC virtual int_type pbackfail(int_type = traits_type::eof()); + virtual int_type pbackfail(int_type = traits_type::eof()); protected: // Virtual put area functions, as defined in // 27.5.2.4.5 of the standard. // Writes up to __n characters. Return value is the number of characters // written. - _STLP_DECLSPEC virtual streamsize xsputn(const char_type* __s, streamsize __n); + virtual streamsize xsputn(const char_type* __s, streamsize __n); // Extension: writes up to __n copies of __c. Return value is the number // of characters written. - _STLP_DECLSPEC virtual streamsize _M_xsputnc(char_type __c, streamsize __n); + virtual streamsize _M_xsputnc(char_type __c, streamsize __n); // Called when there is no write position. All subclasses are expected to // override this virtual member function. - _STLP_DECLSPEC virtual int_type overflow(int_type = traits_type::eof()); + virtual int_type overflow(int_type = traits_type::eof()); public: // Public members for writing characters. // Write a single character. @@ -210,49 +205,48 @@ // Write __n characters. streamsize sputn(const char_type* __s, streamsize __n) - { return this->xsputn(__s, __n); } + { return this->xsputn(__s, __n); } // Extension: write __n copies of __c. streamsize _M_sputnc(char_type __c, streamsize __n) - { return this->_M_xsputnc(__c, __n); } + { return this->_M_xsputnc(__c, __n); } private: // Helper functions. - _STLP_DECLSPEC int_type _M_snextc_aux(); - + int_type _M_snextc_aux(); public: // Public members for reading characters. streamsize in_avail() { return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc(); } - + // Advance to the next character and return it. int_type snextc() { - return ( _M_gend - _M_gnext > 1 ? + return ( _M_gend - _M_gnext > 1 ? _Traits::to_int_type(*++_M_gnext) : this->_M_snextc_aux()); } // Return the current character and advance to the next. int_type sbumpc() { - return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++) + return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++) : this->uflow(); } - + // Return the current character without advancing to the next. int_type sgetc() { - return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext) + return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext) : this->underflow(); } - + streamsize sgetn(char_type* __s, streamsize __n) { return this->xsgetn(__s, __n); } - + int_type sputbackc(char_type __c) { return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1))) ? _Traits::to_int_type(*--_M_gnext) : this->pbackfail(_Traits::to_int_type(__c)); } - + int_type sungetc() { return (_M_gbegin < _M_gnext) ? _Traits::to_int_type(*--_M_gnext) @@ -265,16 +259,16 @@ // sets the streambuf's locale to __loc. Note that imbue should // not (and cannot, since it has no access to streambuf's private // members) set the streambuf's locale itself. - _STLP_DECLSPEC virtual void imbue(const locale&); + virtual void imbue(const locale&); public: // Locale-related functions. - _STLP_DECLSPEC locale pubimbue(const locale&); + locale pubimbue(const locale&); locale getloc() const { return _M_locale; } -# ifndef _STLP_NO_ANACHRONISMS +#if !defined (_STLP_NO_ANACHRONISMS) void stossc() { this->sbumpc(); } -# endif -#if defined(__MVS__) || defined(__OS400__) +#endif +#if defined (__MVS__) || defined (__OS400__) private: // Data members. char_type* _M_gbegin; // Beginning of get area @@ -287,251 +281,21 @@ #endif }; +#if defined (_STLP_USE_TEMPLATE_EXPORT) +_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf >; +# if !defined (_STLP_NO_WCHAR_T) +_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf >; +# endif // _STLP_NO_WCHAR_T +#endif // _STLP_USE_TEMPLATE_EXPORT -//---------------------------------------------------------------------- -// Specialization: basic_streambuf > +_STLP_END_NAMESPACE -// We implement basic_streambuf > very differently -// than the general basic_streambuf<> template. The main reason for this -// difference is a requirement in the C++ standard: the standard input -// and output streams cin and cout are required by default to be synchronized -// with the C library components stdin and stdout. This means it must be -// possible to synchronize a basic_streambuf with a C buffer. -// -// There are two basic ways to do that. First, the streambuf could be -// unbuffered and delegate all buffering to stdio operations. This -// would be correct, but slow: it would require at least one virtual -// function call for every character. Second, the streambuf could use -// a C stdio FILE as its buffer. -// -// We choose the latter option. Every streambuf has pointers to two -// FILE objects, one for the get area and one for the put area. Ordinarily -// it just uses a FILE object as a convenient way to package the three -// get/put area pointers. If a basic_streambuf is synchronized with -// a stdio stream, though, then the pointers are to a FILE object that's -// also used by the C library. -// -// The header encapsulates the implementation details -// of struct FILE. It contains low-level inline functions that convert -// between whe FILE's internal representation and the three-pointer -// representation that basic_streambuf<> needs. - -_STLP_TEMPLATE_NULL -#ifdef __SYMBIAN32__ -class basic_streambuf > -#else -class _STLP_CLASS_DECLSPEC basic_streambuf > -#endif -{ - friend class basic_istream >; - friend class basic_ostream >; -public: // Typedefs. - typedef char char_type; - typedef char_traits::int_type int_type; - typedef char_traits::pos_type pos_type; - typedef char_traits::off_type off_type; - typedef char_traits traits_type; - -private: // Data members. - - FILE* _M_get; // Reference to the get area - FILE* _M_put; // Reference to the put area - -#if defined(__hpux) - _FILEX _M_default_get; // Get area, unless we're syncing with stdio. - _FILEX _M_default_put; // Put area, unless we're syncing with stdio. -#else - FILE _M_default_get; // Get area, unless we're syncing with stdio. - FILE _M_default_put; // Put area, unless we're syncing with stdio. +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) +# include #endif - locale _M_locale; - -public: // Extension: locking, for thread safety. - _STLP_mutex _M_lock; - -public: // Destructor. - _STLP_DECLSPEC virtual ~basic_streambuf _STLP_PSPEC2(char, char_traits) (); - -public: - // The default constructor; defined here inline as some compilers require it - _STLP_DECLSPEC basic_streambuf _STLP_PSPEC2(char, char_traits) (); - // Extension: a constructor for streambufs synchronized with C stdio files. - _STLP_DECLSPEC basic_streambuf _STLP_PSPEC2(char, char_traits) (FILE* __get, FILE* __put); - -protected: // Protected interface to the get area. - char_type* eback() const { return _FILE_I_begin(_M_get); } - char_type* gptr() const { return _FILE_I_next(_M_get); } - char_type* egptr() const { return _FILE_I_end(_M_get); } - void gbump(int __n) { _FILE_I_bump(_M_get, __n); } - void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) - { - _FILE_I_set(_M_get, __gbegin, __gnext, __gend); -#ifdef __SYMBIAN32__ - _change_input_mode(); -#endif - } - -public: - // An alternate public interface to the above functions - // which allows us to avoid using templated friends which - // are not supported on some compilers. - - char_type* _M_eback() const { return _FILE_I_begin(_M_get); } - char_type* _M_gptr() const { return _FILE_I_next(_M_get); } - char_type* _M_egptr() const { return _FILE_I_end(_M_get); } - - void _M_gbump(int __n) { _FILE_I_bump(_M_get, __n); } - void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) - { _FILE_I_set(_M_get, __gbegin, __gnext, __gend); } - -protected: // Protected interface to the put area - char_type* pbase() const { return _FILE_O_begin(_M_put); } - char_type* pptr() const { return _FILE_O_next(_M_put); } - char_type* epptr() const { return _FILE_O_end(_M_put); } - - void pbump(int __n) { _FILE_O_bump(_M_put, __n); } - void setp(char_type* __pbegin, char_type* __pend) - { _FILE_O_set(_M_put, __pbegin, __pbegin, __pend); } - -protected: // Virtual buffer-management functions. - _STLP_DECLSPEC virtual basic_streambuf >* setbuf(char_type*, streamsize); - _STLP_DECLSPEC virtual pos_type seekoff(off_type, ios_base::seekdir, - ios_base::openmode = ios_base::in | ios_base::out); - _STLP_DECLSPEC virtual pos_type - seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out); - _STLP_DECLSPEC virtual int sync(); - -public: // Buffer management. - basic_streambuf >* pubsetbuf(char_type* __s, streamsize __n) - { return this->setbuf(__s, __n); } - - pos_type pubseekoff(off_type __offset, ios_base::seekdir __way, - ios_base::openmode __mod = ios_base::in | ios_base::out) - { return this->seekoff(__offset, __way, __mod); } - - pos_type pubseekpos(pos_type __sp, - ios_base::openmode __mod = ios_base::in | ios_base::out) - { return this->seekpos(__sp, __mod); } - - int pubsync() { return this->sync(); } - -protected: // Virtual get area functions. - _STLP_DECLSPEC virtual streamsize showmanyc(); - _STLP_DECLSPEC virtual streamsize xsgetn(char_type* __s, streamsize __n); - _STLP_DECLSPEC virtual int_type underflow(); - _STLP_DECLSPEC virtual int_type uflow(); - _STLP_DECLSPEC virtual int_type pbackfail(int_type __c = traits_type::eof()); - -protected: // Virtual put area functions. - _STLP_DECLSPEC virtual streamsize xsputn(const char_type* __s, streamsize __n); - _STLP_DECLSPEC virtual streamsize _M_xsputnc(char_type __c, streamsize __n); - _STLP_DECLSPEC virtual int_type overflow(int_type = traits_type::eof()); -#ifdef __SYMBIAN32__ - virtual int save_read_buffer () { return 0; } - virtual void _change_input_mode() {}; -#endif -public: // Public members for writing characters. - // Write a single character. - int_type sputc(char_type __c) { - int_type __res; - if( _FILE_O_avail(_M_put) > 0 ) - { - _FILE_O_postincr(_M_put) = __c; - __res = traits_type::to_int_type(__c); - } - else - __res = this->overflow(traits_type::to_int_type(__c)); - return __res; - } - - // Write __n characters. - streamsize sputn(const char_type* __s, streamsize __n) - { return this->xsputn(__s, __n); } - - // Extension: write __n copies of __c. - streamsize _M_sputnc(char_type __c, streamsize __n) - { return this->_M_xsputnc(__c, __n); } - -private: // Helper functions. - _STLP_DECLSPEC int_type _M_snextc_aux(); - -public: // Public members for reading characters. - streamsize in_avail() - { return _FILE_I_avail(_M_get) > 0 ? _FILE_I_avail(_M_get) -#ifdef __SYMBIAN32__ - + save_read_buffer() -#endif - : this->showmanyc(); } - - // Advance to the next character and return it. - int_type snextc() { - return _FILE_I_avail(_M_get) > 1 - ? traits_type::to_int_type(_FILE_I_preincr(_M_get)) - : this->_M_snextc_aux(); - } - - // Return the current character and advance to the next. - int_type sbumpc() { - return _FILE_I_avail(_M_get) > 0 - ? traits_type::to_int_type(_FILE_I_postincr(_M_get)) - : this->uflow(); - } - - // Return the current character without advancing to the next. - int_type sgetc() { - return _FILE_I_avail(_M_get) > 0 - ? traits_type::to_int_type(*_FILE_I_next(_M_get)) - : this->underflow(); - } - - streamsize sgetn(char_type* __s, streamsize __n) - { return this->xsgetn(__s, __n); } - - int_type sputbackc(char_type __c) { - return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get) && - __c == *(_FILE_I_next(_M_get) - 1) - ? traits_type::to_int_type(_FILE_I_predecr(_M_get)) - : this->pbackfail(traits_type::to_int_type(__c)); - } - - int_type sungetc() { - return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get) - ? traits_type::to_int_type(_FILE_I_predecr(_M_get)) - : this->pbackfail(); - } - -protected: // Virtual locale functions. - _STLP_DECLSPEC virtual void imbue(const locale&); -public: // Locale-related functions. - _STLP_DECLSPEC locale pubimbue(const locale&); - locale getloc() const { return _M_locale; } - -# ifndef _STLP_NO_ANACHRONISMS -public: - void stossc() { this->sbumpc(); } -# endif - -#if defined(__MVS__) || defined(__OS400__) -private: // Data members. - - char_type* _M_gbegin; // Beginning of get area - char_type* _M_gnext; // Current position within the get area - char_type* _M_gend; // End of get area - - char_type* _M_pbegin; // Beginning of put area - char_type* _M_pnext; // Current position within the put area - char_type* _M_pend; // End of put area #endif -}; -_STLP_END_NAMESPACE - -# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) -# include -# endif - -#endif // Local Variables: // mode:C++ // End: