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