00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <fstream>
00036
00037 namespace std
00038 {
00039 template<>
00040 basic_filebuf<char>::int_type
00041 basic_filebuf<char>::_M_underflow_common(bool __bump)
00042 {
00043 int_type __ret = traits_type::eof();
00044 bool __testin = _M_mode & ios_base::in;
00045 bool __testout = _M_mode & ios_base::out;
00046
00047 if (__testin)
00048 {
00049
00050
00051
00052 if (_M_pback_init)
00053 {
00054 _M_pback_destroy();
00055 if (_M_in_cur < _M_in_end)
00056 return traits_type::to_int_type(*_M_in_cur);
00057 }
00058
00059
00060
00061 bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
00062 bool __testinit = _M_is_indeterminate();
00063 if (__testget)
00064 {
00065 if (__testout)
00066 _M_really_overflow();
00067 else if (_M_in_cur != _M_filepos)
00068 _M_file.seekoff(_M_in_cur - _M_filepos,
00069 ios_base::cur, ios_base::in);
00070 }
00071
00072 if (__testinit || __testget)
00073 {
00074 streamsize __elen = 0;
00075 streamsize __ilen = 0;
00076 __elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg),
00077 _M_buf_size);
00078 __ilen = __elen;
00079
00080 if (0 < __ilen)
00081 {
00082 _M_set_determinate(__ilen);
00083 if (__testout)
00084 _M_out_cur = _M_in_cur;
00085 __ret = traits_type::to_int_type(*_M_in_cur);
00086 if (__bump)
00087 _M_in_cur_move(1);
00088 else if (_M_buf_size == 1)
00089 {
00090
00091
00092
00093 _M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
00094 _M_set_indeterminate();
00095 }
00096 }
00097 }
00098 }
00099 _M_last_overflowed = false;
00100 return __ret;
00101 }
00102
00103 #ifdef _GLIBCPP_USE_WCHAR_T
00104 template<>
00105 basic_filebuf<wchar_t>::int_type
00106 basic_filebuf<wchar_t>::_M_underflow_common(bool __bump)
00107 {
00108 int_type __ret = traits_type::eof();
00109 bool __testin = _M_mode & ios_base::in;
00110 bool __testout = _M_mode & ios_base::out;
00111
00112 if (__testin)
00113 {
00114
00115
00116
00117 if (_M_pback_init)
00118 {
00119 _M_pback_destroy();
00120 if (_M_in_cur < _M_in_end)
00121 return traits_type::to_int_type(*_M_in_cur);
00122 }
00123
00124
00125
00126 bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
00127 bool __testinit = _M_is_indeterminate();
00128 if (__testget)
00129 {
00130 if (__testout)
00131 _M_really_overflow();
00132 else if (_M_in_cur != _M_filepos)
00133 _M_file.seekoff(_M_in_cur - _M_filepos,
00134 ios_base::cur, ios_base::in);
00135 }
00136
00137 if (__testinit || __testget)
00138 {
00139 const locale __loc = this->getloc();
00140 const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
00141
00142 streamsize __elen = 0;
00143 streamsize __ilen = 0;
00144 if (__cvt.always_noconv())
00145 {
00146 __elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg),
00147 _M_buf_size);
00148 __ilen = __elen;
00149 }
00150 else
00151 {
00152 char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size));
00153 __elen = _M_file.xsgetn(__buf, _M_buf_size);
00154
00155 const char* __eend;
00156 char_type* __iend;
00157 __res_type __r = __cvt.in(_M_state_cur, __buf,
00158 __buf + __elen, __eend, _M_in_beg,
00159 _M_in_beg + _M_buf_size, __iend);
00160 if (__r == codecvt_base::ok)
00161 __ilen = __iend - _M_in_beg;
00162 else
00163 {
00164
00165 __ilen = 0;
00166 _M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
00167 }
00168 }
00169
00170 if (0 < __ilen)
00171 {
00172 _M_set_determinate(__ilen);
00173 if (__testout)
00174 _M_out_cur = _M_in_cur;
00175 __ret = traits_type::to_int_type(*_M_in_cur);
00176 if (__bump)
00177 _M_in_cur_move(1);
00178 else if (_M_buf_size == 1)
00179 {
00180
00181
00182
00183 _M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
00184 _M_set_indeterminate();
00185 }
00186 }
00187 }
00188 }
00189 _M_last_overflowed = false;
00190 return __ret;
00191 }
00192 #endif
00193 }