1999-07-07 17:45:35 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-04-14 17:01:16 +00:00
|
|
|
// Name: wx/txtstrm.h
|
1999-07-07 17:45:35 +00:00
|
|
|
// Purpose: Text stream classes
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 28/06/1998
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
2004-09-23 18:20:56 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-07-07 17:45:35 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_TXTSTREAM_H_
|
|
|
|
#define _WX_TXTSTREAM_H_
|
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/stream.h"
|
2006-04-05 14:37:47 +00:00
|
|
|
#include "wx/convauto.h"
|
1999-07-07 17:45:35 +00:00
|
|
|
|
|
|
|
#if wxUSE_STREAMS
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxTextInputStream;
|
|
|
|
class WXDLLIMPEXP_FWD_BASE wxTextOutputStream;
|
1999-08-22 16:12:48 +00:00
|
|
|
|
|
|
|
typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&);
|
|
|
|
typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&);
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream );
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
|
2003-07-09 22:55:57 +00:00
|
|
|
#define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream)
|
|
|
|
|
|
|
|
// If you're scanning through a file using wxTextInputStream, you should check for EOF _before_
|
2004-09-23 18:20:56 +00:00
|
|
|
// reading the next item (word / number), because otherwise the last item may get lost.
|
2003-07-09 22:55:57 +00:00
|
|
|
// You should however be prepared to receive an empty item (empty string / zero number) at the
|
|
|
|
// end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
|
|
|
|
// with whitespace (i.e. usually a newline).
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxTextInputStream
|
1999-12-20 16:15:32 +00:00
|
|
|
{
|
1999-07-07 17:45:35 +00:00
|
|
|
public:
|
2002-12-04 14:11:26 +00:00
|
|
|
#if wxUSE_UNICODE
|
2006-04-05 14:37:47 +00:00
|
|
|
wxTextInputStream(wxInputStream& s,
|
|
|
|
const wxString &sep=wxT(" \t"),
|
|
|
|
const wxMBConv& conv = wxConvAuto());
|
2002-12-04 14:11:26 +00:00
|
|
|
#else
|
2006-04-05 14:37:47 +00:00
|
|
|
wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"));
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
1999-12-20 16:15:32 +00:00
|
|
|
~wxTextInputStream();
|
|
|
|
|
2003-07-09 22:55:57 +00:00
|
|
|
wxUint32 Read32(int base = 10); // base may be between 2 and 36, inclusive, or the special 0 (= C format)
|
|
|
|
wxUint16 Read16(int base = 10);
|
|
|
|
wxUint8 Read8(int base = 10);
|
|
|
|
wxInt32 Read32S(int base = 10);
|
|
|
|
wxInt16 Read16S(int base = 10);
|
|
|
|
wxInt8 Read8S(int base = 10);
|
1999-12-20 16:15:32 +00:00
|
|
|
double ReadDouble();
|
|
|
|
wxString ReadLine();
|
|
|
|
wxString ReadWord();
|
2004-10-05 15:38:40 +00:00
|
|
|
wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); }
|
1999-12-20 16:15:32 +00:00
|
|
|
|
|
|
|
wxString GetStringSeparators() const { return m_separators; }
|
|
|
|
void SetStringSeparators(const wxString &c) { m_separators = c; }
|
|
|
|
|
|
|
|
// Operators
|
|
|
|
wxTextInputStream& operator>>(wxString& word);
|
2000-07-15 19:51:35 +00:00
|
|
|
wxTextInputStream& operator>>(char& c);
|
2004-10-20 22:50:03 +00:00
|
|
|
#if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
|
|
|
|
wxTextInputStream& operator>>(wchar_t& wc);
|
|
|
|
#endif // wxUSE_UNICODE
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextInputStream& operator>>(wxInt16& i);
|
|
|
|
wxTextInputStream& operator>>(wxInt32& i);
|
|
|
|
wxTextInputStream& operator>>(wxUint16& i);
|
|
|
|
wxTextInputStream& operator>>(wxUint32& i);
|
|
|
|
wxTextInputStream& operator>>(double& i);
|
|
|
|
wxTextInputStream& operator>>(float& f);
|
1999-12-22 18:40:24 +00:00
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); }
|
1999-12-22 18:40:24 +00:00
|
|
|
|
2006-04-14 17:01:16 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6
|
|
|
|
wxDEPRECATED( wxString ReadString() ); // use ReadLine or ReadWord instead
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_6
|
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
protected:
|
|
|
|
wxInputStream &m_input;
|
|
|
|
wxString m_separators;
|
2003-07-09 22:55:57 +00:00
|
|
|
char m_lastBytes[10]; // stores the bytes that were read for the last character
|
2004-09-23 18:20:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#if wxUSE_UNICODE
|
2006-04-05 16:10:08 +00:00
|
|
|
wxMBConv *m_conv;
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
1999-10-29 11:18:46 +00:00
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
bool EatEOL(const wxChar &c);
|
2003-07-09 22:55:57 +00:00
|
|
|
void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
|
|
|
|
// returns EOT (\4) if there is a stream error, or end of file
|
|
|
|
wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues
|
1999-12-20 16:15:32 +00:00
|
|
|
wxChar NextNonSeparators();
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxTextInputStream);
|
1999-07-07 17:45:35 +00:00
|
|
|
};
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
1999-12-20 16:15:32 +00:00
|
|
|
wxEOL_NATIVE,
|
|
|
|
wxEOL_UNIX,
|
|
|
|
wxEOL_MAC,
|
1999-12-22 18:40:24 +00:00
|
|
|
wxEOL_DOS
|
1999-12-20 16:15:32 +00:00
|
|
|
} wxEOL;
|
1999-07-07 17:45:35 +00:00
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxTextOutputStream
|
1999-12-20 16:15:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2002-12-04 14:11:26 +00:00
|
|
|
#if wxUSE_UNICODE
|
2006-04-05 14:37:47 +00:00
|
|
|
wxTextOutputStream(wxOutputStream& s,
|
|
|
|
wxEOL mode = wxEOL_NATIVE,
|
|
|
|
const wxMBConv& conv = wxConvAuto());
|
2002-12-04 14:11:26 +00:00
|
|
|
#else
|
2006-04-05 14:37:47 +00:00
|
|
|
wxTextOutputStream(wxOutputStream& s, wxEOL mode = wxEOL_NATIVE);
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
1999-12-20 16:15:32 +00:00
|
|
|
virtual ~wxTextOutputStream();
|
|
|
|
|
|
|
|
void SetMode( wxEOL mode = wxEOL_NATIVE );
|
|
|
|
wxEOL GetMode() { return m_mode; }
|
|
|
|
|
|
|
|
void Write32(wxUint32 i);
|
|
|
|
void Write16(wxUint16 i);
|
|
|
|
void Write8(wxUint8 i);
|
|
|
|
virtual void WriteDouble(double d);
|
|
|
|
virtual void WriteString(const wxString& string);
|
1999-12-22 18:40:24 +00:00
|
|
|
|
2004-11-21 18:26:38 +00:00
|
|
|
wxTextOutputStream& PutChar(wxChar c);
|
|
|
|
|
2008-06-01 03:09:25 +00:00
|
|
|
void Flush();
|
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextOutputStream& operator<<(const wxString& string);
|
2000-07-15 19:51:35 +00:00
|
|
|
wxTextOutputStream& operator<<(char c);
|
2004-09-12 15:08:36 +00:00
|
|
|
#if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
|
2004-09-11 18:42:58 +00:00
|
|
|
wxTextOutputStream& operator<<(wchar_t wc);
|
2004-09-12 15:08:36 +00:00
|
|
|
#endif // wxUSE_UNICODE
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextOutputStream& operator<<(wxInt16 c);
|
|
|
|
wxTextOutputStream& operator<<(wxInt32 c);
|
|
|
|
wxTextOutputStream& operator<<(wxUint16 c);
|
|
|
|
wxTextOutputStream& operator<<(wxUint32 c);
|
|
|
|
wxTextOutputStream& operator<<(double f);
|
|
|
|
wxTextOutputStream& operator<<(float f);
|
1999-12-22 18:40:24 +00:00
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
|
1999-12-22 18:40:24 +00:00
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
protected:
|
|
|
|
wxOutputStream &m_output;
|
|
|
|
wxEOL m_mode;
|
2004-09-23 18:20:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#if wxUSE_UNICODE
|
2006-04-05 16:10:08 +00:00
|
|
|
wxMBConv *m_conv;
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxTextOutputStream);
|
1999-07-07 17:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// wxUSE_STREAMS
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_DATSTREAM_H_
|