2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: stream.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxCountingOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxCountingOutputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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
|
2008-03-08 14:43:31 +00:00
|
|
|
to a
|
2008-03-08 13:52:38 +00:00
|
|
|
memory stream).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
|
|
|
class wxCountingOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a wxCountingOutputStream object.
|
|
|
|
*/
|
|
|
|
wxCountingOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxCountingOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current size of the stream.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetSize() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxBufferedInputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxStreamBuffer, wxInputStream, wxBufferedOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxBufferedInputStream : public wxFilterInputStream
|
|
|
|
{
|
|
|
|
public:
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxStreamBuffer
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxStreamBase
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxStreamBuffer
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Constructor. It initializes the stream buffer with the data of the specified
|
|
|
|
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-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see @ref setbufferio() wxStreamBuffer:SetBufferIO
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
|
2008-03-08 14:43:31 +00:00
|
|
|
wxStreamBuffer(BufMode mode);
|
|
|
|
wxStreamBuffer(const wxStreamBuffer& buffer);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor. It finalizes all IO calls and frees all internal buffers if
|
|
|
|
necessary.
|
|
|
|
*/
|
|
|
|
wxStreamBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fill the IO buffer.
|
|
|
|
*/
|
|
|
|
bool FillBuffer();
|
|
|
|
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Toggles the fixed flag. Usually this flag is toggled at the same time as
|
2008-03-08 13:52:38 +00:00
|
|
|
@e flushable. This flag allows (when it has the @false value) or forbids
|
|
|
|
(when it has the @true value) the stream buffer to resize dynamically the IO
|
|
|
|
buffer.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see SetBufferIO()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void Fixed(bool fixed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Flushes the IO buffer.
|
|
|
|
*/
|
|
|
|
bool FlushBuffer();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Toggles the flushable flag. If @a flushable is disabled, no data are sent
|
2008-03-08 13:52:38 +00:00
|
|
|
to the parent stream.
|
|
|
|
*/
|
|
|
|
void Flushable(bool flushable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the end of the stream buffer.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
void* GetBufferEnd() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the current position of the stream buffer.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
void* GetBufferPos() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the size of the buffer.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetBufferSize() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer on the start of the stream buffer.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
void* GetBufferStart() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets a single char from the stream buffer. It acts like the Read call.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Read()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
char GetChar();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the amount of available data in the buffer.
|
|
|
|
*/
|
|
|
|
size_t GetDataLeft();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current position (counted in bytes) in the stream buffer.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
off_t GetIntPosition() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the amount of bytes read during the last IO call to the parent stream.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetLastAccess() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Puts a single char to the stream buffer.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Read()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void PutChar(char c);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Copies data to @e buffer. The function returns when @a buffer is full or when
|
2008-03-08 13:52:38 +00:00
|
|
|
there isn't
|
|
|
|
any more data in the current buffer.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Write()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
size_t Read(void* buffer, size_t size);
|
|
|
|
Return value size_t Read(wxStreamBuffer* buffer);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Resets to the initial state variables concerning the buffer.
|
|
|
|
*/
|
|
|
|
void ResetBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Changes the current position.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a mode may be one of the following:
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxFromStart
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The position is counted from the start of the stream.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxFromCurrent
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The position is counted from the current position of the stream.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxFromEnd
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The position is counted from the end of the stream.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Upon successful completion, it returns the new offset as
|
2008-03-09 12:33:59 +00:00
|
|
|
measured in bytes from the beginning of the stream.
|
|
|
|
Otherwise, it returns wxInvalidOffset.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
off_t Seek(off_t pos, wxSeekMode mode);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Destroys or invalidates the previous IO buffer and allocates a new one of the
|
|
|
|
specified size.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Fixed(), Flushable()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetBufferIO(char* buffer_start, char* buffer_end);
|
2008-03-08 14:43:31 +00:00
|
|
|
Remarks See also
|
|
|
|
wxStreamBuffer constructor
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
wxStreamBuffer::Fixed
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
wxStreamBuffer::Flushable
|
|
|
|
void SetBufferIO(size_t bufsize);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current position (in bytes) in the stream buffer.
|
|
|
|
*/
|
|
|
|
void SetIntPosition(size_t pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the parent stream of the stream buffer.
|
|
|
|
*/
|
|
|
|
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 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns the current position in the stream if possible,
|
2008-03-09 12:33:59 +00:00
|
|
|
wxInvalidOffset in the other case.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
off_t Tell() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Truncates the buffer to the current position.
|
|
|
|
Note: Truncate() cannot be used to enlarge the buffer. This is
|
|
|
|
usually not needed since the buffer expands automatically.
|
|
|
|
*/
|
|
|
|
void Truncate();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
See Read().
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
size_t Write(const void* buffer, size_t size);
|
|
|
|
size_t Write(wxStreamBuffer* buffer);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxOutputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxOutputStream is an abstract base class which may not be used directly.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
|
|
|
class wxOutputStream : public wxStreamBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a dummy wxOutputStream object.
|
|
|
|
*/
|
|
|
|
wxOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the stream, returning @false if an error occurs. The
|
|
|
|
stream is closed implicitly in the destructor if Close() is not
|
|
|
|
called explicitly.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
bool Close();
|
|
|
|
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Returns the number of bytes written during the last
|
2008-03-08 13:52:38 +00:00
|
|
|
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-09 16:24:26 +00:00
|
|
|
size_t LastWrite() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Puts the specified character in the output queue and increments the
|
|
|
|
stream position.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void PutC(char c);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Changes the stream current position.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param pos
|
2008-03-09 12:33:59 +00:00
|
|
|
Offset to seek to.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param mode
|
2008-03-09 12:33:59 +00:00
|
|
|
One of wxFromStart, wxFromEnd, wxFromCurrent.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return The new stream position or wxInvalidOffset on error.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current stream position.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
off_t TellO() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Reads data from the specified input stream and stores them
|
2008-03-08 13:52:38 +00:00
|
|
|
in the current stream. The data is read until an error is raised
|
|
|
|
by one of the two streams.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxOutputStream Write(const void* buffer, size_t size);
|
2008-03-08 14:43:31 +00:00
|
|
|
wxOutputStream Write(wxInputStream& stream_in);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFilterClassFactory
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Allows the creation of filter streams to handle compression formats such
|
|
|
|
as gzip and bzip2.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
For example, given a filename you can search for a factory that will
|
|
|
|
handle it and create a stream to decompress it:
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@code
|
|
|
|
factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT);
|
|
|
|
if (factory)
|
|
|
|
stream = factory-NewStream(new wxFFileInputStream(filename));
|
|
|
|
@endcode
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxFilterClassFactory::Find can also search
|
|
|
|
for a factory by MIME type, HTTP encoding or by wxFileSystem protocol.
|
|
|
|
The available factories can be enumerated
|
|
|
|
using @ref wxFilterClassFactory::getfirst "GetFirst() and GetNext".
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{FIXME}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory, @ref
|
2008-03-08 13:52:38 +00:00
|
|
|
overview_wxarc "Archive formats such as zip"
|
|
|
|
*/
|
|
|
|
class wxFilterClassFactory : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Returns @true if this factory can handle the given protocol, MIME type, HTTP
|
|
|
|
encoding or file extension.
|
|
|
|
When using wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
|
|
|
*/
|
|
|
|
bool CanHandle(const wxString& protocol,
|
2008-03-09 16:24:26 +00:00
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
|
2008-03-08 13:52:38 +00: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.
|
|
|
|
When using wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
|
|
|
*/
|
|
|
|
static const wxFilterClassFactory* Find(const wxString& protocol,
|
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
GetFirst and GetNext can be used to enumerate the available factories.
|
|
|
|
For example, to list them:
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
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-09 16:24:26 +00:00
|
|
|
static const wxFilterClassFactory* GetFirst() const;
|
|
|
|
const wxFilterClassFactory* GetNext() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the wxFileSystem protocol supported by this factory. Equivalent
|
|
|
|
to wxString(*GetProtcols()).
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetProtocol() const;
|
2008-03-08 13:52:38 +00: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.
|
|
|
|
For example, to list the file extensions a factory supports:
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
const wxChar* const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Create a new input or output stream to decompress or compress a given 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.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxFilterInputStream* NewStream(wxInputStream& stream) const;
|
|
|
|
const wxFilterOutputStream* NewStream(wxOutputStream& stream) const;
|
|
|
|
const wxFilterInputStream* NewStream(wxInputStream* stream) const;
|
|
|
|
const wxFilterOutputStream* NewStream(wxOutputStream* stream) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Remove the file extension of @a location if it is one of the file
|
2008-03-08 13:52:38 +00:00
|
|
|
extensions handled by this factory.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString PopExtension(const wxString& location) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Adds this class factory to the list returned
|
|
|
|
by @ref getfirst() GetFirst()/GetNext.
|
|
|
|
It is not necessary to do this to use the filter streams. It is usually
|
2008-03-08 14:43:31 +00:00
|
|
|
used when implementing streams, typically the implementation will
|
2008-03-08 13:52:38 +00:00
|
|
|
add a static instance of its factory class.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void PushFront();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes this class factory from the list returned
|
|
|
|
by @ref getfirst() 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.
|
|
|
|
*/
|
|
|
|
void Remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFilterOutputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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 compress, encrypt the data which are passed to it and write them to another
|
|
|
|
stream.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxFilterClassFactory, wxFilterInputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFilterOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
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);
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFilterOutputStream(wxOutputStream* stream);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFilterInputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxFilterClassFactory, wxFilterOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFilterInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
wxFilterInputStream(wxInputStream& stream);
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFilterInputStream(wxInputStream* stream);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxBufferedOutputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxStreamBuffer, wxOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxBufferedOutputStream : public wxFilterOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a buffered stream using a buffer of a default size of 1024 bytes for
|
|
|
|
cashing
|
|
|
|
the stream @e parent.
|
|
|
|
*/
|
|
|
|
wxBufferedOutputStream(const wxOutputStream& parent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor. Calls Sync() and destroys the internal buffer.
|
|
|
|
*/
|
|
|
|
~wxBufferedOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls Sync() and changes the stream position.
|
|
|
|
*/
|
|
|
|
off_t SeekO(off_t pos, wxSeekMode mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Flushes the buffer and calls Sync() on the parent stream.
|
|
|
|
*/
|
|
|
|
void Sync();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxInputStream
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxInputStream is an abstract base class which may not be used directly.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
*/
|
|
|
|
class wxInputStream : public wxStreamBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a dummy input stream.
|
|
|
|
*/
|
|
|
|
wxInputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxInputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if some data is available in the stream right now, so that
|
|
|
|
calling Read() wouldn't block.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool CanRead() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true after an attempt has been made to read past the end of the
|
|
|
|
stream.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool Eof() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Returns the first character in the input queue and removes it,
|
2008-03-08 13:52:38 +00:00
|
|
|
blocking until it appears if necessary.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
char GetC();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the last number of bytes read.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t LastRead() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the first character in the input queue without removing it.
|
|
|
|
*/
|
|
|
|
char Peek();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
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-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return This function returns a reference on the current object, so the
|
2008-03-09 12:33:59 +00:00
|
|
|
user can test any states of the stream right away.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxInputStream Read(void* buffer, size_t size);
|
2008-03-08 14:43:31 +00:00
|
|
|
Warning Return value
|
|
|
|
This function returns a reference on the current object, so the user can test
|
|
|
|
any states of the stream right away.
|
|
|
|
wxInputStream& Read(wxOutputStream& stream_out);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Changes the stream current position.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param pos
|
2008-03-09 12:33:59 +00:00
|
|
|
Offset to seek to.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param mode
|
2008-03-09 12:33:59 +00:00
|
|
|
One of wxFromStart, wxFromEnd, wxFromCurrent.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return The new stream position or wxInvalidOffset on error.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current stream position.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
off_t TellI() const;
|
2008-03-08 13:52:38 +00: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.
|
|
|
|
*/
|
|
|
|
size_t Ungetch(const char* buffer, size_t size);
|
2008-03-08 14:43:31 +00:00
|
|
|
Return value bool Ungetch(char c);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxStreamBase
|
|
|
|
@wxheader{stream.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
This class is the base class of most stream related classes in wxWidgets. It
|
|
|
|
must
|
|
|
|
not be used directly.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxStreamBuffer
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxStreamBase
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Creates a dummy stream object. It doesn't do anything.
|
|
|
|
*/
|
|
|
|
wxStreamBase();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxStreamBase();
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function returns the last error.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxSTREAM_NO_ERROR
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
No error occurred.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxSTREAM_EOF
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
An End-Of-File occurred.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxSTREAM_WRITE_ERROR
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
A generic error occurred on the last write call.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@b wxSTREAM_READ_ERROR
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
A generic error occurred on the last read call.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxStreamError GetLastError() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the stream in bytes. If the length cannot be determined
|
2008-03-08 14:43:31 +00:00
|
|
|
(this is always the case for socket streams for example), returns
|
2008-03-08 13:52:38 +00:00
|
|
|
@c wxInvalidOffset.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-04-21 10:34:23 +00:00
|
|
|
@since 2.5.4
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxFileOffset GetLength() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
GetLength()
|
|
|
|
This function returns the size of the stream. For example, for a file it is the
|
|
|
|
size of the file.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetSize() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if no error occurred on the stream.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see GetLastError()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
virtual bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the streams supports seeking to arbitrary offsets.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsSeekable() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Internal function. It is called when the stream wants to read data of the
|
|
|
|
specified size. It should return the size that was actually read.
|
|
|
|
*/
|
|
|
|
size_t OnSysRead(void* buffer, size_t bufsize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal function. It is called when the stream needs to change the
|
|
|
|
current position.
|
|
|
|
*/
|
|
|
|
off_t OnSysSeek(off_t pos, wxSeekMode mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal function. Is is called when the stream needs to know the
|
|
|
|
real position.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
off_t OnSysTell() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
See OnSysRead().
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
size_t OnSysWrite(const void* buffer, size_t bufsize);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|