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.

212 lines
6.5 KiB

  1. /***
  2. *fstream.h - definitions/declarations for filebuf and fstream classes
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines the classes, values, macros, and functions
  8. * used by the filebuf and fstream classes.
  9. * [AT&T C++]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 01-23-92 KRS Ported from 16-bit version.
  15. * 08-19-92 KRS Remove sh_compat for NT.
  16. * 02-23-93 SKS Update copyright to 1993
  17. * 03-23-93 CFW Modified #pragma warnings.
  18. * 09-01-93 GJF Merged Cuda and NT SDK versions.
  19. * 10-13-93 GJF Enclose #pragma-s in #ifdef _MSC_VER
  20. * 08-12-94 GJF Disable warning 4514 instead of 4505.
  21. * 11-03-94 GJF Changed pack pragma to 8 byte alignment.
  22. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  23. * 02-14-95 CFW Clean up Mac merge.
  24. * 05-11-95 CFW Only for use by C++ programs.
  25. * 12-14-95 JWM Add "#pragma once".
  26. * 04-09-96 SKS Change _CRTIMP to _CRTIMP1 for special iostream build
  27. * 04-15-96 JWM Remove _OLD_IOSTREAMS, add '#pragma comment(lib,"cirt")'.
  28. * 04-16-96 JWM '#include useoldio.h' replaces '#pragma comment(...)'.
  29. * 02-21-97 GJF Cleaned out obsolete support for _NTSDK. Also,
  30. * detab-ed.
  31. * 05-17-99 PML Remove all Macintosh support.
  32. *
  33. ****/
  34. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  35. #pragma once
  36. #endif
  37. #ifdef __cplusplus
  38. #ifndef _INC_FSTREAM
  39. #define _INC_FSTREAM
  40. #if !defined(_WIN32)
  41. #error ERROR: Only Win32 target supported!
  42. #endif
  43. #ifndef _CRTBLD
  44. /* This version of the header files is NOT for user programs.
  45. * It is intended for use when building the C runtimes ONLY.
  46. * The version intended for public use will not have this message.
  47. */
  48. #error ERROR: Use of C runtime library internal header file.
  49. #endif /* _CRTBLD */
  50. #ifdef _MSC_VER
  51. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  52. // alignment.
  53. #pragma pack(push,8)
  54. #include <useoldio.h>
  55. #endif // _MSC_VER
  56. /* Define _CRTIMP */
  57. #ifndef _CRTIMP
  58. #ifdef CRTDLL
  59. #define _CRTIMP __declspec(dllexport)
  60. #else /* ndef CRTDLL */
  61. #ifdef _DLL
  62. #define _CRTIMP __declspec(dllimport)
  63. #else /* ndef _DLL */
  64. #define _CRTIMP
  65. #endif /* _DLL */
  66. #endif /* CRTDLL */
  67. #endif /* _CRTIMP */
  68. #ifndef _INTERNAL_IFSTRIP_
  69. /* Define _CRTIMP1 */
  70. #ifndef _CRTIMP1
  71. #ifdef CRTDLL1
  72. #define _CRTIMP1 __declspec(dllexport)
  73. #else /* ndef CRTDLL1 */
  74. #define _CRTIMP1 _CRTIMP
  75. #endif /* CRTDLL1 */
  76. #endif /* _CRTIMP1 */
  77. #endif /* _INTERNAL_IFSTRIP_ */
  78. #include <iostream.h>
  79. #ifdef _MSC_VER
  80. // C4514: "unreferenced inline function has been removed"
  81. #pragma warning(disable:4514) // disable C4514 warning
  82. // #pragma warning(default:4514) // use this to reenable, if desired
  83. #endif // _MSC_VER
  84. typedef int filedesc;
  85. class _CRTIMP1 filebuf : public streambuf {
  86. public:
  87. static const int openprot; // default share/prot mode for open
  88. // optional share values for 3rd argument (prot) of open or constructor
  89. static const int sh_none; // exclusive mode no sharing
  90. static const int sh_read; // allow read sharing
  91. static const int sh_write; // allow write sharing
  92. // use (sh_read | sh_write) to allow both read and write sharing
  93. // options for setmode member function
  94. static const int binary;
  95. static const int text;
  96. filebuf();
  97. filebuf(filedesc);
  98. filebuf(filedesc, char *, int);
  99. ~filebuf();
  100. filebuf* attach(filedesc);
  101. filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
  102. int is_open() const { return (x_fd!=-1); }
  103. filebuf* open(const char *, int, int = filebuf::openprot);
  104. filebuf* close();
  105. int setmode(int = filebuf::text);
  106. virtual int overflow(int=EOF);
  107. virtual int underflow();
  108. virtual streambuf* setbuf(char *, int);
  109. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  110. // virtual streampos seekpos(streampos, int);
  111. virtual int sync();
  112. private:
  113. filedesc x_fd;
  114. int x_fOpened;
  115. };
  116. class _CRTIMP1 ifstream : public istream {
  117. public:
  118. ifstream();
  119. ifstream(const char *, int =ios::in, int = filebuf::openprot);
  120. ifstream(filedesc);
  121. ifstream(filedesc, char *, int);
  122. ~ifstream();
  123. streambuf * setbuf(char *, int);
  124. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  125. void attach(filedesc);
  126. filedesc fd() const { return rdbuf()->fd(); }
  127. int is_open() const { return rdbuf()->is_open(); }
  128. void open(const char *, int =ios::in, int = filebuf::openprot);
  129. void close();
  130. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  131. };
  132. class _CRTIMP1 ofstream : public ostream {
  133. public:
  134. ofstream();
  135. ofstream(const char *, int =ios::out, int = filebuf::openprot);
  136. ofstream(filedesc);
  137. ofstream(filedesc, char *, int);
  138. ~ofstream();
  139. streambuf * setbuf(char *, int);
  140. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  141. void attach(filedesc);
  142. filedesc fd() const { return rdbuf()->fd(); }
  143. int is_open() const { return rdbuf()->is_open(); }
  144. void open(const char *, int =ios::out, int = filebuf::openprot);
  145. void close();
  146. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  147. };
  148. class _CRTIMP1 fstream : public iostream {
  149. public:
  150. fstream();
  151. fstream(const char *, int, int = filebuf::openprot);
  152. fstream(filedesc);
  153. fstream(filedesc, char *, int);
  154. ~fstream();
  155. streambuf * setbuf(char *, int);
  156. filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
  157. void attach(filedesc);
  158. filedesc fd() const { return rdbuf()->fd(); }
  159. int is_open() const { return rdbuf()->is_open(); }
  160. void open(const char *, int, int = filebuf::openprot);
  161. void close();
  162. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  163. };
  164. // manipulators to dynamically change file access mode (filebufs only)
  165. inline ios& binary(ios& _fstrm) \
  166. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
  167. inline ios& text(ios& _fstrm) \
  168. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
  169. #ifdef _MSC_VER
  170. #pragma pack(pop)
  171. #endif // _MSC_VER
  172. #endif // _INC_FSTREAM
  173. #endif /* __cplusplus */