]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/datstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDataInputStream and wxDataOutputStream
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxDataOutputStream
12 This class provides functions that write binary data types in a portable
13 way. Data can be written in either big-endian or little-endian format,
14 little-endian being the default on all architectures.
16 If you want to write data to text files (or streams) use wxTextOutputStream
19 The "<<" operator is overloaded and you can use this class like a standard
20 C++ iostream. See wxDataInputStream for its usage and caveats.
25 @see wxDataInputStream
27 class wxDataOutputStream
31 Constructs a datastream object from an output stream. Only write
32 methods will be available.
37 wxDataOutputStream(wxOutputStream
& s
,
38 const wxMBConv
& conv
= wxConvAuto(wxFONTENCODING_DEFAULT
));
40 Constructs a datastream object from an output stream. Only write
41 methods will be available. This constructor is only available in
42 Unicode builds of wxWidgets.
47 Charset conversion object object used to encoding Unicode strings
48 before writing them to the stream in Unicode mode (see
49 WriteString() for a detailed description). Note that you must not
50 destroy @a conv before you destroy this wxDataOutputStream
51 instance! It is recommended to use the default value (UTF-8).
53 wxDataOutputStream(wxOutputStream
& stream
,
54 const wxMBConv
& conv
= wxConvAuto());
57 Destroys the wxDataOutputStream object.
59 ~wxDataOutputStream();
62 If @a be_order is @true, all data will be written in big-endian order,
63 e.g. for reading on a Sparc or from Java-Streams (which always use
64 big-endian order), otherwise data will be written in little-endian
67 void BigEndianOrdered(bool be_order
);
70 Writes the single byte @a i8 to the stream.
72 void Write8(wxUint8 i8
);
74 Writes an array of bytes to the stream. The amount of bytes to write is
75 specified with the @a size variable.
77 void Write8(const wxUint8
* buffer
, size_t size
);
80 Writes the 16 bit unsigned integer @a i16 to the stream.
82 void Write16(wxUint16 i16
);
84 Writes an array of 16 bit unsigned integer to the stream. The amount of
85 16 bit unsigned integer to write is specified with the @a size variable.
87 void Write16(const wxUint16
* buffer
, size_t size
);
90 Writes the 32 bit unsigned integer @a i32 to the stream.
92 void Write32(wxUint32 i32
);
94 Writes an array of 32 bit unsigned integer to the stream. The amount of
95 32 bit unsigned integer to write is specified with the @a size variable.
97 void Write32(const wxUint32
* buffer
, size_t size
);
100 Writes the 64 bit unsigned integer @a i64 to the stream.
102 void Write64(wxUint64 i64
);
104 Writes an array of 64 bit unsigned integer to the stream. The amount of
105 64 bit unsigned integer to write is specified with the @a size variable.
107 void Write64(const wxUint64
* buffer
, size_t size
);
110 Writes the double @a f to the stream using the IEEE format.
112 void WriteDouble(double f
);
114 Writes an array of double to the stream. The amount of double to write is
115 specified with the @a size variable.
117 void WriteDouble(const double* buffer
, size_t size
);
120 Writes @a string to the stream. Actually, this method writes the size
121 of the string before writing @a string itself.
123 In ANSI build of wxWidgets, the string is written to the stream in
124 exactly same way it is represented in memory. In Unicode build,
125 however, the string is first converted to multibyte representation with
126 @e conv object passed to stream's constructor (consequently, ANSI
127 applications can read data written by Unicode application, as long as
128 they agree on encoding) and this representation is written to the
129 stream. UTF-8 is used by default.
131 void WriteString(const wxString
& string
);
137 @class wxDataInputStream
139 This class provides functions that read binary data types in a portable
140 way. Data can be read in either big-endian or little-endian format,
141 little-endian being the default on all architectures.
143 If you want to read data from text files (or streams) use wxTextInputStream
146 The ">>" operator is overloaded and you can use this class like a standard
147 C++ iostream. Note, however, that the arguments are the fixed size types
148 wxUint32, wxInt32 etc and on a typical 32-bit computer, none of these match
149 to the "long" type (wxInt32 is defined as signed int on 32-bit
150 architectures) so that you cannot use long. To avoid problems (here and
151 elsewhere), make use of the wxInt32, wxUint32, etc types.
156 wxFileInputStream input( "mytext.dat" );
157 wxDataInputStream store( input );
162 store >> i1; // read a 8 bit integer.
163 store >> i1 >> f2; // read a 8 bit integer followed by float.
164 store >> line; // read a text line
170 @see wxDataOutputStream
172 class wxDataInputStream
176 Constructs a datastream object from an input stream. Only read methods
182 wxDataInputStream(wxInputStream
& s
,
183 const wxMBConv
& conv
= wxConvAuto(wxFONTENCODING_DEFAULT
));
185 Constructs a datastream object from an input stream. Only read methods
186 will be available. This constructor is only available in Unicode builds
192 Charset conversion object object used to decode strings in Unicode
193 mode (see ReadString() for a detailed description). Note that you
194 must not destroy @a conv before you destroy this wxDataInputStream
197 wxDataInputStream(wxInputStream
& stream
,
198 const wxMBConv
& conv
= wxConvAuto());
201 Destroys the wxDataInputStream object.
203 ~wxDataInputStream();
206 If @a be_order is @true, all data will be read in big-endian order,
207 such as written by programs on a big endian architecture (e.g. Sparc)
208 or written by Java-Streams (which always use big-endian order).
210 void BigEndianOrdered(bool be_order
);
213 Reads a single byte from the stream.
217 Reads bytes from the stream in a specified buffer. The amount of bytes
218 to read is specified by the @a size variable.
220 void Read8(wxUint8
* buffer
, size_t size
);
223 Reads a 16 bit unsigned integer from the stream.
227 Reads 16 bit unsigned integers from the stream in a specified buffer.
228 The amount of 16 bit unsigned integers to read is specified by the
231 void Read16(wxUint16
* buffer
, size_t size
);
234 Reads a 32 bit unsigned integer from the stream.
238 Reads 32 bit unsigned integers from the stream in a specified buffer.
239 The amount of 32 bit unsigned integers to read is specified by the
242 void Read32(wxUint32
* buffer
, size_t size
);
245 Reads a 64 bit unsigned integer from the stream.
249 Reads 64 bit unsigned integers from the stream in a specified buffer.
250 The amount of 64 bit unsigned integers to read is specified by the
253 void Read64(wxUint64
* buffer
, size_t size
);
256 Reads a double (IEEE encoded) from the stream.
260 Reads double data (IEEE encoded) from the stream in a specified buffer.
261 The amount of doubles to read is specified by the @a size variable.
263 void ReadDouble(double* buffer
, size_t size
);
266 Reads a string from a stream. Actually, this function first reads a
267 long integer specifying the length of the string (without the last null
268 character) and then reads the string.
270 In Unicode build of wxWidgets, the fuction first reads multibyte
271 (char*) string from the stream and then converts it to Unicode using
272 the @e conv object passed to constructor and returns the result as
273 wxString. You are responsible for using the same convertor as when
276 @see wxDataOutputStream::WriteString()
278 wxString
ReadString();