txtstrm.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/txtstrm.h
  3. // Purpose: Text stream classes
  4. // Author: Guilhem Lavaux
  5. // Modified by:
  6. // Created: 28/06/1998
  7. // Copyright: (c) Guilhem Lavaux
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_TXTSTREAM_H_
  11. #define _WX_TXTSTREAM_H_
  12. #include "wx/stream.h"
  13. #include "wx/convauto.h"
  14. #if wxUSE_STREAMS
  15. class WXDLLIMPEXP_FWD_BASE wxTextInputStream;
  16. class WXDLLIMPEXP_FWD_BASE wxTextOutputStream;
  17. typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&);
  18. typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&);
  19. WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream );
  20. #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream)
  21. // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_
  22. // reading the next item (word / number), because otherwise the last item may get lost.
  23. // You should however be prepared to receive an empty item (empty string / zero number) at the
  24. // end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
  25. // with whitespace (i.e. usually a newline).
  26. class WXDLLIMPEXP_BASE wxTextInputStream
  27. {
  28. public:
  29. #if wxUSE_UNICODE
  30. wxTextInputStream(wxInputStream& s,
  31. const wxString &sep=wxT(" \t"),
  32. const wxMBConv& conv = wxConvAuto());
  33. #else
  34. wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"));
  35. #endif
  36. ~wxTextInputStream();
  37. const wxInputStream& GetInputStream() const { return m_input; }
  38. wxUint32 Read32(int base = 10); // base may be between 2 and 36, inclusive, or the special 0 (= C format)
  39. wxUint16 Read16(int base = 10);
  40. wxUint8 Read8(int base = 10);
  41. wxInt32 Read32S(int base = 10);
  42. wxInt16 Read16S(int base = 10);
  43. wxInt8 Read8S(int base = 10);
  44. double ReadDouble();
  45. wxString ReadLine();
  46. wxString ReadWord();
  47. wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); }
  48. wxString GetStringSeparators() const { return m_separators; }
  49. void SetStringSeparators(const wxString &c) { m_separators = c; }
  50. // Operators
  51. wxTextInputStream& operator>>(wxString& word);
  52. wxTextInputStream& operator>>(char& c);
  53. #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
  54. wxTextInputStream& operator>>(wchar_t& wc);
  55. #endif // wxUSE_UNICODE
  56. wxTextInputStream& operator>>(wxInt16& i);
  57. wxTextInputStream& operator>>(wxInt32& i);
  58. wxTextInputStream& operator>>(wxUint16& i);
  59. wxTextInputStream& operator>>(wxUint32& i);
  60. wxTextInputStream& operator>>(double& i);
  61. wxTextInputStream& operator>>(float& f);
  62. wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); }
  63. #if WXWIN_COMPATIBILITY_2_6
  64. wxDEPRECATED( wxString ReadString() ); // use ReadLine or ReadWord instead
  65. #endif // WXWIN_COMPATIBILITY_2_6
  66. protected:
  67. wxInputStream &m_input;
  68. wxString m_separators;
  69. char m_lastBytes[10]; // stores the bytes that were read for the last character
  70. #if wxUSE_UNICODE
  71. wxMBConv *m_conv;
  72. #endif
  73. bool EatEOL(const wxChar &c);
  74. void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
  75. // returns EOT (\4) if there is a stream error, or end of file
  76. wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues
  77. wxChar NextNonSeparators();
  78. wxDECLARE_NO_COPY_CLASS(wxTextInputStream);
  79. };
  80. typedef enum
  81. {
  82. wxEOL_NATIVE,
  83. wxEOL_UNIX,
  84. wxEOL_MAC,
  85. wxEOL_DOS
  86. } wxEOL;
  87. class WXDLLIMPEXP_BASE wxTextOutputStream
  88. {
  89. public:
  90. #if wxUSE_UNICODE
  91. wxTextOutputStream(wxOutputStream& s,
  92. wxEOL mode = wxEOL_NATIVE,
  93. const wxMBConv& conv = wxConvAuto());
  94. #else
  95. wxTextOutputStream(wxOutputStream& s, wxEOL mode = wxEOL_NATIVE);
  96. #endif
  97. virtual ~wxTextOutputStream();
  98. const wxOutputStream& GetOutputStream() const { return m_output; }
  99. void SetMode( wxEOL mode = wxEOL_NATIVE );
  100. wxEOL GetMode() { return m_mode; }
  101. void Write32(wxUint32 i);
  102. void Write16(wxUint16 i);
  103. void Write8(wxUint8 i);
  104. virtual void WriteDouble(double d);
  105. virtual void WriteString(const wxString& string);
  106. wxTextOutputStream& PutChar(wxChar c);
  107. void Flush();
  108. wxTextOutputStream& operator<<(const wxString& string);
  109. wxTextOutputStream& operator<<(char c);
  110. #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
  111. wxTextOutputStream& operator<<(wchar_t wc);
  112. #endif // wxUSE_UNICODE
  113. wxTextOutputStream& operator<<(wxInt16 c);
  114. wxTextOutputStream& operator<<(wxInt32 c);
  115. wxTextOutputStream& operator<<(wxUint16 c);
  116. wxTextOutputStream& operator<<(wxUint32 c);
  117. wxTextOutputStream& operator<<(double f);
  118. wxTextOutputStream& operator<<(float f);
  119. wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
  120. protected:
  121. wxOutputStream &m_output;
  122. wxEOL m_mode;
  123. #if wxUSE_UNICODE
  124. wxMBConv *m_conv;
  125. #endif
  126. wxDECLARE_NO_COPY_CLASS(wxTextOutputStream);
  127. };
  128. #endif
  129. // wxUSE_STREAMS
  130. #endif
  131. // _WX_DATSTREAM_H_