/home/ntakagi/work/STLport-5.1.5/stlport/stl/_streambuf.c

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_STREAMBUF_C
00019 #define _STLP_STREAMBUF_C
00020 
00021 #ifndef _STLP_INTERNAL_STREAMBUF
00022 #  include <stl/_streambuf.h>
00023 #endif
00024 
00025 _STLP_BEGIN_NAMESPACE
00026 //----------------------------------------------------------------------
00027 // Non-inline basic_streambuf<> member functions.
00028 
00029 #if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300) || !defined (_STLP_USE_STATIC_LIB)
00030 template <class _CharT, class _Traits>
00031 basic_streambuf<_CharT, _Traits>::basic_streambuf()
00032   : _M_gbegin(0), _M_gnext(0), _M_gend(0),
00033     _M_pbegin(0), _M_pnext(0), _M_pend(0),
00034     _M_locale() {
00035   //  _M_lock._M_initialize();
00036 }
00037 #endif
00038 
00039 template <class _CharT, class _Traits>
00040 basic_streambuf<_CharT, _Traits>::~basic_streambuf()
00041 {}
00042 
00043 template <class _CharT, class _Traits>
00044 locale
00045 basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
00046   this->imbue(__loc);
00047   locale __tmp = _M_locale;
00048   _M_locale = __loc;
00049   return __tmp;
00050 }
00051 
00052 template <class _CharT, class _Traits>
00053 streamsize
00054 basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n) {
00055   streamsize __result = 0;
00056   const int_type __eof = _Traits::eof();
00057 
00058   while (__result < __n) {
00059     if (_M_gnext < _M_gend) {
00060       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
00061                               __STATIC_CAST(size_t,__n - __result));
00062       _Traits::copy(__s, _M_gnext, __chunk);
00063       __result += __chunk;
00064       __s += __chunk;
00065       _M_gnext += __chunk;
00066     }
00067     else {
00068       int_type __c = this->sbumpc();
00069       if (!_Traits::eq_int_type(__c, __eof)) {
00070         *__s = _Traits::to_char_type(__c);
00071         ++__result;
00072         ++__s;
00073       }
00074       else
00075         break;
00076     }
00077   }
00078 
00079   return __result;
00080 }
00081 
00082 template <class _CharT, class _Traits>
00083 streamsize
00084 basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
00085 {
00086   streamsize __result = 0;
00087   const int_type __eof = _Traits::eof();
00088 
00089   while (__result < __n) {
00090     if (_M_pnext < _M_pend) {
00091       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
00092                            __STATIC_CAST(size_t,__n - __result));
00093       _Traits::copy(_M_pnext, __s, __chunk);
00094       __result += __chunk;
00095       __s += __chunk;
00096       _M_pnext += __chunk;
00097     }
00098 
00099     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
00100                                    __eof)) {
00101       ++__result;
00102       ++__s;
00103     }
00104     else
00105       break;
00106   }
00107   return __result;
00108 }
00109 
00110 template <class _CharT, class _Traits>
00111 streamsize
00112 basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
00113 {
00114   streamsize __result = 0;
00115   const int_type __eof = _Traits::eof();
00116 
00117   while (__result < __n) {
00118     if (_M_pnext < _M_pend) {
00119       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
00120                            __STATIC_CAST(size_t,__n - __result));
00121       _Traits::assign(_M_pnext, __chunk, __c);
00122       __result += __chunk;
00123       _M_pnext += __chunk;
00124     }
00125 
00126     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
00127                                    __eof))
00128       ++__result;
00129     else
00130       break;
00131   }
00132   return __result;
00133 }
00134 
00135 template <class _CharT, class _Traits>
00136 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
00137 basic_streambuf<_CharT, _Traits>::_M_snextc_aux()
00138 {
00139   int_type __eof = _Traits::eof();
00140   if (_M_gend == _M_gnext)
00141     return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
00142   else {
00143     _M_gnext = _M_gend;
00144     return this->underflow();
00145   }
00146 }
00147 
00148 template <class _CharT, class _Traits>
00149 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
00150 basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
00151  return _Traits::eof();
00152 }
00153 
00154 template <class _CharT, class _Traits>
00155 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
00156 basic_streambuf<_CharT, _Traits>::overflow(int_type) {
00157   return _Traits::eof();
00158 }
00159 
00160 template <class _CharT, class _Traits>
00161 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
00162 basic_streambuf<_CharT, _Traits>::uflow() {
00163     return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
00164              _Traits::eof() :
00165              _Traits::to_int_type(*_M_gnext++));
00166 }
00167 
00168 template <class _CharT, class _Traits>
00169 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
00170 basic_streambuf<_CharT, _Traits>::underflow()
00171 { return _Traits::eof(); }
00172 
00173 template <class _CharT, class _Traits>
00174 streamsize
00175 basic_streambuf<_CharT, _Traits>::showmanyc()
00176 { return 0; }
00177 
00178 template <class _CharT, class _Traits>
00179 void
00180 basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
00181 
00182 template <class _CharT, class _Traits>
00183 int
00184 basic_streambuf<_CharT, _Traits>::sync() { return 0; }
00185 
00186 template <class _CharT, class _Traits>
00187 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
00188 basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
00189 { return pos_type(-1); }
00190 
00191 template <class _CharT, class _Traits>
00192 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
00193 basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
00194                                           ios_base::openmode)
00195 { return pos_type(-1); }
00196 
00197 template <class _CharT, class _Traits>
00198 basic_streambuf<_CharT, _Traits>*
00199 basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
00200 { return this; }
00201 
00202 _STLP_END_NAMESPACE
00203 
00204 #endif
00205 
00206 // Local Variables:
00207 // mode:C++
00208 // End:



Generated on Mon Mar 10 15:32:36 2008 by  doxygen 1.5.1