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.

157 lines
4.1 KiB

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