Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_streambuf.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 #ifndef _STLP_INTERNAL_STREAMBUF 00019 #define _STLP_INTERNAL_STREAMBUF 00020 00021 #ifndef _STLP_IOS_BASE_H 00022 # include <stl/_ios_base.h> // Needed for ios_base bitfield members. 00023 #endif // <ios_base> includes <iosfwd>. 00024 00025 _STLP_BEGIN_NAMESPACE 00026 00027 //---------------------------------------------------------------------- 00028 // Class basic_streambuf<>, the base class of the streambuf hierarchy. 00029 00030 // A basic_streambuf<> manages an input (get) area and an output (put) 00031 // area. Each is described by three pointers: a beginning, an end, and a 00032 // current position. basic_streambuf<> contains some very simple member 00033 // functions that manipulate those six pointers, but almost all of the real 00034 // functionality gets delegated to protected virtual member functions. 00035 // All of the public member functions are inline, and most of the protected 00036 // member functions are virtual. 00037 00038 // Although basic_streambuf<> is not abstract, it is useful only as a base 00039 // class. Its virtual member functions have default definitions such that 00040 // reading from a basic_streambuf<> will always yield EOF, and writing to a 00041 // basic_streambuf<> will always fail. 00042 00043 // The second template parameter, _Traits, defaults to char_traits<_CharT>. 00044 // The default is declared in header <iosfwd>, and it isn't declared here 00045 // because C++ language rules do not allow it to be declared twice. 00046 00047 template <class _CharT, class _Traits> 00048 class basic_streambuf { 00049 friend class basic_istream<_CharT, _Traits>; 00050 friend class basic_ostream<_CharT, _Traits>; 00051 00052 public: // Typedefs. 00053 typedef _CharT char_type; 00054 typedef typename _Traits::int_type int_type; 00055 typedef typename _Traits::pos_type pos_type; 00056 typedef typename _Traits::off_type off_type; 00057 typedef _Traits traits_type; 00058 00059 private: // Data members. 00060 00061 char_type* _M_gbegin; // Beginning of get area 00062 char_type* _M_gnext; // Current position within the get area 00063 char_type* _M_gend; // End of get area 00064 00065 char_type* _M_pbegin; // Beginning of put area 00066 char_type* _M_pnext; // Current position within the put area 00067 char_type* _M_pend; // End of put area 00068 00069 locale _M_locale; // The streambuf's locale object 00070 00071 public: // Destructor. 00072 virtual ~basic_streambuf(); 00073 00074 protected: // The default constructor. 00075 basic_streambuf() 00076 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB) 00077 //We make it inline to avoid unresolved symbol. 00078 : _M_gbegin(0), _M_gnext(0), _M_gend(0), 00079 _M_pbegin(0), _M_pnext(0), _M_pend(0), 00080 _M_locale() 00081 {} 00082 #else 00083 ; 00084 #endif 00085 00086 protected: // Protected interface to the get area. 00087 char_type* eback() const { return _M_gbegin; } // Beginning 00088 char_type* gptr() const { return _M_gnext; } // Current position 00089 char_type* egptr() const { return _M_gend; } // End 00090 00091 void gbump(int __n) { _M_gnext += __n; } 00092 void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) { 00093 _M_gbegin = __gbegin; 00094 _M_gnext = __gnext; 00095 _M_gend = __gend; 00096 } 00097 00098 public: 00099 // An alternate public interface to the above functions 00100 // which allows us to avoid using templated friends which 00101 // are not supported on some compilers. 00102 char_type* _M_eback() const { return eback(); } 00103 char_type* _M_gptr() const { return gptr(); } 00104 char_type* _M_egptr() const { return egptr(); } 00105 void _M_gbump(int __n) { gbump(__n); } 00106 void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) 00107 { this->setg(__gbegin, __gnext, __gend); } 00108 00109 protected: // Protected interface to the put area 00110 00111 char_type* pbase() const { return _M_pbegin; } // Beginning 00112 char_type* pptr() const { return _M_pnext; } // Current position 00113 char_type* epptr() const { return _M_pend; } // End 00114 00115 void pbump(int __n) { _M_pnext += __n; } 00116 void setp(char_type* __pbegin, char_type* __pend) { 00117 _M_pbegin = __pbegin; 00118 _M_pnext = __pbegin; 00119 _M_pend = __pend; 00120 } 00121 00122 protected: // Virtual buffer management functions. 00123 00124 virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize); 00125 00126 // Alters the stream position, using an integer offset. In this 00127 // class seekoff does nothing; subclasses are expected to override it. 00128 virtual pos_type seekoff(off_type, ios_base::seekdir, 00129 ios_base::openmode = ios_base::in | ios_base::out); 00130 00131 // Alters the stream position, using a previously obtained streampos. In 00132 // this class seekpos does nothing; subclasses are expected to override it. 00133 virtual pos_type 00134 seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out); 00135 00136 // Synchronizes (i.e. flushes) the buffer. All subclasses are expected to 00137 // override this virtual member function. 00138 virtual int sync(); 00139 00140 00141 public: // Buffer management. 00142 basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n) 00143 { return this->setbuf(__s, __n); } 00144 00145 pos_type pubseekoff(off_type __offset, ios_base::seekdir __way, 00146 ios_base::openmode __mod = ios_base::in | ios_base::out) 00147 { return this->seekoff(__offset, __way, __mod); } 00148 00149 pos_type pubseekpos(pos_type __sp, 00150 ios_base::openmode __mod = ios_base::in | ios_base::out) 00151 { return this->seekpos(__sp, __mod); } 00152 00153 int pubsync() { return this->sync(); } 00154 00155 protected: // Virtual get area functions, as defined in 00156 // 17.5.2.4.3 and 17.5.2.4.4 of the standard. 00157 // Returns a lower bound on the number of characters that we can read, 00158 // with underflow, before reaching end of file. (-1 is a special value: 00159 // it means that underflow will fail.) Most subclasses should probably 00160 // override this virtual member function. 00161 virtual streamsize showmanyc(); 00162 00163 // Reads up to __n characters. Return value is the number of 00164 // characters read. 00165 virtual streamsize xsgetn(char_type* __s, streamsize __n); 00166 00167 // Called when there is no read position, i.e. when gptr() is null 00168 // or when gptr() >= egptr(). Subclasses are expected to override 00169 // this virtual member function. 00170 virtual int_type underflow(); 00171 00172 // Similar to underflow(), but used for unbuffered input. Most 00173 // subclasses should probably override this virtual member function. 00174 virtual int_type uflow(); 00175 00176 // Called when there is no putback position, i.e. when gptr() is null 00177 // or when gptr() == eback(). All subclasses are expected to override 00178 // this virtual member function. 00179 virtual int_type pbackfail(int_type = traits_type::eof()); 00180 00181 protected: // Virtual put area functions, as defined in 00182 // 27.5.2.4.5 of the standard. 00183 00184 // Writes up to __n characters. Return value is the number of characters 00185 // written. 00186 virtual streamsize xsputn(const char_type* __s, streamsize __n); 00187 00188 // Extension: writes up to __n copies of __c. Return value is the number 00189 // of characters written. 00190 virtual streamsize _M_xsputnc(char_type __c, streamsize __n); 00191 00192 // Called when there is no write position. All subclasses are expected to 00193 // override this virtual member function. 00194 virtual int_type overflow(int_type = traits_type::eof()); 00195 00196 public: // Public members for writing characters. 00197 // Write a single character. 00198 int_type sputc(char_type __c) { 00199 return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c) 00200 : this->overflow(_Traits::to_int_type(__c))); 00201 } 00202 00203 // Write __n characters. 00204 streamsize sputn(const char_type* __s, streamsize __n) 00205 { return this->xsputn(__s, __n); } 00206 00207 // Extension: write __n copies of __c. 00208 streamsize _M_sputnc(char_type __c, streamsize __n) 00209 { return this->_M_xsputnc(__c, __n); } 00210 00211 private: // Helper functions. 00212 int_type _M_snextc_aux(); 00213 00214 public: // Public members for reading characters. 00215 streamsize in_avail() { 00216 return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc(); 00217 } 00218 00219 // Advance to the next character and return it. 00220 int_type snextc() { 00221 return ( _M_gend - _M_gnext > 1 ? 00222 _Traits::to_int_type(*++_M_gnext) : 00223 this->_M_snextc_aux()); 00224 } 00225 00226 // Return the current character and advance to the next. 00227 int_type sbumpc() { 00228 return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++) 00229 : this->uflow(); 00230 } 00231 00232 // Return the current character without advancing to the next. 00233 int_type sgetc() { 00234 return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext) 00235 : this->underflow(); 00236 } 00237 00238 streamsize sgetn(char_type* __s, streamsize __n) 00239 { return this->xsgetn(__s, __n); } 00240 00241 int_type sputbackc(char_type __c) { 00242 return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1))) 00243 ? _Traits::to_int_type(*--_M_gnext) 00244 : this->pbackfail(_Traits::to_int_type(__c)); 00245 } 00246 00247 int_type sungetc() { 00248 return (_M_gbegin < _M_gnext) 00249 ? _Traits::to_int_type(*--_M_gnext) 00250 : this->pbackfail(); 00251 } 00252 00253 protected: // Virtual locale functions. 00254 00255 // This is a hook, called by pubimbue() just before pubimbue() 00256 // sets the streambuf's locale to __loc. Note that imbue should 00257 // not (and cannot, since it has no access to streambuf's private 00258 // members) set the streambuf's locale itself. 00259 virtual void imbue(const locale&); 00260 00261 public: // Locale-related functions. 00262 locale pubimbue(const locale&); 00263 locale getloc() const { return _M_locale; } 00264 00265 #if !defined (_STLP_NO_ANACHRONISMS) 00266 void stossc() { this->sbumpc(); } 00267 #endif 00268 }; 00269 00270 #if defined (_STLP_USE_TEMPLATE_EXPORT) 00271 _STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<char, char_traits<char> >; 00272 # if !defined (_STLP_NO_WCHAR_T) 00273 _STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >; 00274 # endif // _STLP_NO_WCHAR_T 00275 #endif // _STLP_USE_TEMPLATE_EXPORT 00276 00277 _STLP_END_NAMESPACE 00278 00279 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) 00280 # include <stl/_streambuf.c> 00281 #endif 00282 00283 #endif 00284 00285 // Local Variables: 00286 // mode:C++ 00287 // End: Generated on Sun May 27 2012 04:29:32 for ReactOS by
1.7.6.1
|