mstream.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/mstream.h
  3. // Purpose: Memory stream classes
  4. // Author: Guilhem Lavaux
  5. // Modified by:
  6. // Created: 11/07/98
  7. // Copyright: (c) Guilhem Lavaux
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_WXMMSTREAM_H__
  11. #define _WX_WXMMSTREAM_H__
  12. #include "wx/defs.h"
  13. #if wxUSE_STREAMS
  14. #include "wx/stream.h"
  15. class WXDLLIMPEXP_FWD_BASE wxMemoryOutputStream;
  16. class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream
  17. {
  18. public:
  19. wxMemoryInputStream(const void *data, size_t length);
  20. wxMemoryInputStream(const wxMemoryOutputStream& stream);
  21. wxMemoryInputStream(wxInputStream& stream,
  22. wxFileOffset lenFile = wxInvalidOffset)
  23. {
  24. InitFromStream(stream, lenFile);
  25. }
  26. wxMemoryInputStream(wxMemoryInputStream& stream)
  27. : wxInputStream()
  28. {
  29. InitFromStream(stream, wxInvalidOffset);
  30. }
  31. virtual ~wxMemoryInputStream();
  32. virtual wxFileOffset GetLength() const { return m_length; }
  33. virtual bool IsSeekable() const { return true; }
  34. virtual char Peek();
  35. virtual bool CanRead() const;
  36. wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
  37. #if WXWIN_COMPATIBILITY_2_6
  38. // deprecated, compatibility only
  39. wxDEPRECATED( wxStreamBuffer *InputStreamBuffer() const );
  40. #endif // WXWIN_COMPATIBILITY_2_6
  41. protected:
  42. wxStreamBuffer *m_i_streambuf;
  43. size_t OnSysRead(void *buffer, size_t nbytes);
  44. wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
  45. wxFileOffset OnSysTell() const;
  46. private:
  47. // common part of ctors taking wxInputStream
  48. void InitFromStream(wxInputStream& stream, wxFileOffset lenFile);
  49. size_t m_length;
  50. // copy ctor is implemented above: it copies the other stream in this one
  51. DECLARE_ABSTRACT_CLASS(wxMemoryInputStream)
  52. wxDECLARE_NO_ASSIGN_CLASS(wxMemoryInputStream);
  53. };
  54. class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
  55. {
  56. public:
  57. // if data is !NULL it must be allocated with malloc()
  58. wxMemoryOutputStream(void *data = NULL, size_t length = 0);
  59. virtual ~wxMemoryOutputStream();
  60. virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); }
  61. virtual bool IsSeekable() const { return true; }
  62. size_t CopyTo(void *buffer, size_t len) const;
  63. wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
  64. #if WXWIN_COMPATIBILITY_2_6
  65. // deprecated, compatibility only
  66. wxDEPRECATED( wxStreamBuffer *OutputStreamBuffer() const );
  67. #endif // WXWIN_COMPATIBILITY_2_6
  68. protected:
  69. wxStreamBuffer *m_o_streambuf;
  70. protected:
  71. size_t OnSysWrite(const void *buffer, size_t nbytes);
  72. wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
  73. wxFileOffset OnSysTell() const;
  74. DECLARE_DYNAMIC_CLASS(wxMemoryOutputStream)
  75. wxDECLARE_NO_COPY_CLASS(wxMemoryOutputStream);
  76. };
  77. #if WXWIN_COMPATIBILITY_2_6
  78. inline wxStreamBuffer *wxMemoryInputStream::InputStreamBuffer() const { return m_i_streambuf; }
  79. inline wxStreamBuffer *wxMemoryOutputStream::OutputStreamBuffer() const { return m_o_streambuf; }
  80. #endif // WXWIN_COMPATIBILITY_2_6
  81. #endif
  82. // wxUSE_STREAMS
  83. #endif
  84. // _WX_WXMMSTREAM_H__