stream.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: stream.h
  3. // Purpose: stream classes overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_stream Stream Classes Overview
  9. @tableofcontents
  10. wxWidgets provides its own set of stream classes in order to support platforms
  11. not providing standard C++ streams implementation and also to make it possible
  12. to provide binary versions of wxWidgets application not depending on any
  13. particular standard library version. The wxWidgets stream classes also provide
  14. some functionality not available in the standard library such as support for
  15. several compression formats and possibility to work with sockets or text
  16. controls (for output only in the latter case).
  17. Nevertheless wxWidgets programs can also use standard stream classes and are
  18. encouraged to do so if the above considerations don't apply. Moreover,
  19. wxStdInputStream and wxStdOutputStream classes are provided to provide a degree
  20. of interoperability between the two and make it possible to use any wxWidgets
  21. stream as a standard stream (the converse possibility to use a standard stream
  22. as a wxWidgets stream is planned for a future release).
  23. @section overview_stream_classes Stream Classes
  24. wxStream classes are divided in two main groups:
  25. @li The core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
  26. wxFilterInputStream, wxFilterOutputStream
  27. @li The "IO" classes: wxSocketInputStream, wxSocketOutputStream,
  28. wxFileInputStream, wxFileOutputStream, ...
  29. @li Classes for reading text or binary data from a particular stream
  30. such as wxTextInputStream, wxTextOutputStream, wxDataInputStream
  31. and wxDataOutputStream
  32. wxStreamBase is the base definition of a stream. It defines, for example, the
  33. API of OnSysRead(), OnSysWrite(), OnSysSeek() and OnSysTell(). These functions are
  34. really implemented by the "IO" classes.
  35. wxInputStream and wxOutputStream classes inherit from wxStreamBase and provide
  36. specialized methods for input and output.
  37. wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
  38. linked to a stream. One stream can have multiple stream buffers but one stream
  39. has always one autoinitialized stream buffer.
  40. wxInputStream is the base class for read-only streams. It implements Read(),
  41. SeekI() (I for Input), and all read or IO generic related functions.
  42. wxOutputStream does the same thing for write-only streams.
  43. wxFilterInputStream and wxFileterOutputStream are the base class definitions for
  44. stream filtering.
  45. Stream filtering means a stream which does no syscall but filters data which
  46. are passed to it and then pass them to another stream.
  47. For example, wxZLibInputStream is an inline stream decompressor.
  48. The "IO" classes implements the specific parts of the stream. This could be
  49. nothing in the case of wxMemoryInputStream and wxMemoryOutputStream which base
  50. themselves on wxStreamBuffer.
  51. This could also be a simple link to the true syscall (for example read(...), write(...)).
  52. @section overview_stream_example Example
  53. Usage is simple. We can take the example of wxFileInputStream and here is some
  54. sample code:
  55. @code
  56. ...
  57. // The constructor initializes the stream buffer and open the file descriptor
  58. // associated to the name of the file.
  59. wxFileInputStream in_stream("the_file_to_be_read");
  60. // Ok, read some bytes ... nb_datas is expressed in bytes.
  61. in_stream.Read(data, nb_datas);
  62. if (in_stream.LastError() != wxSTREAM_NOERROR) {
  63. // Oh oh, something bad happens.
  64. // For a complete list, look into the documentation at wxStreamBase.
  65. }
  66. // You can also inline all like this.
  67. if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {
  68. // Do something.
  69. }
  70. // You can also get the last number of bytes REALLY put into the buffer.
  71. size_t really_read = in_stream.LastRead();
  72. // Ok, moves to the beginning of the stream. SeekI returns the last position
  73. // in the stream counted from the beginning.
  74. off_t old_position = in_stream.SeekI(0, wxFromBeginning);
  75. // What is my current position ?
  76. off_t position = in_stream.TellI();
  77. // wxFileInputStream will close the file descriptor on destruction.
  78. @endcode
  79. */