]> git.saurik.com Git - wxWidgets.git/blame - include/wx/txtstrm.h
Line-up interfaces to use size_t for GetCount()s (and count related api).
[wxWidgets.git] / include / wx / txtstrm.h
CommitLineData
fae05df5
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: txtstrm.h
3// Purpose: Text stream classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 28/06/1998
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
cb719f2e 9// Licence: wxWindows licence
fae05df5
GL
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_TXTSTREAM_H_
13#define _WX_TXTSTREAM_H_
14
ed58dbea 15#include "wx/stream.h"
fae05df5
GL
16
17#if wxUSE_STREAMS
18
bddd7a8d
VZ
19class WXDLLIMPEXP_BASE wxTextInputStream;
20class WXDLLIMPEXP_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
VZ
38#if wxUSE_UNICODE
39 wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"), wxMBConv& conv = wxConvUTF8 );
40#else
c7a9fa36 41 wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t") );
2b5f62a0 42#endif
c7a9fa36
RR
43 ~wxTextInputStream();
44
2348a842
VZ
45 wxUint32 Read32(int base = 10); // base may be between 2 and 36, inclusive, or the special 0 (= C format)
46 wxUint16 Read16(int base = 10);
47 wxUint8 Read8(int base = 10);
48 wxInt32 Read32S(int base = 10);
49 wxInt16 Read16S(int base = 10);
50 wxInt8 Read8S(int base = 10);
c7a9fa36 51 double ReadDouble();
2348a842 52 wxString ReadString(); // deprecated: use ReadLine or ReadWord instead
c7a9fa36
RR
53 wxString ReadLine();
54 wxString ReadWord();
254a2129 55 wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); }
c7a9fa36
RR
56
57 wxString GetStringSeparators() const { return m_separators; }
58 void SetStringSeparators(const wxString &c) { m_separators = c; }
59
60 // Operators
61 wxTextInputStream& operator>>(wxString& word);
f6bcfd97 62 wxTextInputStream& operator>>(char& c);
fdd99f15
VZ
63#if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
64 wxTextInputStream& operator>>(wchar_t& wc);
65#endif // wxUSE_UNICODE
c7a9fa36
RR
66 wxTextInputStream& operator>>(wxInt16& i);
67 wxTextInputStream& operator>>(wxInt32& i);
68 wxTextInputStream& operator>>(wxUint16& i);
69 wxTextInputStream& operator>>(wxUint32& i);
70 wxTextInputStream& operator>>(double& i);
71 wxTextInputStream& operator>>(float& f);
28f5bdb4 72
c7a9fa36 73 wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); }
28f5bdb4 74
c7a9fa36
RR
75protected:
76 wxInputStream &m_input;
77 wxString m_separators;
2348a842 78 char m_lastBytes[10]; // stores the bytes that were read for the last character
cb719f2e 79
2b5f62a0
VZ
80#if wxUSE_UNICODE
81 wxMBConv &m_conv;
82#endif
191549ed 83
c7a9fa36 84 bool EatEOL(const wxChar &c);
2348a842
VZ
85 void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
86 // returns EOT (\4) if there is a stream error, or end of file
87 wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues
c7a9fa36 88 wxChar NextNonSeparators();
fc7a2a60
VZ
89
90 DECLARE_NO_COPY_CLASS(wxTextInputStream)
fae05df5
GL
91};
92
2b5f62a0
VZ
93typedef enum
94{
c7a9fa36
RR
95 wxEOL_NATIVE,
96 wxEOL_UNIX,
97 wxEOL_MAC,
28f5bdb4 98 wxEOL_DOS
c7a9fa36 99} wxEOL;
fae05df5 100
bddd7a8d 101class WXDLLIMPEXP_BASE wxTextOutputStream
c7a9fa36
RR
102{
103public:
2b5f62a0
VZ
104#if wxUSE_UNICODE
105 wxTextOutputStream( wxOutputStream& s, wxEOL mode = wxEOL_NATIVE, wxMBConv& conv = wxConvUTF8 );
106#else
c7a9fa36 107 wxTextOutputStream( wxOutputStream& s, wxEOL mode = wxEOL_NATIVE );
2b5f62a0 108#endif
c7a9fa36
RR
109 virtual ~wxTextOutputStream();
110
111 void SetMode( wxEOL mode = wxEOL_NATIVE );
112 wxEOL GetMode() { return m_mode; }
113
114 void Write32(wxUint32 i);
115 void Write16(wxUint16 i);
116 void Write8(wxUint8 i);
117 virtual void WriteDouble(double d);
118 virtual void WriteString(const wxString& string);
28f5bdb4 119
ba854691
RN
120 wxTextOutputStream& PutChar(wxChar c);
121
c7a9fa36
RR
122 wxTextOutputStream& operator<<(const wxChar *string);
123 wxTextOutputStream& operator<<(const wxString& string);
f6bcfd97 124 wxTextOutputStream& operator<<(char c);
e4940feb 125#if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
3ca1bf5a 126 wxTextOutputStream& operator<<(wchar_t wc);
e4940feb 127#endif // wxUSE_UNICODE
c7a9fa36
RR
128 wxTextOutputStream& operator<<(wxInt16 c);
129 wxTextOutputStream& operator<<(wxInt32 c);
130 wxTextOutputStream& operator<<(wxUint16 c);
131 wxTextOutputStream& operator<<(wxUint32 c);
132 wxTextOutputStream& operator<<(double f);
133 wxTextOutputStream& operator<<(float f);
28f5bdb4 134
c7a9fa36 135 wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
28f5bdb4 136
c7a9fa36
RR
137protected:
138 wxOutputStream &m_output;
139 wxEOL m_mode;
cb719f2e 140
2b5f62a0
VZ
141#if wxUSE_UNICODE
142 wxMBConv &m_conv;
143#endif
144
fc7a2a60 145 DECLARE_NO_COPY_CLASS(wxTextOutputStream)
fae05df5
GL
146};
147
148#endif
149 // wxUSE_STREAMS
150
151#endif
152 // _WX_DATSTREAM_H_