2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: txtstrm.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxTextInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxTextInputStream
|
|
|
|
@wxheader{txtstrm.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class provides functions that read text datas using an input stream.
|
|
|
|
So, you can read @e text floats, integers.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The wxTextInputStream correctly reads text files (or streams) in DOS, Macintosh
|
|
|
|
and Unix formats and reports a single newline char as a line ending.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Operator is overloaded and you can use this class like a standard C++ iostream.
|
|
|
|
Note, however, that the arguments are the fixed size types wxUint32, wxInt32 etc
|
|
|
|
and on a typical 32-bit computer, none of these match to the "long" type
|
|
|
|
(wxInt32
|
|
|
|
is defined as int on 32-bit architectures) so that you cannot use long. To avoid
|
|
|
|
problems (here and elsewhere), make use of wxInt32, wxUint32 and similar types.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If you're scanning through a file using wxTextInputStream, you should check for
|
|
|
|
EOF @b before
|
|
|
|
reading the next item (word / number), because otherwise the last item may get
|
2008-03-08 09:43:31 -05:00
|
|
|
lost.
|
2008-03-08 08:52:38 -05: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).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
For example:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
wxFileInputStream input( "mytext.txt" );
|
|
|
|
wxTextInputStream text( input );
|
|
|
|
wxUint8 i1;
|
|
|
|
float f2;
|
|
|
|
wxString line;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
text i1; // read a 8 bit integer.
|
|
|
|
text i1 f2; // read a 8 bit integer followed by float.
|
|
|
|
text line; // read a text line
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxTextInputStream::SetStringSeparators
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxTextInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
)
|
|
|
|
Constructs a text stream associated to the given input stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param stream
|
2008-03-09 08:33:59 -04:00
|
|
|
The underlying input stream.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param sep
|
2008-03-09 08:33:59 -04:00
|
|
|
The initial string separator characters.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param conv
|
2008-03-09 08:33:59 -04:00
|
|
|
In Unicode build only: The encoding converter used to convert the bytes in
|
|
|
|
the
|
|
|
|
underlying input stream to characters.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxTextInputStream(wxInputStream& stream,
|
2008-03-09 08:33:59 -04:00
|
|
|
const wxString& sep = " \t");
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destroys the wxTextInputStream object.
|
|
|
|
*/
|
|
|
|
~wxTextInputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a character, returns 0 if there are no more characters in the stream.
|
|
|
|
*/
|
|
|
|
wxChar GetChar();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a unsigned 16 bit integer from the stream.
|
|
|
|
See wxTextInputStream::Read8 for the
|
2008-03-09 08:33:59 -04:00
|
|
|
description of the @a base parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxUint16 Read16(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a signed 16 bit integer from the stream.
|
|
|
|
See wxTextInputStream::Read8 for the
|
2008-03-09 08:33:59 -04:00
|
|
|
description of the @a base parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxInt16 Read16S(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a 32 bit unsigned integer from the stream.
|
|
|
|
See wxTextInputStream::Read8 for the
|
2008-03-09 08:33:59 -04:00
|
|
|
description of the @a base parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxUint32 Read32(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a 32 bit signed integer from the stream.
|
|
|
|
See wxTextInputStream::Read8 for the
|
2008-03-09 08:33:59 -04:00
|
|
|
description of the @a base parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxInt32 Read32S(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a single unsigned byte from the stream, given in base @e base.
|
2008-03-09 08:33:59 -04:00
|
|
|
The value of @a base must be comprised between 2 and 36, inclusive, or
|
2008-03-08 08:52:38 -05:00
|
|
|
be a special value 0 which means that the usual rules of @c C numbers are
|
|
|
|
applied: if the number starts with @c 0x it is considered to be in base
|
|
|
|
16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
|
|
|
|
that you may not want to specify the base 0 if you are parsing the numbers
|
|
|
|
which may have leading zeroes as they can yield unexpected (to the user not
|
|
|
|
familiar with C) results.
|
|
|
|
*/
|
|
|
|
wxUint8 Read8(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a single signed byte from the stream.
|
|
|
|
See wxTextInputStream::Read8 for the
|
2008-03-09 08:33:59 -04:00
|
|
|
description of the @a base parameter.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxInt8 Read8S(int base = 10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a double (IEEE encoded) from the stream.
|
|
|
|
*/
|
|
|
|
double ReadDouble();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a line from the input stream and returns it (without the end of line
|
|
|
|
character).
|
|
|
|
*/
|
|
|
|
wxString ReadLine();
|
|
|
|
|
|
|
|
/**
|
2008-03-28 12:19:12 -04:00
|
|
|
@note This method is deprecated, use ReadLine()
|
2008-03-08 08:52:38 -05:00
|
|
|
or ReadWord() instead.
|
|
|
|
Same as ReadLine().
|
|
|
|
*/
|
|
|
|
wxString ReadString();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a word (a sequence of characters until the next separator) from the
|
|
|
|
input stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetStringSeparators()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxString ReadWord();
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Sets the characters which are used to define the word boundaries in
|
2008-03-08 08:52:38 -05:00
|
|
|
ReadWord().
|
|
|
|
The default separators are the space and @c TAB characters.
|
|
|
|
*/
|
|
|
|
void SetStringSeparators(const wxString& sep);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxTextOutputStream
|
|
|
|
@wxheader{txtstrm.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class provides functions that write text datas using an output stream.
|
|
|
|
So, you can write @e text floats, integers.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
You can also simulate the C++ cout class:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
wxFFileOutputStream output( stderr );
|
|
|
|
wxTextOutputStream cout( output );
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
cout "This is a text line" endl;
|
|
|
|
cout 1234;
|
|
|
|
cout 1.23456;
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The wxTextOutputStream writes text files (or streams) on DOS, Macintosh
|
|
|
|
and Unix in their native formats (concerning the line ending).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxTextOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
)
|
|
|
|
Constructs a text stream object associated to the given output stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param stream
|
2008-03-09 08:33:59 -04:00
|
|
|
The output stream.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param mode
|
2008-03-09 08:33:59 -04:00
|
|
|
The end-of-line mode. One of wxEOL_NATIVE, wxEOL_DOS, wxEOL_MAC and
|
|
|
|
wxEOL_UNIX.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param conv
|
2008-03-09 08:33:59 -04:00
|
|
|
In Unicode build only: The object used to convert
|
|
|
|
Unicode text into ASCII characters written to the output stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxTextOutputStream(wxOutputStream& stream,
|
|
|
|
wxEOL mode = wxEOL_NATIVE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destroys the wxTextOutputStream object.
|
|
|
|
*/
|
|
|
|
~wxTextOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the end-of-line mode. One of @b wxEOL_DOS, @b wxEOL_MAC and @b
|
|
|
|
wxEOL_UNIX.
|
|
|
|
*/
|
|
|
|
wxEOL GetMode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes a character to the stream.
|
|
|
|
*/
|
|
|
|
void PutChar(wxChar c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the end-of-line mode. One of @b wxEOL_NATIVE, @b wxEOL_DOS, @b wxEOL_MAC
|
|
|
|
and @b wxEOL_UNIX.
|
|
|
|
*/
|
|
|
|
void SetMode(wxEOL mode = wxEOL_NATIVE);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Writes the 16 bit integer @a i16 to the stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Write16(wxUint16 i16);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Writes the 32 bit integer @a i32 to the stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Write32(wxUint32 i32);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Writes the single byte @a i8 to the stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Write8(wxUint8 i8);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Writes the double @a f to the stream using the IEEE format.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
virtual void WriteDouble(double f);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Writes @a string as a line. Depending on the end-of-line mode the end of
|
2008-03-08 08:52:38 -05:00
|
|
|
line ('\n') characters in the string are converted to the correct
|
|
|
|
line ending terminator.
|
|
|
|
*/
|
|
|
|
virtual void WriteString(const wxString& string);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|