Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

681 lines
19 KiB

  1. // fstream standard header
  2. #pragma once
  3. #ifndef _FSTREAM_
  4. #define _FSTREAM_
  5. #include <istream>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. #pragma warning(disable: 4127)
  9. _STD_BEGIN
  10. extern _CRTIMP2 _Filet *__cdecl _Fiopen(const char *, ios_base::openmode);
  11. // TEMPLATE FUNCTION _Fgetc
  12. template<class _Elem> inline
  13. bool _Fgetc(_Elem& _Ch, _Filet *_File)
  14. { // get an element from a C stream
  15. return (fread(&_Ch, sizeof (_Elem), 1, _File) == 1);
  16. }
  17. template<> inline bool _Fgetc(char& _Byte, _Filet *_File)
  18. { // get a char element from a C stream
  19. int _Meta;
  20. if ((_Meta = fgetc(_File)) == EOF)
  21. return (false);
  22. else
  23. { // got one, convert to char
  24. _Byte = (char)_Meta;
  25. return (true);
  26. }
  27. }
  28. template<> inline bool _Fgetc(wchar_t& _Wchar, _Filet *_File)
  29. { // get a wchar_t element from a C stream
  30. wint_t _Meta;
  31. if ((_Meta = fgetwc(_File)) == WEOF)
  32. return (false);
  33. else
  34. { // got one, convert to wchar_t
  35. _Wchar = (wchar_t)_Meta;
  36. return (true);
  37. }
  38. }
  39. // TEMPLATE FUNCTION _Fputc
  40. template<class _Elem> inline
  41. bool _Fputc(_Elem _Ch, _Filet *_File)
  42. { // put an element to a C stream
  43. return (fwrite(&_Ch, sizeof (_Elem), 1, _File) == 1);
  44. }
  45. template<> inline bool _Fputc(char _Byte, _Filet *_File)
  46. { // put a char element to a C stream
  47. return (fputc(_Byte, _File) != EOF);
  48. }
  49. template<> inline bool _Fputc(wchar_t _Wchar, _Filet *_File)
  50. { // put a wchar_t element to a C stream
  51. return (fputwc(_Wchar, _File) != WEOF);
  52. }
  53. // TEMPLATE FUNCTION _Ungetc
  54. template<class _Elem> inline
  55. bool _Ungetc(const _Elem& _Ch, _Filet *_File)
  56. { // put back an arbitrary element to a C stream (always fail)
  57. return (false);
  58. }
  59. template<> inline bool _Ungetc(const char& _Byte, _Filet *_File)
  60. { // put back a char element to a C stream
  61. return (ungetc((unsigned char)_Byte, _File) != EOF);
  62. }
  63. template<> inline bool _Ungetc(const signed char& _Byte, _Filet *_File)
  64. { // put back a signed char element to a C stream
  65. return (ungetc((unsigned char)_Byte, _File) != EOF);
  66. }
  67. template<> inline bool _Ungetc(const unsigned char& _Byte, _Filet *_File)
  68. { // put back an unsigned char element to a C stream
  69. return (ungetc(_Byte, _File) != EOF);
  70. }
  71. template<> inline bool _Ungetc(const wchar_t& _Wchar, _Filet *_File)
  72. { // put back a wchar_t element to a C stream
  73. return (ungetwc(_Wchar, _File) != WEOF);
  74. }
  75. // TEMPLATE CLASS basic_filebuf
  76. template<class _Elem,
  77. class _Traits>
  78. class basic_filebuf
  79. : public basic_streambuf<_Elem, _Traits>
  80. { // stream buffer associated with a C stream
  81. public:
  82. typedef basic_filebuf<_Elem, _Traits> _Myt;
  83. typedef basic_streambuf<_Elem, _Traits> _Mysb;
  84. typedef codecvt<_Elem, char, typename _Traits::state_type> _Cvt;
  85. virtual ~basic_filebuf()
  86. { // destroy the object
  87. if (_Closef)
  88. close();
  89. _DELETE_CRT(_Mystr);
  90. }
  91. basic_filebuf(_Filet *_File = 0)
  92. : _Mysb(), _Mystr(0), _Loc()
  93. { // construct from pointer to C stream
  94. _Init(_File, _Newfl);
  95. }
  96. typedef typename _Traits::int_type int_type;
  97. typedef typename _Traits::pos_type pos_type;
  98. typedef typename _Traits::off_type off_type;
  99. basic_filebuf(_Uninitialized)
  100. : _Mysb(_Noinit), _Loc(_Noinit)
  101. { // construct uninitialized
  102. }
  103. enum _Initfl
  104. { // reasons for a call to _Init
  105. _Newfl, _Openfl, _Closefl};
  106. bool is_open() const
  107. { // test if C stream has been opened
  108. return (_Myfile != 0);
  109. }
  110. _Myt *open(const char *_Filename, ios_base::openmode _Mode)
  111. { // open a C stream with specified mode
  112. _Filet *_File;
  113. if (_Myfile != 0 || (_File = _Fiopen(_Filename, _Mode)) == 0)
  114. return (0); // open failed
  115. _Init(_File, _Openfl);
  116. _Initcvt((_Cvt *)&_USE(_Mysb::getloc(), _Cvt));
  117. return (this); // open succeeded
  118. }
  119. _Myt *open(const char *_Filename, ios_base::open_mode _Mode)
  120. { // open a C stream with specified mode (old style)
  121. return (open(_Filename, (ios_base::openmode)_Mode));
  122. }
  123. _Myt *close()
  124. { // close the C stream
  125. if (_Myfile != 0 && _Endwrite() && fclose(_Myfile) == 0)
  126. { // close succeeded, tidy up
  127. _Init(0, _Closefl);
  128. return (this);
  129. }
  130. else
  131. return (0);
  132. }
  133. protected:
  134. virtual int_type overflow(int_type _Meta = _Traits::eof())
  135. { // put an element to stream
  136. if (_Traits::eq_int_type(_Traits::eof(), _Meta))
  137. return (_Traits::not_eof(_Meta)); // EOF, return success code
  138. else if (_Mysb::pptr() != 0
  139. && _Mysb::pptr() < _Mysb::epptr())
  140. { // room in buffer, store it
  141. *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
  142. return (_Meta);
  143. }
  144. else if (_Myfile == 0)
  145. return (_Traits::eof()); // no open C stream, fail
  146. else if (_Pcvt == 0)
  147. return (_Fputc(_Traits::to_char_type(_Meta), _Myfile)
  148. ? _Meta : _Traits::eof()); // no codecvt facet, put as is
  149. else
  150. { // put using codecvt facet
  151. const int _STRING_INC = 8;
  152. const _Elem _Ch = _Traits::to_char_type(_Meta);
  153. const _Elem *_Source;
  154. char *_Dest;
  155. _Mystr->erase();
  156. string _Str(_STRING_INC, '\0');
  157. for (; ; )
  158. switch (_Pcvt->out(_State,
  159. &_Ch, &_Ch + 1, _Source,
  160. &*_Str.begin(), &*_Str.end(), _Dest))
  161. { // test result of converting one element
  162. case codecvt_base::partial:
  163. case codecvt_base::ok:
  164. { // converted something, try to put it out
  165. size_t _Count = _Dest - &*_Str.begin();
  166. if (0 < _Count && _Count !=
  167. fwrite(&*_Str.begin(), 1, _Count, _Myfile))
  168. return (_Traits::eof()); // write failed
  169. _Wrotesome = true; // write succeeded
  170. if (_Source != &_Ch)
  171. return (_Meta); // converted whole element
  172. if (_Count == 0)
  173. _Str.append(_STRING_INC, '\0'); // try some more
  174. break;
  175. }
  176. case codecvt_base::noconv:
  177. return (_Fputc(_Ch, _Myfile) ? _Meta
  178. : _Traits::eof()); // no conversion, put as is
  179. default:
  180. return (_Traits::eof()); // conversion failed
  181. }
  182. }
  183. }
  184. virtual int_type pbackfail(int_type _Meta = _Traits::eof())
  185. { // put an element back to stream
  186. if (_Mysb::gptr() != 0
  187. && _Mysb::eback() < _Mysb::gptr()
  188. && (_Traits::eq_int_type(_Traits::eof(), _Meta)
  189. || _Traits::eq_int_type(_Traits::to_int_type(_Mysb::gptr()[-1]),
  190. _Meta)))
  191. { // just back up position
  192. _Mysb::_Gndec();
  193. return (_Traits::not_eof(_Meta));
  194. }
  195. else if (_Myfile == 0 || _Traits::eq_int_type(_Traits::eof(), _Meta))
  196. return (_Traits::eof()); // no open C stream or EOF, fail
  197. else if (_Pcvt == 0 && _Ungetc(_Traits::to_char_type(_Meta), _Myfile))
  198. return (_Meta); // no facet and unget succeeded, return
  199. else
  200. { // putback to _Mychar
  201. _Mychar = _Traits::to_char_type(_Meta);
  202. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar + 1);
  203. return (_Meta);
  204. }
  205. }
  206. virtual int_type underflow()
  207. { // get an element from stream, but don't point past it
  208. int_type _Meta;
  209. if (_Mysb::gptr() != 0
  210. && _Mysb::gptr() < _Mysb::egptr())
  211. return (_Traits::to_int_type(*_Mysb::gptr())); // return buffered
  212. else if (_Traits::eq_int_type(_Traits::eof(), _Meta = uflow()))
  213. return (_Meta); // uflow failed, return EOF
  214. else
  215. { // get a char, don't point past it
  216. pbackfail(_Meta);
  217. return (_Meta);
  218. }
  219. }
  220. virtual int_type uflow()
  221. { // get an element from stream, point past it
  222. if (_Mysb::gptr() != 0
  223. && _Mysb::gptr() < _Mysb::egptr())
  224. return (_Traits::to_int_type(
  225. *_Mysb::_Gninc())); // return buffered
  226. else if (_Myfile == 0)
  227. return (_Traits::eof()); // no open C stream, fail
  228. else if (_Pcvt == 0)
  229. { // no codecvt facet, just get it
  230. _Elem _Ch = 0;
  231. return (_Fgetc(_Ch, _Myfile) ? _Traits::to_int_type(_Ch)
  232. : _Traits::eof());
  233. }
  234. else
  235. for (_State0 = _State, _Mystr->erase(); ; )
  236. { // get using codecvt facet
  237. _Elem _Ch, *_Dest;
  238. const char *_Source;
  239. int _Meta = fgetc(_Myfile);
  240. if (_Meta == EOF)
  241. return (_Traits::eof()); // partial char?
  242. _Mystr->append(1, (char)_Meta); // append byte and convert
  243. _State = _State0;
  244. switch (_Pcvt->in(_State,
  245. &*_Mystr->begin(), &*_Mystr->end(), _Source,
  246. &_Ch, &_Ch + 1, _Dest))
  247. { // test result of converting one element
  248. case codecvt_base::partial:
  249. break; // partial, not done yet
  250. case codecvt_base::noconv:
  251. if (_Mystr->size() < sizeof (_Elem))
  252. break; // no conversion, but need more chars
  253. memcpy(&_Ch, &*_Mystr->begin(),
  254. sizeof (_Elem)); // copy raw bytes to element
  255. case codecvt_base::ok: // can fall through
  256. return (_Traits::to_int_type(_Ch)); // return result
  257. default:
  258. return (_Traits::eof()); // conversion failed
  259. }
  260. }
  261. }
  262. virtual pos_type seekoff(off_type _Off, ios_base::seekdir _Way,
  263. ios_base::openmode =
  264. (ios_base::openmode)(ios_base::in | ios_base::out))
  265. { // change position by _Off
  266. fpos_t _Fileposition;
  267. if (_Mysb::gptr() != &_Mychar
  268. || _Mysb::egptr() <= _Mysb::gptr()
  269. || _Way != ios_base::cur)
  270. ; // don't have to worry about putback character
  271. else if (_Pcvt == 0)
  272. _Off -= (off_type)sizeof (_Elem); // back up over _Elem bytes
  273. else
  274. { // back up over converted bytes
  275. _Off -= (off_type)_Mystr->size();
  276. _Mystr->erase();
  277. _State = _State0;
  278. }
  279. if (_Myfile == 0 || !_Endwrite()
  280. || (_Off != 0 || _Way != ios_base::cur)
  281. && fseek(_Myfile, (long)_Off, _Way) != 0
  282. || fgetpos(_Myfile, &_Fileposition) != 0)
  283. return (pos_type(_BADOFF)); // report failure
  284. if (_Mysb::gptr() == &_Mychar)
  285. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar); // discard putback
  286. return (pos_type(_State, _Fileposition)); // return new position
  287. }
  288. virtual pos_type seekpos(pos_type _Pos,
  289. ios_base::openmode =
  290. (ios_base::openmode)(ios_base::in | ios_base::out))
  291. { // change position to _Pos
  292. fpos_t _Fileposition = _Pos.seekpos();
  293. off_type _Off = (off_type)_Pos - _FPOSOFF(_Fileposition);
  294. if (_Myfile == 0 || !_Endwrite()
  295. || fsetpos(_Myfile, &_Fileposition) != 0
  296. || _Off != 0 && fseek(_Myfile, (long)_Off, SEEK_CUR) != 0
  297. || fgetpos(_Myfile, &_Fileposition) != 0)
  298. return (pos_type(_BADOFF)); // report failure
  299. if (_Mystr != 0)
  300. _State = _Pos.state(), _Mystr->erase(); // restore state
  301. if (_Mysb::gptr() == &_Mychar)
  302. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar); // discard putback
  303. return (pos_type(_State, _Fileposition)); // return new position
  304. }
  305. virtual _Mysb *setbuf(_Elem *_Buffer, streamsize _Count)
  306. { // offer _Buffer to C stream
  307. return (_Myfile == 0 || setvbuf(_Myfile, (char *)_Buffer,
  308. _Buffer == 0 && _Count == 0 ? _IONBF : _IOFBF,
  309. _Count * sizeof (_Elem)) != 0 ? 0 : this);
  310. }
  311. virtual int sync()
  312. { // synchronize C stream with external file
  313. return (_Myfile == 0
  314. || _Traits::eq_int_type(_Traits::eof(), overflow())
  315. || 0 <= fflush(_Myfile) ? 0 : -1);
  316. }
  317. virtual void imbue(const locale& _Loc)
  318. { // set locale to argument (capture nontrivial codecvt facet)
  319. _Initcvt((_Cvt *)&_USE(_Loc, _Cvt));
  320. }
  321. void _Init(_Filet *_File, _Initfl _Which)
  322. { // initialize to C stream _File after {new, open, close}
  323. static typename _Traits::state_type _Stinit; // initial state
  324. _Closef = _Which == _Openfl;
  325. _Wrotesome = false;
  326. _Mysb::_Init(); // initialize stream buffer base object
  327. #ifndef _IORCNT
  328. #define _IORCNT _IOCNT /* read and write counts are the same */
  329. #define _IOWCNT _IOCNT
  330. #endif
  331. if (_File != 0 && sizeof (_Elem) == 1)
  332. { // point inside C stream with [first, first + count) buffer
  333. _Elem **_Pb = (_Elem **)&_File->_IOBASE;
  334. _Elem **_Pn = (_Elem **)&_File->_IOPTR;
  335. int *_Nr = (int *)&_File->_IORCNT;
  336. int *_Nw = (int *)&_File->_IOWCNT;
  337. _Mysb::_Init(_Pb, _Pn, _Nr, _Pb, _Pn, _Nw);
  338. }
  339. _Myfile = _File;
  340. _State = _Stinit;
  341. _State0 = _Stinit;
  342. _Pcvt = 0; // pointer to codecvt facet
  343. }
  344. bool _Endwrite()
  345. { // put shift to initial conversion state, as needed
  346. if (_Pcvt == 0 || !_Wrotesome)
  347. return (true);
  348. else
  349. { // may have to put
  350. const int _STRING_INC = 8;
  351. char *_Dest;
  352. overflow();
  353. string _Str(_STRING_INC, '\0');
  354. for (; ; )
  355. switch (_Pcvt->unshift(_State,
  356. &*_Str.begin(), &*_Str.end(), _Dest))
  357. { // test result of homing conversion
  358. case codecvt_base::ok:
  359. _Wrotesome = false; // homed successfully
  360. case codecvt_base::partial: // can fall through
  361. { // put any generated bytes
  362. size_t _Count = _Dest - &*_Str.begin();
  363. if (0 < _Count && _Count !=
  364. fwrite(&*_Str.begin(), _Count, 1, _Myfile))
  365. return (false); // write failed
  366. if (!_Wrotesome)
  367. return (true);
  368. _Str.append(_STRING_INC, '\0'); // try some more
  369. break;
  370. }
  371. case codecvt_base::noconv:
  372. return (true); // nothing to do
  373. default:
  374. return (false); // conversion failed
  375. }
  376. }
  377. }
  378. void _Initcvt(_Cvt *_Newpcvt)
  379. { // initialize codecvt pointer
  380. if (_Newpcvt->always_noconv())
  381. _Pcvt = 0; // nothing to do
  382. else
  383. { // set up for nontrivial codecvt facet
  384. _Pcvt = _Newpcvt;
  385. _Loc = _ADDFAC(_Loc, _Pcvt); // to keep facet alive
  386. _Mysb::_Init(); // reset any buffering
  387. if (_Mystr == 0)
  388. _Mystr = _NEW_CRT _STRING_CRT; // buy conversion buffer
  389. }
  390. }
  391. private:
  392. _Cvt *_Pcvt; // pointer to codecvt facet (may be null)
  393. typename _Traits::state_type _State0; // rollback for bad conversion
  394. _Elem _Mychar; // putback character, when _Ungetc fails
  395. _STRING_CRT *_Mystr; // string to hold partial conversion byte sequences
  396. bool _Wrotesome; // true if homing sequence may be needed
  397. typename _Traits::state_type _State; // current conversion state
  398. bool _Closef; // true if C stream must be closed
  399. locale _Loc; // locale object to hold codecvt facet
  400. _Filet *_Myfile; // pointer to C stream
  401. };
  402. #ifdef _DLL_CPPLIB
  403. template class _CRTIMP2 basic_filebuf<char,
  404. char_traits<char> >;
  405. template class _CRTIMP2 basic_filebuf<wchar_t,
  406. char_traits<wchar_t> >;
  407. #endif // _DLL_CPPLIB
  408. // TEMPLATE CLASS basic_ifstream
  409. template<class _Elem,
  410. class _Traits>
  411. class basic_ifstream
  412. : public basic_istream<_Elem, _Traits>
  413. { // input stream associated with a C stream
  414. public:
  415. typedef basic_ifstream<_Elem, _Traits> _Myt;
  416. typedef basic_filebuf<_Elem, _Traits> _Myfb;
  417. typedef basic_ios<_Elem, _Traits> _Myios;
  418. basic_ifstream()
  419. : basic_istream<_Elem, _Traits>(&_Filebuffer)
  420. { // construct unopened
  421. }
  422. explicit basic_ifstream(const char *_Filename,
  423. ios_base::openmode _Mode = ios_base::in)
  424. : basic_istream<_Elem, _Traits>(&_Filebuffer)
  425. { // construct with named file and specified mode
  426. if (_Filebuffer.open(_Filename, _Mode | ios_base::in) == 0)
  427. _Myios::setstate(ios_base::failbit);
  428. }
  429. virtual ~basic_ifstream()
  430. { // destroy the object
  431. }
  432. _Myfb *rdbuf() const
  433. { // return pointer to file buffer
  434. return ((_Myfb *)&_Filebuffer);
  435. }
  436. bool is_open() const
  437. { // test if C stream has been opened
  438. return (_Filebuffer.is_open());
  439. }
  440. void open(const char *_Filename,
  441. ios_base::openmode _Mode = ios_base::in)
  442. { // open a C stream with specified mode
  443. if (_Filebuffer.open(_Filename, _Mode | ios_base::in) == 0)
  444. _Myios::setstate(ios_base::failbit);
  445. }
  446. void open(const char *_Filename, ios_base::open_mode _Mode)
  447. { // open named file with specified mode (old style)
  448. open(_Filename, (ios_base::openmode)_Mode);
  449. }
  450. void close()
  451. { // close the C stream
  452. if (_Filebuffer.close() == 0)
  453. _Myios::setstate(ios_base::failbit);
  454. }
  455. private:
  456. _Myfb _Filebuffer; // the file buffer
  457. };
  458. #ifdef _DLL_CPPLIB
  459. template class _CRTIMP2 basic_ifstream<char,
  460. char_traits<char> >;
  461. template class _CRTIMP2 basic_ifstream<wchar_t,
  462. char_traits<wchar_t> >;
  463. #endif // _DLL_CPPLIB
  464. // TEMPLATE CLASS basic_ofstream
  465. template<class _Elem,
  466. class _Traits>
  467. class basic_ofstream
  468. : public basic_ostream<_Elem, _Traits>
  469. { // output stream associated with a C stream
  470. public:
  471. typedef basic_ofstream<_Elem, _Traits> _Myt;
  472. typedef basic_filebuf<_Elem, _Traits> _Myfb;
  473. typedef basic_ios<_Elem, _Traits> _Myios;
  474. basic_ofstream()
  475. : basic_ostream<_Elem, _Traits>(&_Filebuffer)
  476. { // construct unopened
  477. }
  478. explicit basic_ofstream(const char *_Filename,
  479. ios_base::openmode _Mode = ios_base::out)
  480. : basic_ostream<_Elem, _Traits>(&_Filebuffer)
  481. { // construct with named file and specified mode
  482. if (_Filebuffer.open(_Filename, _Mode | ios_base::out) == 0)
  483. _Myios::setstate(ios_base::failbit);
  484. }
  485. virtual ~basic_ofstream()
  486. { // destroy the object
  487. }
  488. _Myfb *rdbuf() const
  489. { // return pointer to file buffer
  490. return ((_Myfb *)&_Filebuffer);
  491. }
  492. bool is_open() const
  493. { // test if C stream has been opened
  494. return (_Filebuffer.is_open());
  495. }
  496. void open(const char *_Filename,
  497. ios_base::openmode _Mode = ios_base::out)
  498. { // open a C stream with specified mode
  499. if (_Filebuffer.open(_Filename, _Mode | ios_base::out) == 0)
  500. _Myios::setstate(ios_base::failbit);
  501. }
  502. void open(const char *_Filename, ios_base::open_mode _Mode)
  503. { // open a C stream with specified mode (old style)
  504. open(_Filename, (ios_base::openmode)_Mode);
  505. }
  506. void close()
  507. { // close the C stream
  508. if (_Filebuffer.close() == 0)
  509. _Myios::setstate(ios_base::failbit);
  510. }
  511. private:
  512. _Myfb _Filebuffer; // the file buffer
  513. };
  514. #ifdef _DLL_CPPLIB
  515. template class _CRTIMP2 basic_ofstream<char,
  516. char_traits<char> >;
  517. template class _CRTIMP2 basic_ofstream<wchar_t,
  518. char_traits<wchar_t> >;
  519. #endif // _DLL_CPPLIB
  520. // TEMPLATE CLASS basic_fstream
  521. template<class _Elem,
  522. class _Traits>
  523. class basic_fstream
  524. : public basic_iostream<_Elem, _Traits>
  525. { // input/output stream associated with a C stream
  526. public:
  527. typedef basic_ios<_Elem, _Traits> _Myios;
  528. typedef _Elem char_type;
  529. typedef _Traits traits_type;
  530. typedef typename _Traits::int_type int_type;
  531. typedef typename _Traits::pos_type pos_type;
  532. typedef typename _Traits::off_type off_type;
  533. basic_fstream()
  534. : basic_iostream<_Elem, _Traits>(&_Filebuffer)
  535. { // construct unopened
  536. }
  537. explicit basic_fstream(const char *_Filename,
  538. ios_base::openmode _Mode = ios_base::in | ios_base::out)
  539. : basic_iostream<_Elem, _Traits>(&_Filebuffer)
  540. { // construct with named file and specified mode
  541. if (_Filebuffer.open(_Filename, _Mode) == 0)
  542. _Myios::setstate(ios_base::failbit);
  543. }
  544. virtual ~basic_fstream()
  545. { // destroy the object
  546. }
  547. basic_filebuf<_Elem, _Traits> *rdbuf() const
  548. { // return pointer to file buffer
  549. return ((basic_filebuf<_Elem, _Traits> *)&_Filebuffer);
  550. }
  551. bool is_open() const
  552. { // test if C stream has been opened
  553. return (_Filebuffer.is_open());
  554. }
  555. void open(const char *_Filename,
  556. ios_base::openmode _Mode = ios_base::in | ios_base::out)
  557. { // open a C stream with specified mode
  558. if (_Filebuffer.open(_Filename, _Mode) == 0)
  559. _Myios::setstate(ios_base::failbit);
  560. }
  561. void open(const char *_Filename, ios_base::open_mode _Mode)
  562. { // open a C stream with specified mode (old style)
  563. open(_Filename, (ios_base::openmode)_Mode);
  564. }
  565. void close()
  566. { // close the C stream
  567. if (_Filebuffer.close() == 0)
  568. _Myios::setstate(ios_base::failbit);
  569. }
  570. private:
  571. basic_filebuf<_Elem, _Traits> _Filebuffer; // the file buffer
  572. };
  573. #ifdef _DLL_CPPLIB
  574. template class _CRTIMP2 basic_fstream<char,
  575. char_traits<char> >;
  576. template class _CRTIMP2 basic_fstream<wchar_t,
  577. char_traits<wchar_t> >;
  578. #endif // _DLL_CPPLIB
  579. _STD_END
  580. #pragma warning(default: 4127)
  581. #pragma warning(pop)
  582. #pragma pack(pop)
  583. #endif /* _FSTREAM_ */
  584. /*
  585. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  586. * Consult your license regarding permissions and restrictions.
  587. V3.10:0009 */