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.

169 lines
4.3 KiB

  1. /***
  2. *fstream.h - definitions/declarations for filebuf and fstream classes
  3. *
  4. * Copyright (c) 1991-1995, 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. ****/
  14. #ifdef __cplusplus
  15. #ifndef _INC_FSTREAM
  16. #define _INC_FSTREAM
  17. #if !defined(_WIN32) && !defined(_MAC)
  18. #error ERROR: Only Mac or Win32 targets supported!
  19. #endif
  20. #ifdef _MSC_VER
  21. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  22. // alignment.
  23. #pragma pack(push,8)
  24. #endif // _MSC_VER
  25. /* Define _CRTIMP */
  26. #ifndef _CRTIMP
  27. #ifdef _NTSDK
  28. /* definition compatible with NT SDK */
  29. #define _CRTIMP
  30. #else /* ndef _NTSDK */
  31. /* current definition */
  32. #ifdef _DLL
  33. #define _CRTIMP __declspec(dllimport)
  34. #else /* ndef _DLL */
  35. #define _CRTIMP
  36. #endif /* _DLL */
  37. #endif /* _NTSDK */
  38. #endif /* _CRTIMP */
  39. #include <iostream.h>
  40. #ifdef _MSC_VER
  41. // C4514: "unreferenced inline function has been removed"
  42. #pragma warning(disable:4514) // disable C4514 warning
  43. // #pragma warning(default:4514) // use this to reenable, if desired
  44. #endif // _MSC_VER
  45. typedef int filedesc;
  46. class _CRTIMP filebuf : public streambuf {
  47. public:
  48. static const int openprot; // default share/prot mode for open
  49. // optional share values for 3rd argument (prot) of open or constructor
  50. static const int sh_none; // exclusive mode no sharing
  51. static const int sh_read; // allow read sharing
  52. static const int sh_write; // allow write sharing
  53. // use (sh_read | sh_write) to allow both read and write sharing
  54. // options for setmode member function
  55. static const int binary;
  56. static const int text;
  57. filebuf();
  58. filebuf(filedesc);
  59. filebuf(filedesc, char *, int);
  60. ~filebuf();
  61. filebuf* attach(filedesc);
  62. filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
  63. int is_open() const { return (x_fd!=-1); }
  64. filebuf* open(const char *, int, int = filebuf::openprot);
  65. filebuf* close();
  66. int setmode(int = filebuf::text);
  67. virtual int overflow(int=EOF);
  68. virtual int underflow();
  69. virtual streambuf* setbuf(char *, int);
  70. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  71. // virtual streampos seekpos(streampos, int);
  72. virtual int sync();
  73. private:
  74. filedesc x_fd;
  75. int x_fOpened;
  76. };
  77. class _CRTIMP ifstream : public istream {
  78. public:
  79. ifstream();
  80. ifstream(const char *, int =ios::in, int = filebuf::openprot);
  81. ifstream(filedesc);
  82. ifstream(filedesc, char *, int);
  83. ~ifstream();
  84. streambuf * setbuf(char *, int);
  85. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  86. void attach(filedesc);
  87. filedesc fd() const { return rdbuf()->fd(); }
  88. int is_open() const { return rdbuf()->is_open(); }
  89. void open(const char *, int =ios::in, int = filebuf::openprot);
  90. void close();
  91. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  92. };
  93. class _CRTIMP ofstream : public ostream {
  94. public:
  95. ofstream();
  96. ofstream(const char *, int =ios::out, int = filebuf::openprot);
  97. ofstream(filedesc);
  98. ofstream(filedesc, char *, int);
  99. ~ofstream();
  100. streambuf * setbuf(char *, int);
  101. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  102. void attach(filedesc);
  103. filedesc fd() const { return rdbuf()->fd(); }
  104. int is_open() const { return rdbuf()->is_open(); }
  105. void open(const char *, int =ios::out, int = filebuf::openprot);
  106. void close();
  107. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  108. };
  109. class _CRTIMP fstream : public iostream {
  110. public:
  111. fstream();
  112. fstream(const char *, int, int = filebuf::openprot);
  113. fstream(filedesc);
  114. fstream(filedesc, char *, int);
  115. ~fstream();
  116. streambuf * setbuf(char *, int);
  117. filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
  118. void attach(filedesc);
  119. filedesc fd() const { return rdbuf()->fd(); }
  120. int is_open() const { return rdbuf()->is_open(); }
  121. void open(const char *, int, int = filebuf::openprot);
  122. void close();
  123. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  124. };
  125. // manipulators to dynamically change file access mode (filebufs only)
  126. inline ios& binary(ios& _fstrm) \
  127. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
  128. inline ios& text(ios& _fstrm) \
  129. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
  130. #ifdef _MSC_VER
  131. #pragma pack(pop)
  132. #endif // _MSC_VER
  133. #endif // _INC_FSTREAM
  134. #endif /* __cplusplus */