]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stream.h | |
c977fa84 | 3 | // Purpose: interface of wxStreamBase and its derived classes |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxCountingOutputStream | |
7c913512 | 11 | |
23324ae1 | 12 | wxCountingOutputStream is a specialized output stream which does not write any |
c977fa84 FM |
13 | data anywhere, instead it counts how many bytes would get written if this were a |
14 | normal stream. This can sometimes be useful or required if some data gets | |
15 | serialized to a stream or compressed by using stream compression and thus the | |
16 | final size of the stream cannot be known other than pretending to write the stream. | |
17 | One case where the resulting size would have to be known is if the data has | |
18 | to be written to a piece of memory and the memory has to be allocated before | |
19 | writing to it (which is probably always the case when writing to a memory stream). | |
7c913512 | 20 | |
23324ae1 FM |
21 | @library{wxbase} |
22 | @category{streams} | |
23 | */ | |
24 | class wxCountingOutputStream : public wxOutputStream | |
25 | { | |
26 | public: | |
27 | /** | |
28 | Creates a wxCountingOutputStream object. | |
29 | */ | |
30 | wxCountingOutputStream(); | |
31 | ||
32 | /** | |
33 | Destructor. | |
34 | */ | |
adaaa686 | 35 | virtual ~wxCountingOutputStream(); |
23324ae1 FM |
36 | |
37 | /** | |
38 | Returns the current size of the stream. | |
39 | */ | |
328f5751 | 40 | size_t GetSize() const; |
23324ae1 FM |
41 | }; |
42 | ||
43 | ||
e54c96f1 | 44 | |
23324ae1 FM |
45 | /** |
46 | @class wxBufferedInputStream | |
7c913512 | 47 | |
23324ae1 | 48 | This stream acts as a cache. It caches the bytes read from the specified |
c977fa84 | 49 | input stream (see wxFilterInputStream). |
23324ae1 FM |
50 | It uses wxStreamBuffer and sets the default in-buffer size to 1024 bytes. |
51 | This class may not be used without some other stream to read the data | |
52 | from (such as a file stream or a memory stream). | |
7c913512 | 53 | |
23324ae1 FM |
54 | @library{wxbase} |
55 | @category{streams} | |
7c913512 | 56 | |
e54c96f1 | 57 | @see wxStreamBuffer, wxInputStream, wxBufferedOutputStream |
23324ae1 FM |
58 | */ |
59 | class wxBufferedInputStream : public wxFilterInputStream | |
60 | { | |
61 | public: | |
c977fa84 FM |
62 | /** |
63 | Constructor. | |
64 | If a non @NULL buffer is given to the stream, it will be deleted by it. | |
65 | */ | |
66 | wxBufferedInputStream(wxInputStream& stream, | |
67 | wxStreamBuffer *buffer = NULL); | |
7c913512 | 68 | |
c977fa84 FM |
69 | /** |
70 | Destructor. | |
71 | */ | |
72 | virtual ~wxBufferedInputStream(); | |
23324ae1 FM |
73 | }; |
74 | ||
75 | ||
e54c96f1 | 76 | |
23324ae1 FM |
77 | /** |
78 | @class wxStreamBuffer | |
7c913512 | 79 | |
c977fa84 | 80 | @todo WRITE A DESCRIPTION |
7c913512 | 81 | |
23324ae1 FM |
82 | @library{wxbase} |
83 | @category{streams} | |
7c913512 | 84 | |
e54c96f1 | 85 | @see wxStreamBase |
23324ae1 | 86 | */ |
7c913512 | 87 | class wxStreamBuffer |
23324ae1 FM |
88 | { |
89 | public: | |
c977fa84 FM |
90 | |
91 | /** | |
92 | Constructor, creates a new stream buffer using @a stream as a parent stream | |
93 | and mode as the IO mode. | |
94 | ||
95 | @param stream | |
96 | The parent stream. | |
97 | @param mode | |
98 | Can be: wxStreamBuffer::read, wxStreamBuffer::write, wxStreamBuffer::read_write. | |
99 | ||
100 | One stream can have many stream buffers but only one is used internally | |
101 | to pass IO call (e.g. wxInputStream::Read() -> wxStreamBuffer::Read()), | |
102 | but you can call directly wxStreamBuffer::Read without any problems. | |
103 | Note that all errors and messages linked to the stream are stored in the | |
104 | stream, not the stream buffers: | |
105 | ||
106 | @code | |
107 | streambuffer.Read(...); | |
108 | streambuffer2.Read(...); // This call erases previous error messages set by 'streambuffer' | |
109 | @endcode | |
110 | ||
111 | @see SetBufferIO() | |
112 | */ | |
113 | wxStreamBuffer(wxStreamBase& stream, BufMode mode); | |
114 | ||
115 | /** | |
116 | Constructor; creates a new empty stream buffer which won't flush any data | |
117 | to a stream. mode specifies the type of the buffer (read, write, read_write). | |
4701dc09 | 118 | |
c977fa84 FM |
119 | This stream buffer has the advantage to be stream independent and to work |
120 | only on memory buffers but it is still compatible with the rest of the | |
121 | wxStream classes. You can write, read to this special stream and it will | |
122 | grow (if it is allowed by the user) its internal buffer. | |
123 | Briefly, it has all functionality of a "normal" stream. | |
124 | ||
125 | @warning | |
126 | The "read_write" mode doesn't currently work for standalone stream buffers. | |
127 | ||
128 | @see SetBufferIO() | |
129 | */ | |
130 | wxStreamBuffer(BufMode mode); | |
131 | ||
23324ae1 | 132 | /** |
4701dc09 FM |
133 | Constructor. |
134 | ||
135 | This method initializes the stream buffer with the data of the specified | |
23324ae1 FM |
136 | stream buffer. The new stream buffer has the same attributes, size, position |
137 | and they share the same buffer. This will cause problems if the stream to | |
138 | which the stream buffer belong is destroyed and the newly cloned stream | |
139 | buffer continues to be used, trying to call functions in the (destroyed) | |
140 | stream. It is advised to use this feature only in very local area of the | |
141 | program. | |
23324ae1 | 142 | */ |
7c913512 | 143 | wxStreamBuffer(const wxStreamBuffer& buffer); |
23324ae1 FM |
144 | |
145 | /** | |
c977fa84 FM |
146 | Destructor. |
147 | It finalizes all IO calls and frees all internal buffers if necessary. | |
23324ae1 FM |
148 | */ |
149 | wxStreamBuffer(); | |
150 | ||
151 | /** | |
152 | Fill the IO buffer. | |
153 | */ | |
154 | bool FillBuffer(); | |
155 | ||
156 | /** | |
7c913512 | 157 | Toggles the fixed flag. Usually this flag is toggled at the same time as |
23324ae1 | 158 | @e flushable. This flag allows (when it has the @false value) or forbids |
c977fa84 FM |
159 | (when it has the @true value) the stream buffer to resize dynamically the |
160 | IO buffer. | |
3c4f71cc | 161 | |
4cc4bfaf | 162 | @see SetBufferIO() |
23324ae1 FM |
163 | */ |
164 | void Fixed(bool fixed); | |
165 | ||
166 | /** | |
167 | Flushes the IO buffer. | |
168 | */ | |
169 | bool FlushBuffer(); | |
170 | ||
171 | /** | |
c977fa84 FM |
172 | Toggles the flushable flag. |
173 | If @a flushable is disabled, no data are sent to the parent stream. | |
23324ae1 FM |
174 | */ |
175 | void Flushable(bool flushable); | |
176 | ||
177 | /** | |
178 | Returns a pointer on the end of the stream buffer. | |
179 | */ | |
328f5751 | 180 | void* GetBufferEnd() const; |
23324ae1 FM |
181 | |
182 | /** | |
183 | Returns a pointer on the current position of the stream buffer. | |
184 | */ | |
328f5751 | 185 | void* GetBufferPos() const; |
23324ae1 FM |
186 | |
187 | /** | |
188 | Returns the size of the buffer. | |
189 | */ | |
328f5751 | 190 | size_t GetBufferSize() const; |
23324ae1 FM |
191 | |
192 | /** | |
193 | Returns a pointer on the start of the stream buffer. | |
194 | */ | |
328f5751 | 195 | void* GetBufferStart() const; |
23324ae1 FM |
196 | |
197 | /** | |
c977fa84 FM |
198 | Gets a single char from the stream buffer. It acts like the Read() call. |
199 | ||
200 | @warning | |
201 | You aren't directly notified if an error occurred during the IO call. | |
3c4f71cc | 202 | |
4cc4bfaf | 203 | @see Read() |
23324ae1 | 204 | */ |
adaaa686 | 205 | virtual char GetChar(); |
23324ae1 FM |
206 | |
207 | /** | |
208 | Returns the amount of available data in the buffer. | |
209 | */ | |
210 | size_t GetDataLeft(); | |
211 | ||
212 | /** | |
213 | Returns the current position (counted in bytes) in the stream buffer. | |
214 | */ | |
18e8e19b | 215 | wxFileOffset GetIntPosition() const; |
23324ae1 FM |
216 | |
217 | /** | |
218 | Returns the amount of bytes read during the last IO call to the parent stream. | |
219 | */ | |
328f5751 | 220 | size_t GetLastAccess() const; |
23324ae1 FM |
221 | |
222 | /** | |
223 | Puts a single char to the stream buffer. | |
3c4f71cc | 224 | |
c977fa84 FM |
225 | @warning |
226 | You aren't directly notified if an error occurred during the IO call. | |
227 | ||
4cc4bfaf | 228 | @see Read() |
23324ae1 | 229 | */ |
adaaa686 | 230 | virtual void PutChar(char c); |
23324ae1 | 231 | |
23324ae1 | 232 | /** |
c977fa84 FM |
233 | Reads a block of the specified size and stores the data in buffer. |
234 | This function tries to read from the buffer first and if more data has | |
235 | been requested, reads more data from the associated stream and updates | |
236 | the buffer accordingly until all requested data is read. | |
237 | ||
238 | @return It returns the size of the data read. If the returned size is | |
239 | different of the specified size, an error has occurred and | |
240 | should be tested using GetLastError(). | |
241 | */ | |
adaaa686 | 242 | virtual size_t Read(void* buffer, size_t size); |
c977fa84 FM |
243 | |
244 | /** | |
245 | Copies data to @a buffer. | |
246 | The function returns when @a buffer is full or when there isn't | |
23324ae1 | 247 | any more data in the current buffer. |
3c4f71cc | 248 | |
4cc4bfaf | 249 | @see Write() |
23324ae1 | 250 | */ |
4cc4bfaf | 251 | Return value size_t Read(wxStreamBuffer* buffer); |
23324ae1 FM |
252 | |
253 | /** | |
254 | Resets to the initial state variables concerning the buffer. | |
255 | */ | |
256 | void ResetBuffer(); | |
257 | ||
258 | /** | |
259 | Changes the current position. | |
c977fa84 | 260 | Parameter @a mode may be one of the following: |
3c4f71cc | 261 | |
c977fa84 FM |
262 | - @b wxFromStart: The position is counted from the start of the stream. |
263 | - @b wxFromCurrent: The position is counted from the current position of the stream. | |
264 | - @b wxFromEnd: The position is counted from the end of the stream. | |
3c4f71cc | 265 | |
c977fa84 FM |
266 | @return Upon successful completion, it returns the new offset as |
267 | measured in bytes from the beginning of the stream. | |
268 | Otherwise, it returns wxInvalidOffset. | |
269 | */ | |
18e8e19b | 270 | virtual wxFileOffset Seek(wxFileOffset pos, wxSeekMode mode); |
3c4f71cc | 271 | |
c977fa84 FM |
272 | /** |
273 | Specifies which pointers to use for stream buffering. | |
274 | You need to pass a pointer on the start of the buffer end and another | |
275 | on the end. The object will use this buffer to cache stream data. | |
276 | It may be used also as a source/destination buffer when you create an | |
277 | empty stream buffer (See wxStreamBuffer::wxStreamBuffer). | |
3c4f71cc | 278 | |
c977fa84 FM |
279 | @remarks |
280 | When you use this function, you will have to destroy the IO buffers | |
281 | yourself after the stream buffer is destroyed or don't use it anymore. | |
282 | In the case you use it with an empty buffer, the stream buffer will not | |
283 | resize it when it is full. | |
3c4f71cc | 284 | |
c977fa84 | 285 | @see wxStreamBuffer(), Fixed(), Flushable() |
23324ae1 | 286 | */ |
c977fa84 | 287 | void SetBufferIO(char* buffer_start, char* buffer_end); |
23324ae1 | 288 | |
23324ae1 FM |
289 | /** |
290 | Destroys or invalidates the previous IO buffer and allocates a new one of the | |
291 | specified size. | |
3c4f71cc | 292 | |
c977fa84 FM |
293 | @warning |
294 | All previous pointers aren't valid anymore. | |
23324ae1 | 295 | |
c977fa84 FM |
296 | @remarks |
297 | The created IO buffer is growable by the object. | |
23324ae1 | 298 | |
c977fa84 FM |
299 | @see Fixed(), Flushable() |
300 | */ | |
7c913512 | 301 | void SetBufferIO(size_t bufsize); |
23324ae1 FM |
302 | |
303 | /** | |
304 | Sets the current position (in bytes) in the stream buffer. | |
c977fa84 FM |
305 | |
306 | @warning | |
307 | Since it is a very low-level function, there is no check on the position: | |
308 | specifying an invalid position can induce unexpected results. | |
23324ae1 FM |
309 | */ |
310 | void SetIntPosition(size_t pos); | |
311 | ||
312 | /** | |
313 | Returns the parent stream of the stream buffer. | |
314 | */ | |
315 | wxStreamBase* Stream(); | |
316 | ||
317 | /** | |
318 | Gets the current position in the stream. This position is calculated from | |
319 | the @e real position in the stream and from the internal buffer position: so | |
320 | it gives you the position in the @e real stream counted from the start of | |
321 | the stream. | |
3c4f71cc | 322 | |
d29a9a8a | 323 | @return Returns the current position in the stream if possible, |
c977fa84 | 324 | wxInvalidOffset in the other case. |
23324ae1 | 325 | */ |
18e8e19b | 326 | virtual wxFileOffset Tell() const; |
23324ae1 FM |
327 | |
328 | /** | |
329 | Truncates the buffer to the current position. | |
c977fa84 FM |
330 | |
331 | @note Truncate() cannot be used to enlarge the buffer. This is | |
332 | usually not needed since the buffer expands automatically. | |
23324ae1 FM |
333 | */ |
334 | void Truncate(); | |
335 | ||
23324ae1 | 336 | /** |
c977fa84 FM |
337 | Writes a block of the specified size using data of buffer. |
338 | The data are cached in a buffer before being sent in one block to the stream. | |
23324ae1 | 339 | */ |
adaaa686 | 340 | virtual size_t Write(const void* buffer, size_t size); |
c977fa84 FM |
341 | |
342 | /** | |
343 | See Read(). | |
344 | */ | |
4cc4bfaf | 345 | size_t Write(wxStreamBuffer* buffer); |
23324ae1 FM |
346 | }; |
347 | ||
348 | ||
e54c96f1 | 349 | |
23324ae1 FM |
350 | /** |
351 | @class wxOutputStream | |
7c913512 | 352 | |
23324ae1 | 353 | wxOutputStream is an abstract base class which may not be used directly. |
7c913512 | 354 | |
23324ae1 FM |
355 | @library{wxbase} |
356 | @category{streams} | |
357 | */ | |
358 | class wxOutputStream : public wxStreamBase | |
359 | { | |
360 | public: | |
361 | /** | |
362 | Creates a dummy wxOutputStream object. | |
363 | */ | |
364 | wxOutputStream(); | |
365 | ||
366 | /** | |
367 | Destructor. | |
368 | */ | |
adaaa686 | 369 | virtual ~wxOutputStream(); |
23324ae1 FM |
370 | |
371 | /** | |
c977fa84 FM |
372 | Closes the stream, returning @false if an error occurs. |
373 | The stream is closed implicitly in the destructor if Close() is not | |
23324ae1 | 374 | called explicitly. |
c977fa84 | 375 | |
23324ae1 FM |
376 | If this stream wraps another stream or some other resource such |
377 | as a file, then the underlying resource is closed too if it is owned | |
378 | by this stream, or left open otherwise. | |
379 | */ | |
adaaa686 | 380 | virtual bool Close(); |
23324ae1 FM |
381 | |
382 | /** | |
c977fa84 FM |
383 | Returns the number of bytes written during the last Write(). |
384 | It may return 0 even if there is no error on the stream if it is | |
385 | only temporarily impossible to write to it. | |
23324ae1 | 386 | */ |
adaaa686 | 387 | virtual size_t LastWrite() const; |
23324ae1 FM |
388 | |
389 | /** | |
390 | Puts the specified character in the output queue and increments the | |
391 | stream position. | |
392 | */ | |
4cc4bfaf | 393 | void PutC(char c); |
23324ae1 FM |
394 | |
395 | /** | |
396 | Changes the stream current position. | |
3c4f71cc | 397 | |
7c913512 | 398 | @param pos |
4cc4bfaf | 399 | Offset to seek to. |
7c913512 | 400 | @param mode |
4cc4bfaf | 401 | One of wxFromStart, wxFromEnd, wxFromCurrent. |
3c4f71cc | 402 | |
d29a9a8a | 403 | @return The new stream position or wxInvalidOffset on error. |
23324ae1 | 404 | */ |
18e8e19b | 405 | virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
23324ae1 FM |
406 | |
407 | /** | |
408 | Returns the current stream position. | |
409 | */ | |
18e8e19b | 410 | virtual wxFileOffset TellO() const; |
23324ae1 | 411 | |
c977fa84 FM |
412 | /** |
413 | Writes up to the specified amount of bytes using the data of buffer. | |
414 | Note that not all data can always be written so you must check the number | |
415 | of bytes really written to the stream using LastWrite() when this function | |
416 | returns. | |
417 | ||
418 | In some cases (for example a write end of a pipe which is currently full) | |
419 | it is even possible that there is no errors and zero bytes have been written. | |
420 | This function returns a reference on the current object, so the user can | |
421 | test any states of the stream right away. | |
422 | */ | |
423 | wxOutputStream Write(const void* buffer, size_t size); | |
424 | ||
23324ae1 | 425 | /** |
7c913512 | 426 | Reads data from the specified input stream and stores them |
23324ae1 FM |
427 | in the current stream. The data is read until an error is raised |
428 | by one of the two streams. | |
429 | */ | |
7c913512 | 430 | wxOutputStream Write(wxInputStream& stream_in); |
23324ae1 FM |
431 | }; |
432 | ||
433 | ||
c977fa84 FM |
434 | /** |
435 | Enumeration values used by wxFilterClassFactory. | |
436 | */ | |
437 | enum wxStreamProtocolType | |
438 | { | |
439 | wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one). | |
440 | wxSTREAM_MIMETYPE, //!< MIME types the stream handles. | |
441 | wxSTREAM_ENCODING, //!< The HTTP Content-Encodings the stream handles. | |
442 | wxSTREAM_FILEEXT //!< File extensions the stream handles. | |
443 | }; | |
444 | ||
e54c96f1 | 445 | |
23324ae1 FM |
446 | /** |
447 | @class wxFilterClassFactory | |
7c913512 | 448 | |
23324ae1 FM |
449 | Allows the creation of filter streams to handle compression formats such |
450 | as gzip and bzip2. | |
7c913512 | 451 | |
23324ae1 FM |
452 | For example, given a filename you can search for a factory that will |
453 | handle it and create a stream to decompress it: | |
7c913512 | 454 | |
23324ae1 | 455 | @code |
4701dc09 | 456 | factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT); |
23324ae1 FM |
457 | if (factory) |
458 | stream = factory-NewStream(new wxFFileInputStream(filename)); | |
459 | @endcode | |
7c913512 | 460 | |
c977fa84 FM |
461 | wxFilterClassFactory::Find can also search for a factory by MIME type, |
462 | HTTP encoding or by wxFileSystem protocol. | |
463 | The available factories can be enumerated using wxFilterClassFactory::GetFirst() | |
464 | and wxFilterClassFactory::GetNext(). | |
7c913512 | 465 | |
23324ae1 | 466 | @library{wxbase} |
c977fa84 | 467 | @category{streams} |
7c913512 | 468 | |
c977fa84 FM |
469 | @see wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory, |
470 | @ref overview_archive | |
23324ae1 FM |
471 | */ |
472 | class wxFilterClassFactory : public wxObject | |
473 | { | |
474 | public: | |
475 | /** | |
476 | Returns @true if this factory can handle the given protocol, MIME type, HTTP | |
477 | encoding or file extension. | |
c977fa84 FM |
478 | |
479 | When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter | |
23324ae1 FM |
480 | can be a complete filename rather than just an extension. |
481 | */ | |
482 | bool CanHandle(const wxString& protocol, | |
328f5751 | 483 | wxStreamProtocolType type = wxSTREAM_PROTOCOL) const; |
23324ae1 FM |
484 | |
485 | /** | |
486 | A static member that finds a factory that can handle a given protocol, MIME | |
c977fa84 FM |
487 | type, HTTP encoding or file extension. Returns a pointer to the class |
488 | factory if found, or @NULL otherwise. | |
489 | It does not give away ownership of the factory. | |
490 | ||
491 | When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter | |
23324ae1 FM |
492 | can be a complete filename rather than just an extension. |
493 | */ | |
494 | static const wxFilterClassFactory* Find(const wxString& protocol, | |
495 | wxStreamProtocolType type = wxSTREAM_PROTOCOL); | |
496 | ||
497 | //@{ | |
498 | /** | |
499 | GetFirst and GetNext can be used to enumerate the available factories. | |
23324ae1 | 500 | For example, to list them: |
3c4f71cc | 501 | |
c977fa84 FM |
502 | @code |
503 | wxString list; | |
504 | const wxFilterClassFactory *factory = wxFilterClassFactory::GetFirst(); | |
505 | ||
506 | while (factory) { | |
507 | list << factory->GetProtocol() << _T("\n"); | |
508 | factory = factory->GetNext(); | |
509 | } | |
510 | @endcode | |
511 | ||
23324ae1 FM |
512 | GetFirst()/GetNext() return a pointer to a factory or @NULL if no more |
513 | are available. They do not give away ownership of the factory. | |
514 | */ | |
328f5751 FM |
515 | static const wxFilterClassFactory* GetFirst() const; |
516 | const wxFilterClassFactory* GetNext() const; | |
23324ae1 FM |
517 | //@} |
518 | ||
519 | /** | |
c977fa84 FM |
520 | Returns the wxFileSystem protocol supported by this factory. |
521 | Equivalent to @code wxString(*GetProtocols()) @endcode. | |
23324ae1 | 522 | */ |
328f5751 | 523 | wxString GetProtocol() const; |
23324ae1 FM |
524 | |
525 | /** | |
526 | Returns the protocols, MIME types, HTTP encodings or file extensions | |
c977fa84 FM |
527 | supported by this factory, as an array of null terminated strings. |
528 | It does not give away ownership of the array or strings. | |
529 | ||
23324ae1 | 530 | For example, to list the file extensions a factory supports: |
c977fa84 FM |
531 | |
532 | @code | |
533 | wxString list; | |
534 | const wxChar *const *p; | |
535 | ||
536 | for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++) | |
537 | list << *p << _T("\n"); | |
538 | @endcode | |
23324ae1 | 539 | */ |
da1ed74c | 540 | virtual const wxChar * const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const = 0; |
23324ae1 FM |
541 | |
542 | //@{ | |
543 | /** | |
544 | Create a new input or output stream to decompress or compress a given stream. | |
c977fa84 | 545 | |
23324ae1 FM |
546 | If the parent stream is passed as a pointer then the new filter stream |
547 | takes ownership of it. If it is passed by reference then it does not. | |
548 | */ | |
c977fa84 FM |
549 | wxFilterInputStream* NewStream(wxInputStream& stream) const; |
550 | wxFilterOutputStream* NewStream(wxOutputStream& stream) const; | |
551 | wxFilterInputStream* NewStream(wxInputStream* stream) const; | |
552 | wxFilterOutputStream* NewStream(wxOutputStream* stream) const; | |
23324ae1 FM |
553 | //@} |
554 | ||
555 | /** | |
4cc4bfaf | 556 | Remove the file extension of @a location if it is one of the file |
23324ae1 FM |
557 | extensions handled by this factory. |
558 | */ | |
328f5751 | 559 | wxString PopExtension(const wxString& location) const; |
23324ae1 FM |
560 | |
561 | /** | |
c977fa84 FM |
562 | Adds this class factory to the list returned by GetFirst()/GetNext(). |
563 | ||
23324ae1 | 564 | It is not necessary to do this to use the filter streams. It is usually |
7c913512 | 565 | used when implementing streams, typically the implementation will |
23324ae1 | 566 | add a static instance of its factory class. |
c977fa84 | 567 | |
23324ae1 | 568 | It can also be used to change the order of a factory already in the list, |
c977fa84 FM |
569 | bringing it to the front. This isn't a thread safe operation so can't be |
570 | done when other threads are running that will be using the list. | |
571 | ||
23324ae1 FM |
572 | The list does not take ownership of the factory. |
573 | */ | |
574 | void PushFront(); | |
575 | ||
576 | /** | |
c977fa84 FM |
577 | Removes this class factory from the list returned by GetFirst()/GetNext(). |
578 | Removing from the list isn't a thread safe operation so can't be done | |
579 | when other threads are running that will be using the list. | |
580 | ||
23324ae1 FM |
581 | The list does not own the factories, so removing a factory does not delete it. |
582 | */ | |
583 | void Remove(); | |
584 | }; | |
585 | ||
586 | ||
e54c96f1 | 587 | |
23324ae1 FM |
588 | /** |
589 | @class wxFilterOutputStream | |
7c913512 | 590 | |
c977fa84 FM |
591 | A filter stream has the capability of a normal stream but it can be placed |
592 | on top of another stream. So, for example, it can compress, encrypt the data | |
593 | which are passed to it and write them to another stream. | |
594 | ||
595 | @note | |
596 | The use of this class is exactly the same as of wxOutputStream. | |
597 | Only a constructor differs and it is documented below. | |
7c913512 | 598 | |
23324ae1 FM |
599 | @library{wxbase} |
600 | @category{streams} | |
7c913512 | 601 | |
e54c96f1 | 602 | @see wxFilterClassFactory, wxFilterInputStream |
23324ae1 FM |
603 | */ |
604 | class wxFilterOutputStream : public wxOutputStream | |
605 | { | |
606 | public: | |
607 | //@{ | |
608 | /** | |
609 | Initializes a "filter" stream. | |
c977fa84 | 610 | |
23324ae1 FM |
611 | If the parent stream is passed as a pointer then the new filter stream |
612 | takes ownership of it. If it is passed by reference then it does not. | |
613 | */ | |
614 | wxFilterOutputStream(wxOutputStream& stream); | |
7c913512 | 615 | wxFilterOutputStream(wxOutputStream* stream); |
23324ae1 FM |
616 | //@} |
617 | }; | |
618 | ||
619 | ||
e54c96f1 | 620 | |
23324ae1 FM |
621 | /** |
622 | @class wxFilterInputStream | |
7c913512 | 623 | |
23324ae1 | 624 | A filter stream has the capability of a normal stream but it can be placed on |
c977fa84 FM |
625 | top of another stream. So, for example, it can uncompress or decrypt the data which |
626 | are read from another stream and pass it to the requester. | |
627 | ||
628 | @note | |
629 | The interface of this class is the same as that of wxInputStream. | |
630 | Only a constructor differs and it is documented below. | |
7c913512 | 631 | |
23324ae1 FM |
632 | @library{wxbase} |
633 | @category{streams} | |
7c913512 | 634 | |
e54c96f1 | 635 | @see wxFilterClassFactory, wxFilterOutputStream |
23324ae1 FM |
636 | */ |
637 | class wxFilterInputStream : public wxInputStream | |
638 | { | |
639 | public: | |
640 | //@{ | |
641 | /** | |
642 | Initializes a "filter" stream. | |
c977fa84 | 643 | |
23324ae1 FM |
644 | If the parent stream is passed as a pointer then the new filter stream |
645 | takes ownership of it. If it is passed by reference then it does not. | |
646 | */ | |
647 | wxFilterInputStream(wxInputStream& stream); | |
7c913512 | 648 | wxFilterInputStream(wxInputStream* stream); |
23324ae1 FM |
649 | //@} |
650 | }; | |
651 | ||
652 | ||
e54c96f1 | 653 | |
23324ae1 FM |
654 | /** |
655 | @class wxBufferedOutputStream | |
7c913512 | 656 | |
23324ae1 | 657 | This stream acts as a cache. It caches the bytes to be written to the specified |
c977fa84 FM |
658 | output stream (See wxFilterOutputStream). The data is only written when the |
659 | cache is full, when the buffered stream is destroyed or when calling SeekO(). | |
7c913512 | 660 | |
23324ae1 FM |
661 | This class may not be used without some other stream to write the data |
662 | to (such as a file stream or a memory stream). | |
7c913512 | 663 | |
23324ae1 FM |
664 | @library{wxbase} |
665 | @category{streams} | |
7c913512 | 666 | |
e54c96f1 | 667 | @see wxStreamBuffer, wxOutputStream |
23324ae1 FM |
668 | */ |
669 | class wxBufferedOutputStream : public wxFilterOutputStream | |
670 | { | |
671 | public: | |
672 | /** | |
98ccd545 | 673 | @todo WRITE DESCRIPTION |
23324ae1 | 674 | */ |
98ccd545 FM |
675 | wxBufferedOutputStream(wxOutputStream& stream, |
676 | wxStreamBuffer *buffer = NULL); | |
23324ae1 FM |
677 | /** |
678 | Destructor. Calls Sync() and destroys the internal buffer. | |
679 | */ | |
98ccd545 | 680 | virtual ~wxBufferedOutputStream(); |
23324ae1 FM |
681 | |
682 | /** | |
683 | Calls Sync() and changes the stream position. | |
684 | */ | |
98ccd545 | 685 | virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart) |
23324ae1 FM |
686 | |
687 | /** | |
688 | Flushes the buffer and calls Sync() on the parent stream. | |
689 | */ | |
98ccd545 | 690 | virtual void Sync(); |
23324ae1 FM |
691 | }; |
692 | ||
693 | ||
e54c96f1 | 694 | |
23324ae1 FM |
695 | /** |
696 | @class wxInputStream | |
7c913512 | 697 | |
23324ae1 | 698 | wxInputStream is an abstract base class which may not be used directly. |
7c913512 | 699 | |
23324ae1 FM |
700 | @library{wxbase} |
701 | @category{streams} | |
702 | */ | |
703 | class wxInputStream : public wxStreamBase | |
704 | { | |
705 | public: | |
706 | /** | |
707 | Creates a dummy input stream. | |
708 | */ | |
709 | wxInputStream(); | |
710 | ||
711 | /** | |
712 | Destructor. | |
713 | */ | |
adaaa686 | 714 | virtual ~wxInputStream(); |
23324ae1 FM |
715 | |
716 | /** | |
717 | Returns @true if some data is available in the stream right now, so that | |
718 | calling Read() wouldn't block. | |
719 | */ | |
adaaa686 | 720 | virtual bool CanRead() const; |
23324ae1 FM |
721 | |
722 | /** | |
723 | Returns @true after an attempt has been made to read past the end of the | |
724 | stream. | |
725 | */ | |
adaaa686 | 726 | virtual bool Eof() const; |
23324ae1 FM |
727 | |
728 | /** | |
7c913512 | 729 | Returns the first character in the input queue and removes it, |
23324ae1 FM |
730 | blocking until it appears if necessary. |
731 | */ | |
4cc4bfaf | 732 | char GetC(); |
23324ae1 FM |
733 | |
734 | /** | |
735 | Returns the last number of bytes read. | |
736 | */ | |
adaaa686 | 737 | virtual size_t LastRead() const; |
23324ae1 FM |
738 | |
739 | /** | |
740 | Returns the first character in the input queue without removing it. | |
741 | */ | |
adaaa686 | 742 | virtual char Peek(); |
23324ae1 | 743 | |
c977fa84 FM |
744 | /** |
745 | Reads the specified amount of bytes and stores the data in buffer. | |
746 | ||
747 | @warning | |
748 | The buffer absolutely needs to have at least the specified size. | |
749 | ||
750 | @return This function returns a reference on the current object, so the | |
751 | user can test any states of the stream right away. | |
752 | */ | |
753 | wxInputStream Read(void* buffer, size_t size); | |
754 | ||
23324ae1 FM |
755 | /** |
756 | Reads data from the input queue and stores it in the specified output stream. | |
757 | The data is read until an error is raised by one of the two streams. | |
3c4f71cc | 758 | |
d29a9a8a | 759 | @return This function returns a reference on the current object, so the |
c977fa84 | 760 | user can test any states of the stream right away. |
23324ae1 | 761 | */ |
c977fa84 | 762 | wxInputStream& Read(wxOutputStream& stream_out); |
23324ae1 FM |
763 | |
764 | /** | |
765 | Changes the stream current position. | |
3c4f71cc | 766 | |
7c913512 | 767 | @param pos |
4cc4bfaf | 768 | Offset to seek to. |
7c913512 | 769 | @param mode |
4cc4bfaf | 770 | One of wxFromStart, wxFromEnd, wxFromCurrent. |
3c4f71cc | 771 | |
d29a9a8a | 772 | @return The new stream position or wxInvalidOffset on error. |
23324ae1 | 773 | */ |
18e8e19b | 774 | virtual wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
23324ae1 FM |
775 | |
776 | /** | |
777 | Returns the current stream position. | |
778 | */ | |
18e8e19b | 779 | virtual wxFileOffset TellI() const; |
23324ae1 | 780 | |
c977fa84 FM |
781 | /** |
782 | This function is only useful in read mode. | |
783 | It is the manager of the "Write-Back" buffer. This buffer acts like a | |
784 | temporary buffer where data which has to be read during the next read IO | |
785 | call are put. This is useful when you get a big block of data which you | |
786 | didn't want to read: you can replace them at the top of the input queue | |
787 | by this way. | |
788 | ||
789 | Be very careful about this call in connection with calling SeekI() on | |
790 | the same stream. Any call to SeekI() will invalidate any previous call | |
791 | to this method (otherwise you could SeekI() to one position, "unread" a | |
792 | few bytes there, SeekI() to another position and data would be either | |
793 | lost or corrupted). | |
794 | ||
795 | @return Returns the amount of bytes saved in the Write-Back buffer. | |
796 | */ | |
797 | size_t Ungetch(const char* buffer, size_t size); | |
798 | ||
23324ae1 FM |
799 | /** |
800 | This function acts like the previous one except that it takes only one | |
801 | character: it is sometimes shorter to use than the generic function. | |
802 | */ | |
7c913512 | 803 | Return value bool Ungetch(char c); |
23324ae1 FM |
804 | }; |
805 | ||
806 | ||
c977fa84 FM |
807 | /** |
808 | These enumeration values are returned by various functions in the context | |
809 | of wxStream classes. | |
810 | */ | |
811 | enum wxStreamError | |
812 | { | |
813 | wxSTREAM_NO_ERROR = 0, //!< No error occurred. | |
814 | wxSTREAM_EOF, //!< EOF reached in Read() or similar. | |
815 | wxSTREAM_WRITE_ERROR, //!< generic write error on the last write call. | |
816 | wxSTREAM_READ_ERROR //!< generic read error on the last read call. | |
817 | }; | |
e54c96f1 | 818 | |
23324ae1 FM |
819 | /** |
820 | @class wxStreamBase | |
7c913512 | 821 | |
c977fa84 FM |
822 | This class is the base class of most stream related classes in wxWidgets. |
823 | It must not be used directly. | |
7c913512 | 824 | |
23324ae1 FM |
825 | @library{wxbase} |
826 | @category{streams} | |
7c913512 | 827 | |
e54c96f1 | 828 | @see wxStreamBuffer |
23324ae1 | 829 | */ |
7c913512 | 830 | class wxStreamBase |
23324ae1 FM |
831 | { |
832 | public: | |
833 | /** | |
834 | Creates a dummy stream object. It doesn't do anything. | |
835 | */ | |
836 | wxStreamBase(); | |
837 | ||
838 | /** | |
839 | Destructor. | |
840 | */ | |
adaaa686 | 841 | virtual ~wxStreamBase(); |
23324ae1 FM |
842 | |
843 | /** | |
844 | This function returns the last error. | |
23324ae1 | 845 | */ |
328f5751 | 846 | wxStreamError GetLastError() const; |
23324ae1 FM |
847 | |
848 | /** | |
c977fa84 FM |
849 | Returns the length of the stream in bytes. If the length cannot be |
850 | determined (this is always the case for socket streams for example), | |
851 | returns @c wxInvalidOffset. | |
3c4f71cc | 852 | |
1e24c2af | 853 | @since 2.5.4 |
23324ae1 | 854 | */ |
adaaa686 | 855 | virtual wxFileOffset GetLength() const; |
23324ae1 FM |
856 | |
857 | /** | |
c977fa84 FM |
858 | This function returns the size of the stream. |
859 | For example, for a file it is the size of the file. | |
860 | ||
861 | @warning | |
862 | There are streams which do not have size by definition, such as socket | |
863 | streams. In that cases, GetSize returns 0 so you should always test its | |
864 | return value. | |
23324ae1 | 865 | */ |
adaaa686 | 866 | virtual size_t GetSize() const; |
23324ae1 FM |
867 | |
868 | /** | |
869 | Returns @true if no error occurred on the stream. | |
3c4f71cc | 870 | |
4cc4bfaf | 871 | @see GetLastError() |
23324ae1 | 872 | */ |
328f5751 | 873 | virtual bool IsOk() const; |
23324ae1 FM |
874 | |
875 | /** | |
876 | Returns @true if the streams supports seeking to arbitrary offsets. | |
877 | */ | |
adaaa686 | 878 | virtual bool IsSeekable() const; |
23324ae1 FM |
879 | |
880 | /** | |
881 | Internal function. It is called when the stream wants to read data of the | |
882 | specified size. It should return the size that was actually read. | |
883 | */ | |
884 | size_t OnSysRead(void* buffer, size_t bufsize); | |
885 | ||
886 | /** | |
0004982c | 887 | See OnSysRead(). |
23324ae1 | 888 | */ |
0004982c FM |
889 | size_t OnSysWrite(const void* buffer, size_t bufsize); |
890 | ||
891 | ||
892 | protected: | |
23324ae1 FM |
893 | |
894 | /** | |
c977fa84 | 895 | Internal function. |
0004982c | 896 | It is called when the stream needs to change the current position. |
23324ae1 | 897 | */ |
0004982c | 898 | virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); |
23324ae1 FM |
899 | |
900 | /** | |
0004982c FM |
901 | Internal function. |
902 | It is called when the stream needs to know the real position. | |
23324ae1 | 903 | */ |
0004982c | 904 | virtual wxFileOffset OnSysTell() const; |
23324ae1 | 905 | }; |
e54c96f1 | 906 |