wfstream.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wfstream.h
  3. // Purpose: interface of wxTempFileOutputStream
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxTempFileOutputStream
  9. wxTempFileOutputStream is an output stream based on wxTempFile.
  10. It provides a relatively safe way to replace the contents of the
  11. existing file.
  12. @library{wxbase}
  13. @category{streams}
  14. @see wxTempFile
  15. */
  16. class wxTempFileOutputStream : public wxOutputStream
  17. {
  18. public:
  19. /**
  20. Associates wxTempFileOutputStream with the file to be replaced and opens it.
  21. @warning
  22. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  23. Call Commit() or wxOutputStream::Close() to replace the old file and close
  24. this one. Calling Discard() (or allowing the destructor to do it) will
  25. discard the changes.
  26. */
  27. wxTempFileOutputStream(const wxString& fileName);
  28. /**
  29. Validate changes: deletes the old file of the given name and renames the new
  30. file to the old name. Returns @true if both actions succeeded.
  31. If @false is returned it may unfortunately mean two quite different things: either that
  32. either the old file couldn't be deleted or that the new file couldn't be renamed
  33. to the old name.
  34. */
  35. virtual bool Commit();
  36. /**
  37. Discard changes: the old file contents are not changed, the temporary file is
  38. deleted.
  39. */
  40. virtual void Discard();
  41. };
  42. /**
  43. @class wxFFileOutputStream
  44. This class represents data written to a file.
  45. There are actually two such groups of classes: this one is based on wxFFile
  46. whereas wxFileOutputStream is based in the wxFile class.
  47. Note that wxOutputStream::SeekO() can seek beyond the end of the stream
  48. (file) and will thus not return ::wxInvalidOffset for that.
  49. @library{wxbase}
  50. @category{streams}
  51. @see wxBufferedOutputStream, wxFFileInputStream, wxFileOutputStream, wxFileInputStream
  52. */
  53. class wxFFileOutputStream : public wxOutputStream
  54. {
  55. public:
  56. /**
  57. Open the given file @a filename with mode @a mode.
  58. @warning
  59. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  60. */
  61. wxFFileOutputStream(const wxString& filename,
  62. const wxString& mode = "wb");
  63. /**
  64. Initializes a file stream in write-only mode using the file I/O object file.
  65. */
  66. wxFFileOutputStream(wxFFile& file);
  67. /**
  68. Initializes a file stream in write-only mode using the file descriptor fp.
  69. */
  70. wxFFileOutputStream(FILE* fp);
  71. /**
  72. Destructor.
  73. */
  74. virtual ~wxFFileOutputStream();
  75. /**
  76. Returns @true if the stream is initialized and ready.
  77. */
  78. bool IsOk() const;
  79. /**
  80. Returns the underlying file object.
  81. @since 2.9.5
  82. */
  83. wxFFile* GetFile() const;
  84. };
  85. /**
  86. @class wxFileOutputStream
  87. This class represents data written to a file.
  88. There are actually two such groups of classes: this one is based on wxFile
  89. whereas wxFFileOutputStream is based in the wxFFile class.
  90. Note that wxOutputStream::SeekO() can seek beyond the end of the stream
  91. (file) and will thus not return ::wxInvalidOffset for that.
  92. @library{wxbase}
  93. @category{streams}
  94. @see wxBufferedOutputStream, wxFileInputStream, wxFFileOutputStream, wxFFileInputStream
  95. */
  96. class wxFileOutputStream : public wxOutputStream
  97. {
  98. public:
  99. /**
  100. Creates a new file with @a ofileName name and initializes the stream in write-only mode.
  101. @warning
  102. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  103. */
  104. wxFileOutputStream(const wxString& ofileName);
  105. /**
  106. Initializes a file stream in write-only mode using the file I/O object file.
  107. */
  108. wxFileOutputStream(wxFile& file);
  109. /**
  110. Initializes a file stream in write-only mode using the file descriptor @e fd.
  111. */
  112. wxFileOutputStream(int fd);
  113. /**
  114. Destructor.
  115. */
  116. virtual ~wxFileOutputStream();
  117. /**
  118. Returns @true if the stream is initialized and ready.
  119. */
  120. bool IsOk() const;
  121. /**
  122. Returns the underlying file object.
  123. @since 2.9.5
  124. */
  125. wxFile* GetFile() const;
  126. };
  127. /**
  128. @class wxFileInputStream
  129. This class represents data read in from a file.
  130. There are actually two such groups of classes: this one is based on wxFile
  131. whereas wxFFileInputStream is based in the wxFFile class.
  132. Note that wxInputStream::SeekI() can seek beyond the end of the stream (file)
  133. and will thus not return ::wxInvalidOffset for that.
  134. @library{wxbase}
  135. @category{streams}
  136. @see wxBufferedInputStream, wxFileOutputStream, wxFFileOutputStream
  137. */
  138. class wxFileInputStream : public wxInputStream
  139. {
  140. public:
  141. /**
  142. Opens the specified file using its @a ifileName name in read-only mode.
  143. @warning
  144. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  145. */
  146. wxFileInputStream(const wxString& ifileName);
  147. /**
  148. Initializes a file stream in read-only mode using the file I/O object file.
  149. */
  150. wxFileInputStream(wxFile& file);
  151. /**
  152. Initializes a file stream in read-only mode using the specified file descriptor.
  153. */
  154. wxFileInputStream(int fd);
  155. /**
  156. Destructor.
  157. */
  158. virtual ~wxFileInputStream();
  159. /**
  160. Returns @true if the stream is initialized and ready.
  161. */
  162. bool IsOk() const;
  163. /**
  164. Returns the underlying file object.
  165. @since 2.9.5
  166. */
  167. wxFile* GetFile() const;
  168. };
  169. /**
  170. @class wxFFileInputStream
  171. This class represents data read in from a file.
  172. There are actually two such groups of classes: this one is based on wxFFile
  173. whereas wxFileInputStream is based in the wxFile class.
  174. Note that wxInputStream::SeekI() can seek beyond the end of the stream (file)
  175. and will thus not return ::wxInvalidOffset for that.
  176. @library{wxbase}
  177. @category{streams}
  178. @see wxBufferedInputStream, wxFFileOutputStream, wxFileOutputStream
  179. */
  180. class wxFFileInputStream : public wxInputStream
  181. {
  182. public:
  183. /**
  184. Opens the specified file using its @a filename name using the specified @a mode.
  185. @warning
  186. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  187. */
  188. wxFFileInputStream(const wxString& filename,
  189. const wxString& mode = "rb");
  190. /**
  191. Initializes a file stream in read-only mode using the file I/O object file.
  192. */
  193. wxFFileInputStream(wxFFile& file);
  194. /**
  195. Initializes a file stream in read-only mode using the specified file pointer @a fp.
  196. */
  197. wxFFileInputStream(FILE* fp);
  198. /**
  199. Destructor.
  200. */
  201. virtual ~wxFFileInputStream();
  202. /**
  203. Returns @true if the stream is initialized and ready.
  204. */
  205. bool IsOk() const;
  206. /**
  207. Returns the underlying file object.
  208. @since 2.9.5
  209. */
  210. wxFFile* GetFile() const;
  211. };
  212. /**
  213. @class wxFFileStream
  214. This stream allows to both read from and write to a file using buffered
  215. STDIO functions.
  216. @library{wxbase}
  217. @category{streams}
  218. @see wxFFileInputStream, wxFFileOutputStream, wxFileStream
  219. */
  220. class wxFFileStream : public wxFFileInputStream,
  221. public wxFFileOutputStream
  222. {
  223. public:
  224. /**
  225. Initializes a new file stream in the given @a mode using the specified
  226. @a iofileName name.
  227. @warning
  228. You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
  229. */
  230. wxFFileStream(const wxString& iofileName, const wxString& mode = "w+b");
  231. /**
  232. Returns @true if the stream is initialized and ready.
  233. This method returns @true if the stream can be both read from and
  234. written to.
  235. */
  236. bool IsOk() const;
  237. };
  238. /**
  239. @class wxFileStream
  240. This class represents data that can be both read from and written to a file.
  241. There are actually two such groups of classes: this one is based on wxFile
  242. whereas wxFFileStream is based in the wxFFile class.
  243. @library{wxbase}
  244. @category{streams}
  245. @see wxFileInputStream, wxFileOutputStream, wxFFileStream
  246. */
  247. class wxFileStream : public wxFileOutputStream,
  248. public wxFileInputStream
  249. {
  250. public:
  251. /**
  252. Initializes a new file stream in read-write mode using the specified
  253. @a iofileName name.
  254. @warning
  255. You should use IsOk() to verify if the constructor succeeded.
  256. */
  257. wxFileStream(const wxString& iofileName);
  258. /**
  259. Returns @true if the stream is initialized and ready.
  260. This method returns @true if the stream can be both read from and
  261. written to.
  262. */
  263. bool IsOk() const;
  264. };