2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: stream.h
|
2008-09-21 18:35:10 -04:00
|
|
|
// Purpose: interface of wxStreamBase and its derived classes
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
These enumeration values are returned by various functions in the context
|
|
|
|
of wxStream classes.
|
|
|
|
*/
|
|
|
|
enum wxStreamError
|
|
|
|
{
|
|
|
|
wxSTREAM_NO_ERROR = 0, //!< No error occurred.
|
|
|
|
wxSTREAM_EOF, //!< EOF reached in Read() or similar.
|
|
|
|
wxSTREAM_WRITE_ERROR, //!< generic write error on the last write call.
|
|
|
|
wxSTREAM_READ_ERROR //!< generic read error on the last read call.
|
|
|
|
};
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
@class wxStreamBase
|
|
|
|
|
|
|
|
This class is the base class of most stream related classes in wxWidgets.
|
|
|
|
It must not be used directly.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2009-01-13 13:09:21 -05:00
|
|
|
|
|
|
|
@see wxStreamBuffer
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxStreamBase
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Creates a dummy stream object. It doesn't do anything.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxStreamBase();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual ~wxStreamBase();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
This function returns the last error.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxStreamError GetLastError() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Returns the length of the stream in bytes. If the length cannot be
|
|
|
|
determined (this is always the case for socket streams for example),
|
|
|
|
returns ::wxInvalidOffset.
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@since 2.5.4
|
|
|
|
*/
|
|
|
|
virtual wxFileOffset GetLength() const;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
This function returns the size of the stream.
|
|
|
|
For example, for a file it is the size of the file.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@warning
|
|
|
|
There are streams which do not have size by definition, such as socket
|
|
|
|
streams. In that cases, GetSize() returns 0 so you should always test its
|
|
|
|
return value.
|
|
|
|
*/
|
|
|
|
virtual size_t GetSize() const;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns @true if no error occurred on the stream.
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@see GetLastError()
|
2008-09-21 18:35:10 -04:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual bool IsOk() const;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-29 12:42:45 -04:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns @true if the streams supports seeking to arbitrary offsets.
|
|
|
|
*/
|
|
|
|
virtual bool IsSeekable() const;
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2009-01-13 13:43:48 -05:00
|
|
|
/**
|
|
|
|
Returns the opposite of IsOk().
|
|
|
|
You can use this function to test the validity of the stream as if
|
|
|
|
it was a pointer:
|
|
|
|
|
|
|
|
@code
|
|
|
|
bool DoSomething(wxInputStream& stream)
|
|
|
|
{
|
|
|
|
wxInt32 data;
|
|
|
|
if (!stream.Read(&data, 4))
|
|
|
|
return false;
|
|
|
|
...
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
*/
|
|
|
|
bool operator!() const;
|
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
protected:
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Internal function.
|
|
|
|
It is called when the stream needs to change the current position.
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@param pos
|
|
|
|
Offset to seek to.
|
|
|
|
@param mode
|
|
|
|
One of the ::wxSeekMode enumeration values.
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@return The new stream position or ::wxInvalidOffset on error.
|
2008-09-21 18:35:10 -04:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Internal function.
|
|
|
|
It is called when the stream needs to know the real position.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@return The current stream position.
|
|
|
|
*/
|
|
|
|
virtual wxFileOffset OnSysTell() const;
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxStreamBuffer
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-12-14 09:51:42 -05:00
|
|
|
wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
|
|
|
|
linked to a stream.
|
|
|
|
|
|
|
|
Each stream always has one autoinitialized stream buffer, but you may
|
|
|
|
attach more of them to the same stream.
|
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-12-14 09:51:42 -05:00
|
|
|
@see wxStreamBase, @ref overview_stream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxStreamBuffer
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-09-21 18:35:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor, creates a new stream buffer using @a stream as a parent stream
|
|
|
|
and mode as the IO mode.
|
|
|
|
|
|
|
|
@param stream
|
|
|
|
The parent stream.
|
|
|
|
@param mode
|
|
|
|
Can be: wxStreamBuffer::read, wxStreamBuffer::write, wxStreamBuffer::read_write.
|
|
|
|
|
|
|
|
One stream can have many stream buffers but only one is used internally
|
|
|
|
to pass IO call (e.g. wxInputStream::Read() -> wxStreamBuffer::Read()),
|
|
|
|
but you can call directly wxStreamBuffer::Read without any problems.
|
|
|
|
Note that all errors and messages linked to the stream are stored in the
|
|
|
|
stream, not the stream buffers:
|
|
|
|
|
|
|
|
@code
|
|
|
|
streambuffer.Read(...);
|
2008-12-14 09:51:42 -05:00
|
|
|
streambuffer2.Read(...);
|
|
|
|
// This call erases previous error messages set by 'streambuffer'
|
|
|
|
// assuming that both instances are stream buffers for the same stream
|
2008-09-21 18:35:10 -04:00
|
|
|
@endcode
|
|
|
|
|
|
|
|
@see SetBufferIO()
|
|
|
|
*/
|
|
|
|
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
|
|
|
|
|
2008-10-29 12:42:45 -04:00
|
|
|
/**
|
|
|
|
Constructor for an input buffer of the specified size.
|
|
|
|
|
|
|
|
Using it is equivalent to using the constructor above with read mode
|
|
|
|
and calling SetBufferIO() but is more convenient.
|
|
|
|
|
|
|
|
@since 2.9.0
|
|
|
|
*/
|
|
|
|
wxStreamBuffer(wxInputStream& stream, size_t bufsize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor for an output buffer of the specified size.
|
|
|
|
|
|
|
|
Using it is equivalent to using the constructor above with write mode
|
|
|
|
and calling SetBufferIO() but is more convenient.
|
|
|
|
|
|
|
|
@since 2.9.0
|
|
|
|
*/
|
|
|
|
wxStreamBuffer(wxOutputStream& stream, size_t bufsize);
|
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
|
|
|
Constructor; creates a new empty stream buffer which won't flush any data
|
|
|
|
to a stream. mode specifies the type of the buffer (read, write, read_write).
|
2008-10-07 12:57:34 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
This stream buffer has the advantage to be stream independent and to work
|
|
|
|
only on memory buffers but it is still compatible with the rest of the
|
|
|
|
wxStream classes. You can write, read to this special stream and it will
|
|
|
|
grow (if it is allowed by the user) its internal buffer.
|
|
|
|
Briefly, it has all functionality of a "normal" stream.
|
|
|
|
|
|
|
|
@warning
|
|
|
|
The "read_write" mode doesn't currently work for standalone stream buffers.
|
|
|
|
|
|
|
|
@see SetBufferIO()
|
|
|
|
*/
|
|
|
|
wxStreamBuffer(BufMode mode);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-10-29 12:42:45 -04:00
|
|
|
Copy constructor.
|
2008-10-07 12:57:34 -04:00
|
|
|
|
|
|
|
This method initializes the stream buffer with the data of the specified
|
2008-03-08 08:52:38 -05:00
|
|
|
stream buffer. The new stream buffer has the same attributes, size, position
|
|
|
|
and they share the same buffer. This will cause problems if the stream to
|
|
|
|
which the stream buffer belong is destroyed and the newly cloned stream
|
|
|
|
buffer continues to be used, trying to call functions in the (destroyed)
|
|
|
|
stream. It is advised to use this feature only in very local area of the
|
|
|
|
program.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxStreamBuffer(const wxStreamBuffer& buffer);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Destructor.
|
|
|
|
It finalizes all IO calls and frees all internal buffers if necessary.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxStreamBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fill the IO buffer.
|
|
|
|
*/
|
|
|
|
bool FillBuffer();
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Toggles the fixed flag. Usually this flag is toggled at the same time as
|
2008-03-08 08:52:38 -05:00
|
|
|
@e flushable. This flag allows (when it has the @false value) or forbids
|
2008-09-21 18:35:10 -04:00
|
|
|
(when it has the @true value) the stream buffer to resize dynamically the
|
|
|
|
IO buffer.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetBufferIO()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Fixed(bool fixed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Flushes the IO buffer.
|
|
|
|
*/
|
|
|
|
bool FlushBuffer();
|
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Toggles the flushable flag.
|
|
|
|
If @a flushable is disabled, no data are sent to the parent stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Flushable(bool flushable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the end of the stream buffer.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetBufferEnd() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the current position of the stream buffer.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetBufferPos() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the size of the buffer.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetBufferSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the start of the stream buffer.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetBufferStart() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Gets a single char from the stream buffer. It acts like the Read() call.
|
|
|
|
|
|
|
|
@warning
|
|
|
|
You aren't directly notified if an error occurred during the IO call.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Read()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual char GetChar();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the amount of available data in the buffer.
|
|
|
|
*/
|
|
|
|
size_t GetDataLeft();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current position (counted in bytes) in the stream buffer.
|
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
size_t GetIntPosition() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the amount of bytes read during the last IO call to the parent stream.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetLastAccess() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Puts a single char to the stream buffer.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@warning
|
|
|
|
You aren't directly notified if an error occurred during the IO call.
|
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Read()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual void PutChar(char c);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Reads a block of the specified size and stores the data in buffer.
|
|
|
|
This function tries to read from the buffer first and if more data has
|
|
|
|
been requested, reads more data from the associated stream and updates
|
|
|
|
the buffer accordingly until all requested data is read.
|
|
|
|
|
|
|
|
@return It returns the size of the data read. If the returned size is
|
|
|
|
different of the specified size, an error has occurred and
|
|
|
|
should be tested using GetLastError().
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual size_t Read(void* buffer, size_t size);
|
2008-09-21 18:35:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Copies data to @a buffer.
|
|
|
|
The function returns when @a buffer is full or when there isn't
|
2008-03-08 08:52:38 -05:00
|
|
|
any more data in the current buffer.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Write()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-13 16:32:53 -05:00
|
|
|
size_t Read(wxStreamBuffer* buffer);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Resets to the initial state variables concerning the buffer.
|
|
|
|
*/
|
|
|
|
void ResetBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Changes the current position.
|
2008-09-21 18:35:10 -04:00
|
|
|
Parameter @a mode may be one of the following:
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
- @b wxFromStart: The position is counted from the start of the stream.
|
|
|
|
- @b wxFromCurrent: The position is counted from the current position of the stream.
|
|
|
|
- @b wxFromEnd: The position is counted from the end of the stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@return Upon successful completion, it returns the new offset as
|
|
|
|
measured in bytes from the beginning of the stream.
|
2009-01-13 12:29:34 -05:00
|
|
|
Otherwise, it returns ::wxInvalidOffset.
|
2008-09-21 18:35:10 -04:00
|
|
|
*/
|
2008-09-27 08:29:33 -04:00
|
|
|
virtual wxFileOffset Seek(wxFileOffset pos, wxSeekMode mode);
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
|
|
|
Specifies which pointers to use for stream buffering.
|
|
|
|
You need to pass a pointer on the start of the buffer end and another
|
|
|
|
on the end. The object will use this buffer to cache stream data.
|
|
|
|
It may be used also as a source/destination buffer when you create an
|
|
|
|
empty stream buffer (See wxStreamBuffer::wxStreamBuffer).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@remarks
|
|
|
|
When you use this function, you will have to destroy the IO buffers
|
|
|
|
yourself after the stream buffer is destroyed or don't use it anymore.
|
|
|
|
In the case you use it with an empty buffer, the stream buffer will not
|
|
|
|
resize it when it is full.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@see wxStreamBuffer(), Fixed(), Flushable()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-13 16:32:53 -05:00
|
|
|
void SetBufferIO(void* start, void* end, bool takeOwnership = false);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destroys or invalidates the previous IO buffer and allocates a new one of the
|
|
|
|
specified size.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@warning
|
|
|
|
All previous pointers aren't valid anymore.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@remarks
|
|
|
|
The created IO buffer is growable by the object.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
@see Fixed(), Flushable()
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
void SetBufferIO(size_t bufsize);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current position (in bytes) in the stream buffer.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
|
|
|
@warning
|
|
|
|
Since it is a very low-level function, there is no check on the position:
|
|
|
|
specifying an invalid position can induce unexpected results.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetIntPosition(size_t pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the parent stream of the stream buffer.
|
2008-11-08 10:25:07 -05:00
|
|
|
@deprecated use GetStream() instead
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxStreamBase* Stream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the current position in the stream. This position is calculated from
|
|
|
|
the @e real position in the stream and from the internal buffer position: so
|
|
|
|
it gives you the position in the @e real stream counted from the start of
|
|
|
|
the stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return Returns the current position in the stream if possible,
|
2009-01-13 12:29:34 -05:00
|
|
|
::wxInvalidOffset in the other case.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 08:29:33 -04:00
|
|
|
virtual wxFileOffset Tell() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Truncates the buffer to the current position.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
|
|
|
@note Truncate() cannot be used to enlarge the buffer. This is
|
|
|
|
usually not needed since the buffer expands automatically.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Truncate();
|
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Writes a block of the specified size using data of buffer.
|
|
|
|
The data are cached in a buffer before being sent in one block to the stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual size_t Write(const void* buffer, size_t size);
|
2008-09-21 18:35:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
See Read().
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
size_t Write(wxStreamBuffer* buffer);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxOutputStream is an abstract base class which may not be used directly.
|
2009-01-13 13:09:21 -05:00
|
|
|
It is the base class of all streams which provide a Write() function,
|
|
|
|
i.e. which can be used to output data (e.g. to a file, to a socket, etc).
|
|
|
|
|
|
|
|
If you want to create your own output stream, you'll need to derive from this
|
|
|
|
class and implement the protected OnSysWrite() function only.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
|
|
|
class wxOutputStream : public wxStreamBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a dummy wxOutputStream object.
|
|
|
|
*/
|
|
|
|
wxOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Closes the stream, returning @false if an error occurs.
|
|
|
|
The stream is closed implicitly in the destructor if Close() is not
|
2008-03-08 08:52:38 -05:00
|
|
|
called explicitly.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If this stream wraps another stream or some other resource such
|
|
|
|
as a file, then the underlying resource is closed too if it is owned
|
|
|
|
by this stream, or left open otherwise.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool Close();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-21 18:35:10 -04:00
|
|
|
Returns the number of bytes written during the last Write().
|
|
|
|
It may return 0 even if there is no error on the stream if it is
|
|
|
|
only temporarily impossible to write to it.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual size_t LastWrite() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Puts the specified character in the output queue and increments the
|
|
|
|
stream position.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void PutC(char c);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Changes the stream current position.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-03-09 08:33:59 -04:00
|
|
|
Offset to seek to.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param mode
|
2008-03-09 08:33:59 -04:00
|
|
|
One of wxFromStart, wxFromEnd, wxFromCurrent.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 12:29:34 -05:00
|
|
|
@return The new stream position or ::wxInvalidOffset on error.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 08:29:33 -04:00
|
|
|
virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current stream position.
|
|
|
|
*/
|
2008-09-27 08:29:33 -04:00
|
|
|
virtual wxFileOffset TellO() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
|
|
|
Writes up to the specified amount of bytes using the data of buffer.
|
|
|
|
Note that not all data can always be written so you must check the number
|
|
|
|
of bytes really written to the stream using LastWrite() when this function
|
|
|
|
returns.
|
|
|
|
|
|
|
|
In some cases (for example a write end of a pipe which is currently full)
|
|
|
|
it is even possible that there is no errors and zero bytes have been written.
|
|
|
|
This function returns a reference on the current object, so the user can
|
|
|
|
test any states of the stream right away.
|
|
|
|
*/
|
2008-11-13 16:32:53 -05:00
|
|
|
virtual wxOutputStream& Write(const void* buffer, size_t size);
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Reads data from the specified input stream and stores them
|
2008-03-08 08:52:38 -05:00
|
|
|
in the current stream. The data is read until an error is raised
|
|
|
|
by one of the two streams.
|
|
|
|
*/
|
2008-11-10 16:33:25 -05:00
|
|
|
wxOutputStream& Write(wxInputStream& stream_in);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Internal function. It is called when the stream wants to write data of the
|
|
|
|
specified size @a bufsize into the given @a buffer.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
It should return the size that was actually wrote (which maybe zero if
|
|
|
|
@a bufsize is zero or if an error occurred; in this last case the internal
|
|
|
|
variable @c m_lasterror should be appropriately set).
|
|
|
|
*/
|
|
|
|
size_t OnSysWrite(const void* buffer, size_t bufsize);
|
2008-09-21 18:35:10 -04:00
|
|
|
};
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
@class wxInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
wxInputStream is an abstract base class which may not be used directly.
|
|
|
|
It is the base class of all streams which provide a Read() function,
|
|
|
|
i.e. which can be used to read data from a source (e.g. a file, a socket, etc).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
If you want to create your own input stream, you'll need to derive from this
|
|
|
|
class and implement the protected OnSysRead() function only.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-09-21 18:35:10 -04:00
|
|
|
@category{streams}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxInputStream : public wxStreamBase
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Creates a dummy input stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxInputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Destructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual ~wxInputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns @true if some data is available in the stream right now, so that
|
|
|
|
calling Read() wouldn't block.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual bool CanRead() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns @true after an attempt has been made to read past the end of the
|
|
|
|
stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual bool Eof() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns the first character in the input queue and removes it,
|
|
|
|
blocking until it appears if necessary.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
On success returns a value between 0 - 255; on end of file returns @c wxEOF.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
int GetC();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns the last number of bytes read.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual size_t LastRead() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns the first character in the input queue without removing it.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual char Peek();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Reads the specified amount of bytes and stores the data in buffer.
|
|
|
|
To check if the call was successfull you must use LastRead() to check
|
|
|
|
if this call did actually read @a size bytes (if it didn't, GetLastError()
|
|
|
|
should return a meaningful value).
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@warning
|
|
|
|
The buffer absolutely needs to have at least the specified size.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@return This function returns a reference on the current object, so the
|
|
|
|
user can test any states of the stream right away.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual wxInputStream& Read(void* buffer, size_t size);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Reads data from the input queue and stores it in the specified output stream.
|
|
|
|
The data is read until an error is raised by one of the two streams.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@return This function returns a reference on the current object, so the
|
|
|
|
user can test any states of the stream right away.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxInputStream& Read(wxOutputStream& stream_out);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Changes the stream current position.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@param pos
|
|
|
|
Offset to seek to.
|
|
|
|
@param mode
|
|
|
|
One of wxFromStart, wxFromEnd, wxFromCurrent.
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@return The new stream position or ::wxInvalidOffset on error.
|
|
|
|
*/
|
|
|
|
virtual wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart);
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Returns the current stream position.
|
|
|
|
*/
|
|
|
|
virtual wxFileOffset TellI() const;
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
This function is only useful in read mode.
|
|
|
|
It is the manager of the "Write-Back" buffer. This buffer acts like a
|
|
|
|
temporary buffer where data which has to be read during the next read IO
|
|
|
|
call are put. This is useful when you get a big block of data which you
|
|
|
|
didn't want to read: you can replace them at the top of the input queue
|
|
|
|
by this way.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
Be very careful about this call in connection with calling SeekI() on
|
|
|
|
the same stream. Any call to SeekI() will invalidate any previous call
|
|
|
|
to this method (otherwise you could SeekI() to one position, "unread" a
|
|
|
|
few bytes there, SeekI() to another position and data would be either
|
|
|
|
lost or corrupted).
|
|
|
|
|
|
|
|
@return Returns the amount of bytes saved in the Write-Back buffer.
|
|
|
|
*/
|
|
|
|
size_t Ungetch(const void* buffer, size_t size);
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
This function acts like the previous one except that it takes only one
|
|
|
|
character: it is sometimes shorter to use than the generic function.
|
|
|
|
*/
|
|
|
|
bool Ungetch(char c);
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal function. It is called when the stream wants to read data of the
|
|
|
|
specified size @a bufsize and wants it to be placed inside @a buffer.
|
|
|
|
|
|
|
|
It should return the size that was actually read or zero if EOF has been
|
|
|
|
reached or an error occurred (in this last case the internal @c m_lasterror
|
|
|
|
variable should be set accordingly as well).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
size_t OnSysRead(void* buffer, size_t bufsize);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
@class wxCountingOutputStream
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
wxCountingOutputStream is a specialized output stream which does not write any
|
|
|
|
data anywhere, instead it counts how many bytes would get written if this were a
|
|
|
|
normal stream. This can sometimes be useful or required if some data gets
|
|
|
|
serialized to a stream or compressed by using stream compression and thus the
|
|
|
|
final size of the stream cannot be known other than pretending to write the stream.
|
|
|
|
One case where the resulting size would have to be known is if the data has
|
|
|
|
to be written to a piece of memory and the memory has to be allocated before
|
|
|
|
writing to it (which is probably always the case when writing to a memory stream).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxCountingOutputStream : public wxOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Creates a wxCountingOutputStream object.
|
|
|
|
*/
|
|
|
|
wxCountingOutputStream();
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Destructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual ~wxCountingOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Returns the current size of the stream.
|
|
|
|
*/
|
|
|
|
size_t GetSize() const;
|
|
|
|
};
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
@class wxBufferedInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
This stream acts as a cache. It caches the bytes read from the specified
|
|
|
|
input stream (see wxFilterInputStream).
|
|
|
|
It uses wxStreamBuffer and sets the default in-buffer size to 1024 bytes.
|
|
|
|
This class may not be used without some other stream to read the data
|
|
|
|
from (such as a file stream or a memory stream).
|
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
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@see wxStreamBuffer, wxInputStream, wxBufferedOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxBufferedInputStream : public wxFilterInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-10-29 12:42:45 -04:00
|
|
|
Constructor using the provided buffer or default.
|
|
|
|
|
|
|
|
@param stream
|
|
|
|
The associated low-level stream.
|
|
|
|
@param buffer
|
|
|
|
The buffer to use if non-@NULL. Notice that the ownership of this
|
|
|
|
buffer is taken by the stream, i.e. it will delete it. If this
|
|
|
|
parameter is @NULL a default 1KB buffer is used.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxBufferedInputStream(wxInputStream& stream,
|
|
|
|
wxStreamBuffer *buffer = NULL);
|
2008-10-29 12:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor allowing to specify the size of the buffer.
|
|
|
|
|
|
|
|
This is just a more convenient alternative to creating a wxStreamBuffer
|
|
|
|
of the given size and using the other overloaded constructor of this
|
|
|
|
class.
|
|
|
|
|
|
|
|
@param stream
|
|
|
|
The associated low-level stream.
|
|
|
|
@param bufsize
|
|
|
|
The size of the buffer, in bytes.
|
|
|
|
|
|
|
|
@since 2.9.0
|
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxBufferedInputStream(wxInputStream& stream, size_t bufsize);
|
2008-10-29 12:42:45 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Destructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual ~wxBufferedInputStream();
|
|
|
|
};
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Enumeration values used by wxFilterClassFactory.
|
|
|
|
*/
|
|
|
|
enum wxStreamProtocolType
|
|
|
|
{
|
|
|
|
wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one).
|
|
|
|
wxSTREAM_MIMETYPE, //!< MIME types the stream handles.
|
|
|
|
wxSTREAM_ENCODING, //!< The HTTP Content-Encodings the stream handles.
|
|
|
|
wxSTREAM_FILEEXT //!< File extensions the stream handles.
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
@class wxFilterClassFactory
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
Allows the creation of filter streams to handle compression formats such
|
|
|
|
as gzip and bzip2.
|
|
|
|
|
|
|
|
For example, given a filename you can search for a factory that will
|
|
|
|
handle it and create a stream to decompress it:
|
|
|
|
|
|
|
|
@code
|
|
|
|
factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT);
|
|
|
|
if (factory)
|
|
|
|
stream = factory->NewStream(new wxFFileInputStream(filename));
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
wxFilterClassFactory::Find can also search for a factory by MIME type,
|
|
|
|
HTTP encoding or by wxFileSystem protocol.
|
|
|
|
The available factories can be enumerated using wxFilterClassFactory::GetFirst()
|
|
|
|
and wxFilterClassFactory::GetNext().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2009-01-13 13:09:21 -05:00
|
|
|
|
|
|
|
@see wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory,
|
|
|
|
@ref overview_archive
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxFilterClassFactory : public wxObject
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns @true if this factory can handle the given protocol, MIME type, HTTP
|
|
|
|
encoding or file extension.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
bool CanHandle(const wxString& protocol,
|
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
A static member that finds a factory that can handle a given protocol, MIME
|
|
|
|
type, HTTP encoding or file extension. Returns a pointer to the class
|
|
|
|
factory if found, or @NULL otherwise.
|
|
|
|
It does not give away ownership of the factory.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
static const wxFilterClassFactory* Find(const wxString& protocol,
|
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
//@{
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
GetFirst and GetNext can be used to enumerate the available factories.
|
|
|
|
For example, to list them:
|
2008-11-22 07:44:17 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@code
|
|
|
|
wxString list;
|
|
|
|
const wxFilterClassFactory *factory = wxFilterClassFactory::GetFirst();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
while (factory) {
|
|
|
|
list << factory->GetProtocol() << _T("\n");
|
|
|
|
factory = factory->GetNext();
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
GetFirst()/GetNext() return a pointer to a factory or @NULL if no more
|
|
|
|
are available. They do not give away ownership of the factory.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
static const wxFilterClassFactory* GetFirst();
|
|
|
|
const wxFilterClassFactory* GetNext() const;
|
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns the wxFileSystem protocol supported by this factory.
|
|
|
|
Equivalent to @code wxString(*GetProtocols()) @endcode.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxString GetProtocol() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Returns the protocols, MIME types, HTTP encodings or file extensions
|
|
|
|
supported by this factory, as an array of null terminated strings.
|
|
|
|
It does not give away ownership of the array or strings.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
For example, to list the file extensions a factory supports:
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@code
|
|
|
|
wxString list;
|
|
|
|
const wxChar *const *p;
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++)
|
|
|
|
list << *p << _T("\n");
|
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual const wxChar * const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
//@{
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Create a new input or output stream to decompress or compress a given stream.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
If the parent stream is passed as a pointer then the new filter stream
|
|
|
|
takes ownership of it. If it is passed by reference then it does not.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual wxFilterInputStream* NewStream(wxInputStream& stream) const = 0;
|
|
|
|
virtual wxFilterOutputStream* NewStream(wxOutputStream& stream) const = 0;
|
|
|
|
virtual wxFilterInputStream* NewStream(wxInputStream* stream) const = 0;
|
|
|
|
virtual wxFilterOutputStream* NewStream(wxOutputStream* stream) const = 0;
|
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Remove the file extension of @a location if it is one of the file
|
|
|
|
extensions handled by this factory.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxString PopExtension(const wxString& location) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Adds this class factory to the list returned by GetFirst()/GetNext().
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
It is not necessary to do this to use the filter streams. It is usually
|
|
|
|
used when implementing streams, typically the implementation will
|
|
|
|
add a static instance of its factory class.
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
It can also be used to change the order of a factory already in the list,
|
|
|
|
bringing it to the front. This isn't a thread safe operation so can't be
|
|
|
|
done when other threads are running that will be using the list.
|
|
|
|
|
|
|
|
The list does not take ownership of the factory.
|
2008-09-21 18:35:10 -04:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
void PushFront();
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Removes this class factory from the list returned by GetFirst()/GetNext().
|
|
|
|
Removing from the list isn't a thread safe operation so can't be done
|
|
|
|
when other threads are running that will be using the list.
|
|
|
|
|
|
|
|
The list does not own the factories, so removing a factory does not delete it.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
void Remove();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
|
2008-09-21 18:35:10 -04:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
@class wxFilterOutputStream
|
|
|
|
|
|
|
|
A filter stream has the capability of a normal stream but it can be placed
|
|
|
|
on top of another stream. So, for example, it can compress, encrypt the data
|
|
|
|
which are passed to it and write them to another stream.
|
|
|
|
|
|
|
|
@note
|
|
|
|
The use of this class is exactly the same as of wxOutputStream.
|
|
|
|
Only a constructor differs and it is documented below.
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
|
|
|
|
@see wxFilterClassFactory, wxFilterInputStream
|
2008-09-21 18:35:10 -04:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxFilterOutputStream : public wxOutputStream
|
2008-09-21 18:35:10 -04:00
|
|
|
{
|
2009-01-13 13:09:21 -05:00
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Initializes a "filter" stream.
|
|
|
|
|
|
|
|
If the parent stream is passed as a pointer then the new filter stream
|
|
|
|
takes ownership of it. If it is passed by reference then it does not.
|
|
|
|
*/
|
|
|
|
wxFilterOutputStream(wxOutputStream& stream);
|
|
|
|
wxFilterOutputStream(wxOutputStream* stream);
|
|
|
|
//@}
|
2008-09-21 18:35:10 -04:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
@class wxFilterInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
A filter stream has the capability of a normal stream but it can be placed on
|
|
|
|
top of another stream. So, for example, it can uncompress or decrypt the data which
|
|
|
|
are read from another stream and pass it to the requester.
|
|
|
|
|
|
|
|
@note
|
|
|
|
The interface of this class is the same as that of wxInputStream.
|
|
|
|
Only a constructor differs and it is documented below.
|
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
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@see wxFilterClassFactory, wxFilterOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
class wxFilterInputStream : public wxInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2009-01-13 13:09:21 -05:00
|
|
|
//@{
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Initializes a "filter" stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
If the parent stream is passed as a pointer then the new filter stream
|
|
|
|
takes ownership of it. If it is passed by reference then it does not.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxFilterInputStream(wxInputStream& stream);
|
|
|
|
wxFilterInputStream(wxInputStream* stream);
|
|
|
|
//@}
|
|
|
|
};
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
@class wxBufferedOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
This stream acts as a cache. It caches the bytes to be written to the specified
|
|
|
|
output stream (See wxFilterOutputStream). The data is only written when the
|
|
|
|
cache is full, when the buffered stream is destroyed or when calling SeekO().
|
2008-09-21 18:35:10 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
This class may not be used without some other stream to write the data
|
|
|
|
to (such as a file stream or a memory stream).
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@see wxStreamBuffer, wxOutputStream
|
|
|
|
*/
|
|
|
|
class wxBufferedOutputStream : public wxFilterOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Constructor using the provided buffer or default.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@param stream
|
|
|
|
The associated low-level stream.
|
|
|
|
@param buffer
|
|
|
|
The buffer to use if non-@NULL. Notice that the ownership of this
|
|
|
|
buffer is taken by the stream, i.e. it will delete it. If this
|
|
|
|
parameter is @NULL a default 1KB buffer is used.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
wxBufferedOutputStream(wxOutputStream& stream,
|
|
|
|
wxStreamBuffer *buffer = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Constructor allowing to specify the size of the buffer.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
This is just a more convenient alternative to creating a wxStreamBuffer
|
|
|
|
of the given size and using the other overloaded constructor of this
|
|
|
|
class.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@param stream
|
|
|
|
The associated low-level stream.
|
|
|
|
@param bufsize
|
|
|
|
The size of the buffer, in bytes.
|
2008-10-13 07:09:56 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
@since 2.9.0
|
|
|
|
*/
|
|
|
|
wxBufferedOutputStream(wxOutputStream& stream, size_t bufsize);
|
2008-10-13 07:09:56 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
/**
|
|
|
|
Destructor. Calls Sync() and destroys the internal buffer.
|
|
|
|
*/
|
|
|
|
virtual ~wxBufferedOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Calls Sync() and changes the stream position.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-13 13:09:21 -05:00
|
|
|
Flushes the buffer and calls Sync() on the parent stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-13 13:09:21 -05:00
|
|
|
virtual void Sync();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2009-01-13 13:09:21 -05:00
|
|
|
|