|
|
|
| 1 |
|
// fstream standard header |
| 2 |
|
#pragma once |
| 3 |
|
#ifndef _FSTREAM_ |
| 4 |
|
#define _FSTREAM_ |
| 5 |
|
#ifndef RC_INVOKED |
| 6 |
|
#include <istream> |
| 7 |
|
|
| 8 |
|
#ifdef _MSC_VER |
| 9 |
|
#pragma pack(push,_CRT_PACKING) |
| 10 |
|
#pragma warning(push,3) |
| 11 |
|
#pragma warning(disable: 4127) |
| 12 |
|
#endif /* _MSC_VER */ |
| 13 |
|
|
| 14 |
|
_STD_BEGIN |
| 15 |
|
|
| 16 |
|
extern _MRTIMP2_NCEEPURE _Filet *__CLRCALL_PURE_OR_CDECL _Fiopen(const char *, |
| 17 |
|
ios_base::openmode, int); |
| 18 |
|
extern _MRTIMP2_NCEEPURE _Filet *__CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t *, |
| 19 |
|
ios_base::openmode, int); |
| 20 |
|
|
| 21 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 22 |
|
extern _MRTIMP2_NCEEPURE _Filet *__CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short *, |
| 23 |
|
ios_base::openmode, int); |
| 24 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 25 |
|
|
| 26 |
|
// TEMPLATE FUNCTION _Fgetc |
| 27 |
|
template<class _Elem> inline |
| 28 |
|
bool _Fgetc(_Elem& _Ch, _Filet *_File) |
| 29 |
|
{ // get an element from a C stream |
| 30 |
|
return (fread(&_Ch, sizeof (_Elem), 1, _File) == 1); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
template<> inline bool _Fgetc(char& _Byte, _Filet *_File) |
| 34 |
|
{ // get a char element from a C stream |
| 35 |
|
int _Meta; |
| 36 |
|
if ((_Meta = fgetc(_File)) == EOF) |
| 37 |
|
return (false); |
| 38 |
|
else |
| 39 |
|
{ // got one, convert to char |
| 40 |
|
_Byte = (char)_Meta; |
| 41 |
|
return (true); |
| 42 |
|
} |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
template<> inline bool _Fgetc(wchar_t& _Wchar, _Filet *_File) |
| 46 |
|
{ // get a wchar_t element from a C stream |
| 47 |
|
wint_t _Meta; |
| 48 |
|
if ((_Meta = ::fgetwc(_File)) == WEOF) |
| 49 |
|
return (false); |
| 50 |
|
else |
| 51 |
|
{ // got one, convert to wchar_t |
| 52 |
|
_Wchar = (wchar_t)_Meta; |
| 53 |
|
return (true); |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
// TEMPLATE FUNCTION _Fputc |
| 59 |
|
template<class _Elem> inline |
| 60 |
|
bool _Fputc(_Elem _Ch, _Filet *_File) |
| 61 |
|
{ // put an element to a C stream |
| 62 |
|
return (fwrite(&_Ch, 1, sizeof (_Elem), _File) == sizeof (_Elem)); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
template<> inline bool _Fputc(char _Byte, _Filet *_File) |
| 66 |
|
{ // put a char element to a C stream |
| 67 |
|
return (fputc(_Byte, _File) != EOF); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
template<> inline bool _Fputc(wchar_t _Wchar, _Filet *_File) |
| 71 |
|
{ // put a wchar_t element to a C stream |
| 72 |
|
return (::fputwc(_Wchar, _File) != WEOF); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
// TEMPLATE FUNCTION _Ungetc |
| 77 |
|
template<class _Elem> inline |
| 78 |
|
bool _Ungetc(const _Elem& _Ch, _Filet *_File) |
| 79 |
|
{ // put back an arbitrary element to a C stream (always fail) |
| 80 |
|
return (false); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
template<> inline bool _Ungetc(const char& _Byte, _Filet *_File) |
| 84 |
|
{ // put back a char element to a C stream |
| 85 |
|
return (ungetc((unsigned char)_Byte, _File) != EOF); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
template<> inline bool _Ungetc(const signed char& _Byte, _Filet *_File) |
| 89 |
|
{ // put back a signed char element to a C stream |
| 90 |
|
return (ungetc((unsigned char)_Byte, _File) != EOF); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
template<> inline bool _Ungetc(const unsigned char& _Byte, _Filet *_File) |
| 94 |
|
{ // put back an unsigned char element to a C stream |
| 95 |
|
return (ungetc(_Byte, _File) != EOF); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
template<> inline bool _Ungetc(const wchar_t& _Wchar, _Filet *_File) |
| 99 |
|
{ // put back a wchar_t element to a C stream |
| 100 |
|
return (::ungetwc(_Wchar, _File) != WEOF); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
// TEMPLATE CLASS basic_filebuf |
| 105 |
|
template<class _Elem, |
| 106 |
|
class _Traits> |
| 107 |
|
class basic_filebuf |
| 108 |
|
: public basic_streambuf<_Elem, _Traits> |
| 109 |
|
{ // stream buffer associated with a C stream |
| 110 |
|
public: |
| 111 |
|
typedef basic_filebuf<_Elem, _Traits> _Myt; |
| 112 |
|
typedef basic_streambuf<_Elem, _Traits> _Mysb; |
| 113 |
|
typedef typename _Traits::state_type _Myst; |
| 114 |
|
typedef codecvt<_Elem, char, typename _Traits::state_type> _Cvt; |
| 115 |
|
|
| 116 |
|
virtual __CLR_OR_THIS_CALL ~basic_filebuf() |
| 117 |
|
{ // destroy the object |
| 118 |
|
if (_Closef) |
| 119 |
|
close(); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
__CLR_OR_THIS_CALL basic_filebuf(_Filet *_File = 0) |
| 123 |
|
: _Mysb() |
| 124 |
|
{ // construct from pointer to C stream |
| 125 |
|
_Init(_File, _Newfl); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
typedef _Elem char_type; |
| 129 |
|
typedef _Traits traits_type; |
| 130 |
|
typedef typename _Traits::int_type int_type; |
| 131 |
|
typedef typename _Traits::pos_type pos_type; |
| 132 |
|
typedef typename _Traits::off_type off_type; |
| 133 |
|
|
| 134 |
|
__CLR_OR_THIS_CALL basic_filebuf(_Uninitialized) |
| 135 |
|
: _Mysb(_Noinit) |
| 136 |
|
{ // construct uninitialized |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
enum _Initfl |
| 140 |
|
{ // reasons for a call to _Init |
| 141 |
|
_Newfl, _Openfl, _Closefl}; |
| 142 |
|
|
| 143 |
|
bool __CLR_OR_THIS_CALL is_open() const |
| 144 |
|
{ // test if C stream has been opened |
| 145 |
|
return (_Myfile != 0); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
_Myt *__CLR_OR_THIS_CALL open(const char *_Filename, |
| 149 |
|
ios_base::openmode _Mode, |
| 150 |
|
int _Prot = (int)ios_base::_Openprot) |
| 151 |
|
{ // open a C stream with specified mode |
| 152 |
|
_Filet *_File; |
| 153 |
|
if (_Myfile != 0 || (_File = _Fiopen(_Filename, _Mode, _Prot)) == 0) |
| 154 |
|
return (0); // open failed |
| 155 |
|
|
| 156 |
|
_Init(_File, _Openfl); |
| 157 |
|
_Initcvt((_Cvt *)&_USE(_Mysb::getloc(), _Cvt)); |
| 158 |
|
return (this); // open succeeded |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
_Myt *__CLR_OR_THIS_CALL open(const char *_Filename, ios_base::open_mode _Mode) |
| 162 |
|
{ // open a C stream with specified mode (old style) |
| 163 |
|
return (open(_Filename, (ios_base::openmode)_Mode)); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
_Myt *__CLR_OR_THIS_CALL open(const wchar_t *_Filename, |
| 167 |
|
ios_base::openmode _Mode, |
| 168 |
|
int _Prot = (int)ios_base::_Openprot) |
| 169 |
|
{ // open a wide-named C stream -- EXTENSION |
| 170 |
|
_Filet *_File; |
| 171 |
|
if (_Myfile != 0 || (_File = _Fiopen(_Filename, _Mode, _Prot)) == 0) |
| 172 |
|
return (0); // open failed |
| 173 |
|
|
| 174 |
|
_Init(_File, _Openfl); |
| 175 |
|
_Initcvt((_Cvt *)&_USE(_Mysb::getloc(), _Cvt)); |
| 176 |
|
return (this); // open succeeded |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
_Myt *__CLR_OR_THIS_CALL open(const wchar_t *_Filename, ios_base::open_mode _Mode) |
| 180 |
|
{ // open a wide-named C stream (old style) -- EXTENSION |
| 181 |
|
return (open(_Filename, (ios_base::openmode)_Mode)); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 185 |
|
_Myt * __CLR_OR_THIS_CALL open(const unsigned short *_Filename, |
| 186 |
|
ios_base::openmode _Mode, |
| 187 |
|
int _Prot = (int)ios_base::_Openprot) |
| 188 |
|
{ // open a wide-named C stream -- EXTENSION |
| 189 |
|
_Filet *_File; |
| 190 |
|
if (_Myfile != 0 || (_File = _Fiopen(_Filename, _Mode, _Prot)) == 0) |
| 191 |
|
return (0); // open failed |
| 192 |
|
|
| 193 |
|
_Init(_File, _Openfl); |
| 194 |
|
_Initcvt((_Cvt *)&_USE(_Mysb::getloc(), _Cvt)); |
| 195 |
|
return (this); // open succeeded |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
_Myt * __CLR_OR_THIS_CALL open(const unsigned short *_Filename, ios_base::open_mode _Mode) |
| 199 |
|
{ // open a wide-named C stream (old style) -- EXTENSION |
| 200 |
|
return (open(_Filename, (ios_base::openmode)_Mode)); |
| 201 |
|
} |
| 202 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 203 |
|
|
| 204 |
|
_Myt *__CLR_OR_THIS_CALL close() |
| 205 |
|
{ // close the C stream |
| 206 |
|
_Myt *_Ans = this; |
| 207 |
|
if (_Myfile == 0) |
| 208 |
|
_Ans = 0; |
| 209 |
|
else |
| 210 |
|
{ // put any homing sequence and close file |
| 211 |
|
if (!_Endwrite()) |
| 212 |
|
_Ans = 0; |
| 213 |
|
if (fclose(_Myfile) != 0) |
| 214 |
|
_Ans = 0; |
| 215 |
|
} |
| 216 |
|
_Init(0, _Closefl); |
| 217 |
|
return (_Ans); |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
protected: |
| 221 |
|
virtual int_type __CLR_OR_THIS_CALL overflow(int_type _Meta = _Traits::eof()) |
| 222 |
|
{ // put an element to stream |
| 223 |
|
if (_Traits::eq_int_type(_Traits::eof(), _Meta)) |
| 224 |
|
return (_Traits::not_eof(_Meta)); // EOF, return success code |
| 225 |
|
else if (_Mysb::pptr() != 0 |
| 226 |
|
&& _Mysb::pptr() < _Mysb::epptr()) |
| 227 |
|
{ // room in buffer, store it |
| 228 |
|
*_Mysb::_Pninc() = _Traits::to_char_type(_Meta); |
| 229 |
|
return (_Meta); |
| 230 |
|
} |
| 231 |
|
else if (_Myfile == 0) |
| 232 |
|
return (_Traits::eof()); // no open C stream, fail |
| 233 |
|
else if (_Pcvt == 0) |
| 234 |
|
return (_Fputc(_Traits::to_char_type(_Meta), _Myfile) |
| 235 |
|
? _Meta : _Traits::eof()); // no codecvt facet, put as is |
| 236 |
|
else |
| 237 |
|
{ // put using codecvt facet |
| 238 |
|
const int _STRING_INC = 8; |
| 239 |
|
const _Elem _Ch = _Traits::to_char_type(_Meta); |
| 240 |
|
const _Elem *_Src; |
| 241 |
|
char *_Dest; |
| 242 |
|
|
| 243 |
|
string _Str(_STRING_INC, '\0'); |
| 244 |
|
for (; ; ) |
| 245 |
|
switch (_Pcvt->out(_State, |
| 246 |
|
&_Ch, &_Ch + 1, _Src, |
| 247 |
|
&*_Str.begin(), &*_Str.begin() + _Str.size(), _Dest)) |
| 248 |
|
{ // test result of converting one element |
| 249 |
|
case codecvt_base::partial: |
| 250 |
|
case codecvt_base::ok: |
| 251 |
|
{ // converted something, try to put it out |
| 252 |
|
size_t _Count = _Dest - &*_Str.begin(); |
| 253 |
|
if (0 < _Count && _Count != |
| 254 |
|
fwrite(&*_Str.begin(), 1, _Count, _Myfile)) |
| 255 |
|
return (_Traits::eof()); // write failed |
| 256 |
|
|
| 257 |
|
_Wrotesome = true; // write succeeded |
| 258 |
|
if (_Src != &_Ch) |
| 259 |
|
return (_Meta); // converted whole element |
| 260 |
|
|
| 261 |
|
if (0 < _Count) |
| 262 |
|
; |
| 263 |
|
else if (_Str.size() < 4 * _STRING_INC) |
| 264 |
|
_Str.append(_STRING_INC, '\0'); // try with more space |
| 265 |
|
else |
| 266 |
|
return (_Traits::eof()); // conversion failed |
| 267 |
|
break; |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
case codecvt_base::noconv: |
| 271 |
|
return (_Fputc(_Ch, _Myfile) ? _Meta |
| 272 |
|
: _Traits::eof()); // no conversion, put as is |
| 273 |
|
|
| 274 |
|
default: |
| 275 |
|
return (_Traits::eof()); // conversion failed |
| 276 |
|
} |
| 277 |
|
} |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
virtual int_type __CLR_OR_THIS_CALL pbackfail(int_type _Meta = _Traits::eof()) |
| 281 |
|
{ // put an element back to stream |
| 282 |
|
if (_Mysb::gptr() != 0 |
| 283 |
|
&& _Mysb::eback() < _Mysb::gptr() |
| 284 |
|
&& (_Traits::eq_int_type(_Traits::eof(), _Meta) |
| 285 |
|
|| _Traits::eq_int_type(_Traits::to_int_type(_Mysb::gptr()[-1]), |
| 286 |
|
_Meta))) |
| 287 |
|
{ // just back up position |
| 288 |
|
_Mysb::_Gndec(); |
| 289 |
|
return (_Traits::not_eof(_Meta)); |
| 290 |
|
} |
| 291 |
|
else if (_Myfile == 0 || _Traits::eq_int_type(_Traits::eof(), _Meta)) |
| 292 |
|
return (_Traits::eof()); // no open C stream or EOF, fail |
| 293 |
|
else if (_Pcvt == 0 && _Ungetc(_Traits::to_char_type(_Meta), _Myfile)) |
| 294 |
|
return (_Meta); // no facet and unget succeeded, return |
| 295 |
|
#pragma warning(push) |
| 296 |
|
#pragma warning(disable: 6237 6239) |
| 297 |
|
/* prefast noise VSW 489858 */ |
| 298 |
|
else if (1 < sizeof (_Elem) && _Mysb::gptr() != &_Mychar) |
| 299 |
|
#pragma warning(pop) |
| 300 |
|
{ // putback to _Mychar |
| 301 |
|
_Mychar = _Traits::to_char_type(_Meta); |
| 302 |
|
_Mysb::setg(&_Mychar, &_Mychar, &_Mychar + 1); |
| 303 |
|
return (_Meta); |
| 304 |
|
} |
| 305 |
|
else |
| 306 |
|
return (_Traits::eof()); // nowhere to put back |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
virtual int_type __CLR_OR_THIS_CALL underflow() |
| 310 |
|
{ // get an element from stream, but don't point past it |
| 311 |
|
int_type _Meta; |
| 312 |
|
if (_Mysb::gptr() != 0 |
| 313 |
|
&& _Mysb::gptr() < _Mysb::egptr()) |
| 314 |
|
return (_Traits::to_int_type(*_Mysb::gptr())); // return buffered |
| 315 |
|
else if (_Traits::eq_int_type(_Traits::eof(), _Meta = uflow())) |
| 316 |
|
return (_Meta); // uflow failed, return EOF |
| 317 |
|
else |
| 318 |
|
{ // get a char, don't point past it |
| 319 |
|
pbackfail(_Meta); |
| 330 |
|
else if (_Myfile == 0) |
| 331 |
|
return (_Traits::eof()); // no open C stream, fail |
| 332 |
|
else if (_Pcvt == 0) |
| 333 |
|
{ // no codecvt facet, just get it |
| 334 |
|
_Elem _Ch; |
| 335 |
|
return (_Fgetc(_Ch, _Myfile) ? _Traits::to_int_type(_Ch) |
| 336 |
|
: _Traits::eof()); |
| 337 |
|
} |
| 338 |
|
else |
| 339 |
|
{ // build string until codecvt succeeds |
| 340 |
|
string _Str; |
| 341 |
|
|
| 342 |
|
for (; ; ) |
| 343 |
|
{ // get using codecvt facet |
| 344 |
|
_Elem _Ch, *_Dest; |
| 345 |
|
const char *_Src; |
| 346 |
|
ptrdiff_t _Nleft; |
| 347 |
|
int _Meta = fgetc(_Myfile); |
| 348 |
|
|
| 349 |
|
if (_Meta == EOF) |
| 350 |
|
return (_Traits::eof()); // partial char? |
| 351 |
|
|
| 352 |
|
_Str.append(1, (char)_Meta); // append byte and convert |
| 353 |
|
switch (_Pcvt->in(_State, |
| 354 |
|
&*_Str.begin(), &*_Str.begin() + _Str.size(), _Src, |
| 355 |
|
&_Ch, &_Ch + 1, _Dest)) |
| 356 |
|
{ // test result of converting one element |
| 357 |
|
case codecvt_base::partial: |
| 358 |
|
case codecvt_base::ok: |
| 359 |
|
if (_Dest != &_Ch) |
| 360 |
|
{ // got an element, put back excess and deliver it |
| 361 |
|
_Nleft = (int)(&*_Str.begin() + _Str.size() - _Src); |
| 362 |
|
for (; 0 < _Nleft; ) |
| 363 |
|
ungetc(_Src[--_Nleft], _Myfile); |
| 364 |
|
return (_Traits::to_int_type(_Ch)); |
| 365 |
|
} |
| 366 |
|
else |
| 367 |
|
_Str.erase((size_t)0, // partial, discard used input |
| 368 |
|
(size_t)(_Src - &*_Str.begin())); |
| 369 |
|
break; |
| 370 |
|
|
| 371 |
|
case codecvt_base::noconv: |
| 372 |
|
if (_Str.size() < sizeof (_Elem)) |
| 373 |
|
break; // no conversion, but need more chars |
| 374 |
|
|
| 375 |
|
_CRT_SECURE_MEMCPY(&_Ch,sizeof (_Elem), &*_Str.begin(), |
| 376 |
|
sizeof (_Elem)); // copy raw bytes to element |
| 377 |
|
return (_Traits::to_int_type(_Ch)); // return result |
| 378 |
|
|
| 379 |
|
default: |
| 380 |
|
return (_Traits::eof()); // conversion failed |
| 381 |
|
} |
| 382 |
|
} |
| 383 |
|
} |
| 384 |
|
} |
| 385 |
|
|
| 386 |
|
virtual pos_type __CLR_OR_THIS_CALL seekoff(off_type _Off, |
| 387 |
|
ios_base::seekdir _Way, |
| 388 |
|
ios_base::openmode = |
| 389 |
|
(ios_base::openmode)(ios_base::in | ios_base::out)) |
| 390 |
|
{ // change position by _Off |
| 391 |
|
fpos_t _Fileposition; |
| 392 |
|
|
| 393 |
|
if (_Mysb::gptr() == &_Mychar // something putback |
| 394 |
|
&& _Way == ios_base::cur // a relative seek |
| 395 |
|
&& _Pcvt == 0) // not converting |
| 396 |
|
_Off -= (off_type)sizeof (_Elem); // back up over _Elem bytes |
| 397 |
|
|
| 398 |
|
if (_Myfile == 0 || !_Endwrite() |
| 399 |
|
|| (_Off != 0 || _Way != ios_base::cur) |
| 400 |
|
&& fseek(_Myfile, (long)_Off, _Way) != 0 |
| 401 |
|
|| fgetpos(_Myfile, &_Fileposition) != 0) |
| 402 |
|
return (pos_type(_BADOFF)); // report failure |
| 403 |
|
|
| 404 |
|
if (_Mysb::gptr() == &_Mychar) |
| 405 |
|
_Mysb::setg(&_Mychar, &_Mychar + 1, |
| 406 |
|
&_Mychar + 1); // discard any putback |
| 407 |
|
return (_POS_TYPE_FROM_STATE(pos_type, _State, |
| 408 |
|
_Fileposition)); // return new position |
| 409 |
|
} |
| 410 |
|
|
| 411 |
|
virtual pos_type __CLR_OR_THIS_CALL seekpos(pos_type _Pos, |
| 412 |
|
ios_base::openmode = |
| 413 |
|
(ios_base::openmode)(ios_base::in | ios_base::out)) |
| 414 |
|
{ // change position to _Pos |
| 415 |
|
fpos_t _Fileposition = _POS_TYPE_TO_FPOS_T(_Pos); |
| 416 |
|
off_type _Off = (off_type)_Pos - (off_type)_FPOSOFF(_Fileposition); |
| 417 |
|
|
| 418 |
|
if (_Myfile == 0 || !_Endwrite() |
| 419 |
|
|| fsetpos(_Myfile, &_Fileposition) != 0 |
| 420 |
|
|| _Off != 0 && fseek(_Myfile, (long)_Off, SEEK_CUR) != 0 |
| 421 |
|
|| fgetpos(_Myfile, &_Fileposition) != 0) |
| 422 |
|
return (pos_type(_BADOFF)); // report failure |
| 423 |
|
|
| 424 |
|
_State = _POS_TYPE_TO_STATE(_Pos); |
| 425 |
|
|
| 426 |
|
if (_Mysb::gptr() == &_Mychar) |
| 427 |
|
_Mysb::setg(&_Mychar, &_Mychar + 1, |
| 428 |
|
&_Mychar + 1); // discard any putback |
| 429 |
|
return (_POS_TYPE_FROM_STATE(pos_type, _State, |
| 430 |
|
_Fileposition)); // return new position |
| 431 |
|
} |
| 432 |
|
|
| 433 |
|
virtual _Mysb *__CLR_OR_THIS_CALL setbuf(_Elem *_Buffer, streamsize _Count) |
| 434 |
|
{ // offer _Buffer to C stream |
| 435 |
|
if (_Myfile == 0 || setvbuf(_Myfile, (char *)_Buffer, |
| 436 |
|
_Buffer == 0 && _Count == 0 ? _IONBF : _IOFBF, |
| 437 |
|
_Count * sizeof (_Elem)) != 0) |
| 438 |
|
return (0); // failed |
| 439 |
|
else |
| 440 |
|
{ // new buffer, reinitialize pointers |
| 441 |
|
_Init(_Myfile, _Openfl); |
| 442 |
|
return (this); |
| 443 |
|
} |
| 444 |
|
} |
| 445 |
|
|
| 446 |
|
virtual int __CLR_OR_THIS_CALL sync() |
| 447 |
|
{ // synchronize C stream with external file |
| 448 |
|
return (_Myfile == 0 |
| 449 |
|
|| _Traits::eq_int_type(_Traits::eof(), overflow()) |
| 450 |
|
|| 0 <= fflush(_Myfile) ? 0 : -1); |
| 451 |
|
} |
| 452 |
|
|
| 453 |
|
virtual void __CLR_OR_THIS_CALL imbue(const locale& _Loc) |
| 454 |
|
{ // set locale to argument (capture nontrivial codecvt facet) |
| 455 |
|
_Initcvt((_Cvt *)&_USE(_Loc, _Cvt)); |
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
void __CLR_OR_THIS_CALL _Init(_Filet *_File, _Initfl _Which) |
| 459 |
|
{ // initialize to C stream _File after {new, open, close} |
| 460 |
|
__PURE_APPDOMAIN_GLOBAL static _Myst _Stinit; // initial state |
| 461 |
|
_Closef = _Which == _Openfl; |
| 462 |
|
_Wrotesome = false; |
| 463 |
|
|
| 464 |
|
_Mysb::_Init(); // initialize stream buffer base object |
| 465 |
|
|
| 466 |
|
#ifndef _IORCNT |
| 467 |
|
#define _IORCNT _IOCNT /* read and write counts are the same */ |
| 468 |
|
#define _IOWCNT _IOCNT |
| 469 |
|
#endif /* _IORCNT */ |
| 470 |
|
|
| 471 |
|
#pragma warning(push) |
| 472 |
|
#pragma warning(disable: 6240) |
| 473 |
|
/* prefast noise VSW 489858 */ |
| 474 |
|
if (_File != 0 && sizeof (_Elem) == 1) |
| 475 |
|
#pragma warning(pop) |
| 476 |
|
{ // point inside C stream with [first, first + count) buffer |
| 477 |
|
_Elem **_Pb = (_Elem **)&_File->_IOBASE; |
| 478 |
|
_Elem **_Pn = (_Elem **)&_File->_IOPTR; |
| 479 |
|
int *_Nr = (int *)&_File->_IORCNT; |
| 480 |
|
int *_Nw = (int *)&_File->_IOWCNT; |
| 481 |
|
_Mysb::_Init(_Pb, _Pn, _Nr, _Pb, _Pn, _Nw); |
| 482 |
|
} |
| 483 |
|
|
| 484 |
|
_Myfile = _File; |
| 485 |
|
_State = _Stinit; |
| 486 |
|
_Pcvt = 0; // pointer to codecvt facet |
| 487 |
|
} |
| 488 |
|
|
| 489 |
|
bool __CLR_OR_THIS_CALL _Endwrite() |
| 490 |
|
{ // put shift to initial conversion state, as needed |
| 491 |
|
if (_Pcvt == 0 || !_Wrotesome) |
| 492 |
|
return (true); |
| 493 |
|
else |
| 494 |
|
{ // may have to put |
| 495 |
|
const int _STRING_INC = 8; |
| 496 |
|
char *_Dest; |
| 497 |
|
if (_Traits::eq_int_type(_Traits::eof(), overflow())) |
| 498 |
|
return (false); |
| 499 |
|
|
| 500 |
|
string _Str(_STRING_INC, '\0'); |
| 501 |
|
for (; ; ) |
| 502 |
|
switch (_Pcvt->unshift(_State, |
| 503 |
|
&*_Str.begin(), &*_Str.begin() + _Str.size(), _Dest)) |
| 504 |
|
{ // test result of homing conversion |
| 505 |
|
case codecvt_base::ok: |
| 506 |
|
_Wrotesome = false; // homed successfully |
| 507 |
|
|
| 508 |
|
case codecvt_base::partial: // fall through |
| 509 |
|
{ // put any generated bytes |
| 510 |
|
size_t _Count = _Dest - &*_Str.begin(); |
| 511 |
|
if (0 < _Count && _Count != |
| 512 |
|
fwrite(&*_Str.begin(), 1, _Count, _Myfile)) |
| 513 |
|
return (false); // write failed |
| 514 |
|
if (!_Wrotesome) |
| 515 |
|
return (true); |
| 516 |
|
if (_Count == 0) |
| 517 |
|
_Str.append(_STRING_INC, '\0'); // try with more space |
| 518 |
|
break; |
| 519 |
|
} |
| 520 |
|
|
| 521 |
|
case codecvt_base::noconv: |
| 522 |
|
return (true); // nothing to do |
| 523 |
|
|
| 524 |
|
default: |
| 525 |
|
return (false); // conversion failed |
| 526 |
|
} |
| 527 |
|
} |
| 528 |
|
} |
| 529 |
|
|
| 530 |
|
void __CLR_OR_THIS_CALL _Initcvt(_Cvt *_Newpcvt) |
| 531 |
|
{ // initialize codecvt pointer |
| 532 |
|
if (_Newpcvt->always_noconv()) |
| 533 |
|
_Pcvt = 0; // nothing to do |
| 534 |
|
else |
| 535 |
|
{ // set up for nontrivial codecvt facet |
| 536 |
|
_Pcvt = _Newpcvt; |
| 537 |
|
_Mysb::_Init(); // reset any buffering |
| 538 |
|
} |
| 539 |
|
} |
| 540 |
|
|
| 541 |
|
private: |
| 542 |
|
_Cvt *_Pcvt; // pointer to codecvt facet (may be null) |
| 543 |
|
_Elem _Mychar; // putback character, when _Ungetc fails |
| 544 |
|
bool _Wrotesome; // true if homing sequence may be needed |
| 545 |
|
typename _Traits::state_type _State; // current conversion state |
| 546 |
|
bool _Closef; // true if C stream must be closed |
| 547 |
|
_Filet *_Myfile; // pointer to C stream |
| 548 |
|
}; |
| 549 |
|
|
| 550 |
|
|
| 551 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
| 552 |
|
|
| 553 |
|
template class _CRTIMP2_PURE basic_filebuf<char, |
| 554 |
|
char_traits<char> >; |
| 555 |
|
template class _CRTIMP2_PURE basic_filebuf<wchar_t, |
| 556 |
|
char_traits<wchar_t> >; |
| 557 |
|
|
| 558 |
|
|
| 559 |
|
|
| 560 |
|
#endif /* _DLL_CPPLIB */ |
| 561 |
|
|
| 562 |
|
// TEMPLATE CLASS basic_ifstream |
| 563 |
|
template<class _Elem, |
| 564 |
|
class _Traits> |
| 565 |
|
class basic_ifstream |
| 566 |
|
: public basic_istream<_Elem, _Traits> |
| 567 |
|
{ // input stream associated with a C stream |
| 568 |
|
public: |
| 569 |
|
typedef basic_ifstream<_Elem, _Traits> _Myt; |
| 570 |
|
typedef basic_filebuf<_Elem, _Traits> _Myfb; |
| 571 |
|
typedef basic_ios<_Elem, _Traits> _Myios; |
| 572 |
|
|
| 573 |
|
__CLR_OR_THIS_CALL basic_ifstream() |
| 574 |
|
: basic_istream<_Elem, _Traits>(&_Filebuffer) |
| 575 |
|
{ // construct unopened |
| 576 |
|
} |
| 577 |
|
|
| 578 |
|
explicit __CLR_OR_THIS_CALL basic_ifstream(const char *_Filename, |
| 579 |
|
ios_base::openmode _Mode = ios_base::in, |
| 580 |
|
int _Prot = (int)ios_base::_Openprot) |
| 581 |
|
: basic_istream<_Elem, _Traits>(&_Filebuffer) |
| 582 |
|
{ // construct with named file and specified mode |
| 583 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 584 |
|
_Myios::setstate(ios_base::failbit); |
| 585 |
|
} |
| 586 |
|
|
| 587 |
|
explicit __CLR_OR_THIS_CALL basic_ifstream(const wchar_t *_Filename, |
| 588 |
|
ios_base::openmode _Mode = ios_base::in, |
| 589 |
|
int _Prot = (int)ios_base::_Openprot) |
| 590 |
|
: basic_istream<_Elem, _Traits>(&_Filebuffer) |
| 591 |
|
{ // construct with wide-named file -- EXTENSION |
| 592 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 593 |
|
_Myios::setstate(ios_base::failbit); |
| 594 |
|
} |
| 595 |
|
|
| 596 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 597 |
|
explicit __CLR_OR_THIS_CALL basic_ifstream(const unsigned short *_Filename, |
| 598 |
|
ios_base::openmode _Mode = ios_base::in, |
| 599 |
|
int _Prot = (int)ios_base::_Openprot) |
| 600 |
|
: basic_istream<_Elem, _Traits>(&_Filebuffer) |
| 601 |
|
{ // construct with wide-named file -- EXTENSION |
| 602 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 603 |
|
_Myios::setstate(ios_base::failbit); |
| 604 |
|
} |
| 605 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 606 |
|
|
| 607 |
|
explicit __CLR_OR_THIS_CALL basic_ifstream(_Filet *_File) |
| 608 |
|
: basic_istream<_Elem, _Traits>(&_Filebuffer), |
| 609 |
|
_Filebuffer(_File) |
| 610 |
|
{ // construct with specified C stream |
| 611 |
|
} |
| 612 |
|
|
| 613 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, |
| 614 |
|
ios_base::openmode _Mode = ios_base::in, |
| 615 |
|
int _Prot = (int)ios_base::_Openprot) |
| 616 |
|
{ // open a wide-named C stream -- EXTENSION |
| 617 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 618 |
|
_Myios::setstate(ios_base::failbit); |
| 619 |
|
} |
| 620 |
|
|
| 621 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, ios_base::open_mode _Mode) |
| 622 |
|
{ // open wide-named file (old style) -- EXTENSION |
| 623 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 624 |
|
} |
| 625 |
|
|
| 626 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 627 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, |
| 628 |
|
ios_base::openmode _Mode = ios_base::in, |
| 629 |
|
int _Prot = (int)ios_base::_Openprot) |
| 630 |
|
{ // open a wide-named C stream -- EXTENSION |
| 631 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 632 |
|
_Myios::setstate(ios_base::failbit); |
| 633 |
|
} |
| 634 |
|
|
| 635 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, ios_base::open_mode _Mode) |
| 636 |
|
{ // open wide-named file (old style) -- EXTENSION |
| 637 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 638 |
|
} |
| 639 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 640 |
|
|
| 641 |
|
virtual __CLR_OR_THIS_CALL ~basic_ifstream() |
| 642 |
|
{ // destroy the object |
| 643 |
|
} |
| 644 |
|
|
| 645 |
|
_Myfb *__CLR_OR_THIS_CALL rdbuf() const |
| 646 |
|
{ // return pointer to file buffer |
| 647 |
|
return ((_Myfb *)&_Filebuffer); |
| 648 |
|
} |
| 649 |
|
|
| 650 |
|
bool __CLR_OR_THIS_CALL is_open() const |
| 651 |
|
{ // test if C stream has been opened |
| 652 |
|
return (_Filebuffer.is_open()); |
| 653 |
|
} |
| 654 |
|
|
| 655 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, |
| 656 |
|
ios_base::openmode _Mode = ios_base::in, |
| 657 |
|
int _Prot = (int)ios_base::_Openprot) |
| 658 |
|
{ // open a C stream with specified mode |
| 659 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) |
| 660 |
|
_Myios::setstate(ios_base::failbit); |
| 661 |
|
} |
| 662 |
|
|
| 663 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, ios_base::open_mode _Mode) |
| 664 |
|
{ // open named file with specified mode (old style) |
| 665 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 666 |
|
} |
| 667 |
|
|
| 668 |
|
void __CLR_OR_THIS_CALL close() |
| 669 |
|
{ // close the C stream |
| 670 |
|
if (_Filebuffer.close() == 0) |
| 671 |
|
_Myios::setstate(ios_base::failbit); |
| 672 |
|
} |
| 673 |
|
|
| 674 |
|
private: |
| 675 |
|
_Myfb _Filebuffer; // the file buffer |
| 676 |
|
}; |
| 677 |
|
|
| 678 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
| 679 |
|
|
| 680 |
|
template class _CRTIMP2_PURE basic_ifstream<char, |
| 681 |
|
char_traits<char> >; |
| 682 |
|
template class _CRTIMP2_PURE basic_ifstream<wchar_t, |
| 683 |
|
char_traits<wchar_t> >; |
| 684 |
|
|
| 685 |
|
|
| 686 |
|
|
| 687 |
|
#endif /* _DLL_CPPLIB */ |
| 688 |
|
|
| 689 |
|
// TEMPLATE CLASS basic_ofstream |
| 690 |
|
template<class _Elem, |
| 691 |
|
class _Traits> |
| 692 |
|
class basic_ofstream |
| 693 |
|
: public basic_ostream<_Elem, _Traits> |
| 694 |
|
{ // output stream associated with a C stream |
| 695 |
|
public: |
| 696 |
|
typedef basic_ofstream<_Elem, _Traits> _Myt; |
| 697 |
|
typedef basic_filebuf<_Elem, _Traits> _Myfb; |
| 698 |
|
typedef basic_ios<_Elem, _Traits> _Myios; |
| 699 |
|
|
| 700 |
|
__CLR_OR_THIS_CALL basic_ofstream() |
| 701 |
|
: basic_ostream<_Elem, _Traits>(&_Filebuffer) |
| 702 |
|
{ // construct unopened |
| 703 |
|
} |
| 704 |
|
|
| 705 |
|
explicit __CLR_OR_THIS_CALL basic_ofstream(const char *_Filename, |
| 706 |
|
ios_base::openmode _Mode = ios_base::out, |
| 707 |
|
int _Prot = (int)ios_base::_Openprot) |
| 708 |
|
: basic_ostream<_Elem, _Traits>(&_Filebuffer) |
| 709 |
|
{ // construct with named file and specified mode |
| 710 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 711 |
|
_Myios::setstate(ios_base::failbit); |
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
explicit __CLR_OR_THIS_CALL basic_ofstream(const wchar_t *_Filename, |
| 715 |
|
ios_base::openmode _Mode = ios_base::out, |
| 716 |
|
int _Prot = (int)ios_base::_Openprot) |
| 717 |
|
: basic_ostream<_Elem, _Traits>(&_Filebuffer) |
| 718 |
|
{ // construct with wide-named file -- EXTENSION |
| 719 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 720 |
|
_Myios::setstate(ios_base::failbit); |
| 721 |
|
} |
| 722 |
|
|
| 723 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 724 |
|
explicit __CLR_OR_THIS_CALL basic_ofstream(const unsigned short *_Filename, |
| 725 |
|
ios_base::openmode _Mode = ios_base::out, |
| 726 |
|
int _Prot = (int)ios_base::_Openprot) |
| 727 |
|
: basic_ostream<_Elem, _Traits>(&_Filebuffer) |
| 728 |
|
{ // construct with wide-named file -- EXTENSION |
| 729 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 730 |
|
_Myios::setstate(ios_base::failbit); |
| 731 |
|
} |
| 732 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 733 |
|
|
| 734 |
|
explicit __CLR_OR_THIS_CALL basic_ofstream(_Filet *_File) |
| 735 |
|
: basic_ostream<_Elem, _Traits>(&_Filebuffer), |
| 736 |
|
_Filebuffer(_File) |
| 737 |
|
{ // construct with specified C stream |
| 738 |
|
} |
| 739 |
|
|
| 740 |
|
virtual __CLR_OR_THIS_CALL ~basic_ofstream() |
| 741 |
|
{ // destroy the object |
| 742 |
|
} |
| 743 |
|
|
| 744 |
|
_Myfb *__CLR_OR_THIS_CALL rdbuf() const |
| 745 |
|
{ // return pointer to file buffer |
| 746 |
|
return ((_Myfb *)&_Filebuffer); |
| 747 |
|
} |
| 748 |
|
|
| 749 |
|
bool __CLR_OR_THIS_CALL is_open() const |
| 750 |
|
{ // test if C stream has been opened |
| 751 |
|
return (_Filebuffer.is_open()); |
| 752 |
|
} |
| 753 |
|
|
| 754 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, |
| 755 |
|
ios_base::openmode _Mode = ios_base::out, |
| 756 |
|
int _Prot = (int)ios_base::_Openprot) |
| 757 |
|
{ // open a wide-named C stream -- EXTENSION |
| 758 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 759 |
|
_Myios::setstate(ios_base::failbit); |
| 760 |
|
} |
| 761 |
|
|
| 762 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, ios_base::open_mode _Mode) |
| 763 |
|
{ // open a wide-named C stream (old style) -- EXTENSION |
| 764 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 765 |
|
} |
| 766 |
|
|
| 767 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 768 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, |
| 769 |
|
ios_base::openmode _Mode = ios_base::out, |
| 770 |
|
int _Prot = (int)ios_base::_Openprot) |
| 771 |
|
{ // open a wide-named C stream -- EXTENSION |
| 772 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 773 |
|
_Myios::setstate(ios_base::failbit); |
| 774 |
|
} |
| 775 |
|
|
| 776 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, ios_base::open_mode _Mode) |
| 777 |
|
{ // open wide-named file (old style) -- EXTENSION |
| 778 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 779 |
|
} |
| 780 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 781 |
|
|
| 782 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, |
| 783 |
|
ios_base::openmode _Mode = ios_base::out, |
| 784 |
|
int _Prot = (int)ios_base::_Openprot) |
| 785 |
|
{ // open a C stream with specified mode |
| 786 |
|
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) |
| 787 |
|
_Myios::setstate(ios_base::failbit); |
| 788 |
|
} |
| 789 |
|
|
| 790 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, ios_base::open_mode _Mode) |
| 791 |
|
{ // open a C stream with specified mode (old style) |
| 792 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 793 |
|
} |
| 794 |
|
|
| 795 |
|
void __CLR_OR_THIS_CALL close() |
| 796 |
|
{ // close the C stream |
| 797 |
|
if (_Filebuffer.close() == 0) |
| 798 |
|
_Myios::setstate(ios_base::failbit); |
| 799 |
|
} |
| 800 |
|
|
| 801 |
|
private: |
| 802 |
|
_Myfb _Filebuffer; // the file buffer |
| 803 |
|
}; |
| 804 |
|
|
| 805 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
| 806 |
|
|
| 807 |
|
template class _CRTIMP2_PURE basic_ofstream<char, |
| 808 |
|
char_traits<char> >; |
| 809 |
|
template class _CRTIMP2_PURE basic_ofstream<wchar_t, |
| 810 |
|
char_traits<wchar_t> >; |
| 811 |
|
|
| 812 |
|
|
| 813 |
|
|
| 814 |
|
#endif /* _DLL_CPPLIB */ |
| 815 |
|
|
| 816 |
|
// TEMPLATE CLASS basic_fstream |
| 817 |
|
template<class _Elem, |
| 818 |
|
class _Traits> |
| 819 |
|
class basic_fstream |
| 820 |
|
: public basic_iostream<_Elem, _Traits> |
| 821 |
|
{ // input/output stream associated with a C stream |
| 822 |
|
public: |
| 823 |
|
typedef basic_fstream<_Elem, _Traits> _Myt; |
| 824 |
|
typedef basic_ios<_Elem, _Traits> _Myios; |
| 825 |
|
typedef _Elem char_type; |
| 826 |
|
typedef _Traits traits_type; |
| 827 |
|
typedef typename _Traits::int_type int_type; |
| 828 |
|
typedef typename _Traits::pos_type pos_type; |
| 829 |
|
typedef typename _Traits::off_type off_type; |
| 830 |
|
|
| 831 |
|
__CLR_OR_THIS_CALL basic_fstream() |
| 832 |
|
: basic_iostream<_Elem, _Traits>(&_Filebuffer) |
| 833 |
|
{ // construct unopened |
| 834 |
|
} |
| 835 |
|
|
| 836 |
|
explicit __CLR_OR_THIS_CALL basic_fstream(const char *_Filename, |
| 837 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 838 |
|
int _Prot = (int)ios_base::_Openprot) |
| 839 |
|
: basic_iostream<_Elem, _Traits>(&_Filebuffer) |
| 840 |
|
{ // construct with named file and specified mode |
| 841 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 842 |
|
_Myios::setstate(ios_base::failbit); |
| 843 |
|
} |
| 844 |
|
|
| 845 |
|
explicit __CLR_OR_THIS_CALL basic_fstream(const wchar_t *_Filename, |
| 846 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 847 |
|
int _Prot = (int)ios_base::_Openprot) |
| 848 |
|
: basic_iostream<_Elem, _Traits>(&_Filebuffer) |
| 849 |
|
{ // construct with wide-named file -- EXTENSION |
| 850 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 851 |
|
_Myios::setstate(ios_base::failbit); |
| 852 |
|
} |
| 853 |
|
|
| 854 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 855 |
|
explicit __CLR_OR_THIS_CALL basic_fstream(const unsigned short *_Filename, |
| 856 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 857 |
|
int _Prot = (int)ios_base::_Openprot) |
| 858 |
|
: basic_iostream<_Elem, _Traits>(&_Filebuffer) |
| 859 |
|
{ // construct with wide-named file -- EXTENSION |
| 860 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 861 |
|
_Myios::setstate(ios_base::failbit); |
| 862 |
|
} |
| 863 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 864 |
|
|
| 865 |
|
explicit __CLR_OR_THIS_CALL basic_fstream(_Filet *_File) |
| 866 |
|
: basic_iostream<_Elem, _Traits>(&_Filebuffer), |
| 867 |
|
_Filebuffer(_File) |
| 868 |
|
{ // construct with specified C stream |
| 869 |
|
} |
| 870 |
|
|
| 871 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, |
| 872 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 873 |
|
int _Prot = (int)ios_base::_Openprot) |
| 874 |
|
{ // open a wide-named C stream -- EXTENSION |
| 875 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 876 |
|
_Myios::setstate(ios_base::failbit); |
| 877 |
|
} |
| 878 |
|
|
| 879 |
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, ios_base::open_mode _Mode) |
| 880 |
|
{ // open a wide-named C stream (old style) -- EXTENSION |
| 881 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 882 |
|
} |
| 883 |
|
|
| 884 |
|
#ifdef _NATIVE_WCHAR_T_DEFINED |
| 885 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, |
| 886 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 887 |
|
int _Prot = (int)ios_base::_Openprot) |
| 888 |
|
{ // open a wide-named C stream -- EXTENSION |
| 889 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 890 |
|
_Myios::setstate(ios_base::failbit); |
| 891 |
|
} |
| 892 |
|
|
| 893 |
|
void __CLR_OR_THIS_CALL open(const unsigned short *_Filename, ios_base::open_mode _Mode) |
| 894 |
|
{ // open a wide-named C stream (old style) -- EXTENSION |
| 895 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 896 |
|
} |
| 897 |
|
#endif /* _NATIVE_WCHAR_T_DEFINED */ |
| 898 |
|
|
| 899 |
|
virtual __CLR_OR_THIS_CALL ~basic_fstream() |
| 900 |
|
{ // destroy the object |
| 901 |
|
} |
| 902 |
|
|
| 903 |
|
basic_filebuf<_Elem, _Traits> *__CLR_OR_THIS_CALL rdbuf() const |
| 904 |
|
{ // return pointer to file buffer |
| 905 |
|
return ((basic_filebuf<_Elem, _Traits> *)&_Filebuffer); |
| 906 |
|
} |
| 907 |
|
|
| 908 |
|
bool __CLR_OR_THIS_CALL is_open() const |
| 909 |
|
{ // test if C stream has been opened |
| 910 |
|
return (_Filebuffer.is_open()); |
| 911 |
|
} |
| 912 |
|
|
| 913 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, |
| 914 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out, |
| 915 |
|
int _Prot = (int)ios_base::_Openprot) |
| 916 |
|
{ // open a C stream with specified mode |
| 917 |
|
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) |
| 918 |
|
_Myios::setstate(ios_base::failbit); |
| 919 |
|
} |
| 920 |
|
|
| 921 |
|
void __CLR_OR_THIS_CALL open(const char *_Filename, ios_base::open_mode _Mode) |
| 922 |
|
{ // open a C stream with specified mode (old style) |
| 923 |
|
open(_Filename, (ios_base::openmode)_Mode); |
| 924 |
|
} |
| 925 |
|
|
| 926 |
|
void __CLR_OR_THIS_CALL close() |
| 927 |
|
{ // close the C stream |
| 928 |
|
if (_Filebuffer.close() == 0) |
| 929 |
|
_Myios::setstate(ios_base::failbit); |
| 930 |
|
} |
| 931 |
|
|
| 932 |
|
private: |
| 933 |
|
basic_filebuf<_Elem, _Traits> _Filebuffer; // the file buffer |
| 934 |
|
}; |
| 935 |
|
|
| 936 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
| 937 |
|
|
| 938 |
|
template class _CRTIMP2_PURE basic_fstream<char, |
| 939 |
|
char_traits<char> >; |
| 940 |
|
template class _CRTIMP2_PURE basic_fstream<wchar_t, |
| 941 |
|
char_traits<wchar_t> >; |
| 942 |
|
|
| 943 |
|
|
| 944 |
|
|
| 945 |
|
#endif /* _DLL_CPPLIB */ |
| 946 |
|
_STD_END |
| 947 |
|
|
| 948 |
|
#ifdef _MSC_VER |
| 949 |
|
#pragma warning(default: 4127) |
| 950 |
|
#endif |
| 951 |
|
|
| 952 |
|
#ifdef _MSC_VER |
| 953 |
|
#pragma warning(pop) |
| 954 |
|
#pragma pack(pop) |
| 955 |
|
#endif /* _MSC_VER */ |
| 956 |
|
|
| 957 |
|
#endif /* RC_INVOKED */ |
| 958 |
|
#endif /* _FSTREAM_ */ |
| 959 |
|
|
| 960 |
|
/* |
| 961 |
|
* Copyright (c) 1992-2006 by P.J. Plauger. ALL RIGHTS RESERVED. |
| 962 |
|
* Consult your license regarding permissions and restrictions. |
| 963 |
|
V5.02:0009 */ |
| 964 |
|
|
|
|
|