1999-07-07 17:45:35 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: txtstrm.h
|
|
|
|
// Purpose: Text stream classes
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 28/06/1998
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-07-07 17:45:35 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_TXTSTREAM_H_
|
|
|
|
#define _WX_TXTSTREAM_H_
|
|
|
|
|
2003-08-09 12:38:21 +00:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
1999-07-07 17:45:35 +00:00
|
|
|
#pragma interface "txtstrm.h"
|
|
|
|
#endif
|
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/stream.h"
|
1999-07-07 17:45:35 +00:00
|
|
|
|
|
|
|
#if wxUSE_STREAMS
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxTextInputStream;
|
|
|
|
class WXDLLIMPEXP_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_
|
|
|
|
// reading the next item (word / number), because otherwise the last item may get lost.
|
|
|
|
// 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
|
|
|
|
wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"), wxMBConv& conv = wxConvUTF8 );
|
|
|
|
#else
|
1999-12-20 16:15:32 +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();
|
2003-07-09 22:55:57 +00:00
|
|
|
wxString ReadString(); // deprecated: use ReadLine or ReadWord instead
|
1999-12-20 16:15:32 +00:00
|
|
|
wxString ReadLine();
|
|
|
|
wxString ReadWord();
|
2003-09-26 20:15:38 +00:00
|
|
|
wxChar GetChar() { wxChar c = NextChar(); return 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);
|
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
|
|
|
|
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
|
2002-12-04 14:11:26 +00:00
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
wxMBConv &m_conv;
|
|
|
|
#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
|
|
|
|
|
|
|
DECLARE_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
|
|
|
|
wxTextOutputStream( wxOutputStream& s, wxEOL mode = wxEOL_NATIVE, wxMBConv& conv = wxConvUTF8 );
|
|
|
|
#else
|
1999-12-20 16:15:32 +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
|
|
|
|
1999-12-20 16:15:32 +00:00
|
|
|
wxTextOutputStream& operator<<(const wxChar *string);
|
|
|
|
wxTextOutputStream& operator<<(const wxString& string);
|
2000-07-15 19:51:35 +00:00
|
|
|
wxTextOutputStream& operator<<(char c);
|
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;
|
2002-12-04 14:11:26 +00:00
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
wxMBConv &m_conv;
|
|
|
|
#endif
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
DECLARE_NO_COPY_CLASS(wxTextOutputStream)
|
1999-07-07 17:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// wxUSE_STREAMS
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_DATSTREAM_H_
|