From: Vadim Zeitlin Date: Wed, 10 Nov 2004 21:10:30 +0000 (+0000) Subject: replaced wxStream::GetSize() with GetLength() (still keep the former but it will... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/588066b7a39629e44bb39f1ab436b80f38c13f33 replaced wxStream::GetSize() with GetLength() (still keep the former but it will be deprecated) (second part of patch 1063498) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30428 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index ace09c8ba9..3c296e3124 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -229,6 +229,7 @@ All: SQL_C_WXCHAR should be used rather than SQL_C_CHAR to ensure transparent behavior between Unicode and non-unicode builds - BLOB example added to samples\db (thanks to Casey ODonnell) +- use wxStream::GetLength() instead of deprecated GetSize() All (GUI): diff --git a/docs/latex/wx/strmbase.tex b/docs/latex/wx/strmbase.tex index 23d8b3defa..1e7f6d824e 100644 --- a/docs/latex/wx/strmbase.tex +++ b/docs/latex/wx/strmbase.tex @@ -27,27 +27,31 @@ None % ctor & dtor % ----------- + \membersection{wxStreamBase::wxStreamBase}\label{wxstreambasector} \func{}{wxStreamBase}{\void} Creates a dummy stream object. It doesn't do anything. + \membersection{wxStreamBase::\destruct{wxStreamBase}}\label{wxstreambasedtor} \func{}{\destruct{wxStreamBase}}{\void} Destructor. -\membersection{wxStreamBase::IsOk}\label{wxstreambaseisok} -\constfunc{wxStreamError}{IsOk}{\void} +\membersection{wxStreamBase::GetLength}\label{wxstreambasegetlength} -Returns true if no error occurred on the stream. +\constfunc{wxFileOffset}{GetLength}{\void} -\wxheading{See also} +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 +\texttt{wxInvalidOffset}. + +\newsince{2.5.4} -\helpref{GetLastError}{wxstreambasegetlasterror} \membersection{wxStreamBase::GetLastError}\label{wxstreambasegetlasterror} @@ -63,6 +67,33 @@ This function returns the last error. \twocolitem{{\bf wxSTREAM\_READ\_ERROR}}{A generic error occurred on the last read call.} \end{twocollist} + +\membersection{wxStreamBase::GetSize}\label{wxstreambasegetsize} + +\constfunc{size\_t}{GetSize}{\void} + +\deprecated{\helpref{GetLength}{wxstreambasegetlength}} + +This function returns the size of the stream. For example, for a file it is the +size of the file. + +\wxheading{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. + + +\membersection{wxStreamBase::IsOk}\label{wxstreambaseisok} + +\constfunc{wxStreamError}{IsOk}{\void} + +Returns true if no error occurred on the stream. + +\wxheading{See also} + +\helpref{GetLastError}{wxstreambasegetlasterror} + + \membersection{wxStreamBase::OnSysRead}\label{wxstreambaseonsysread} \func{size\_t}{OnSysRead}{\param{void*}{ buffer}, \param{size\_t}{ bufsize}} @@ -70,6 +101,7 @@ This function returns the last error. 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. + \membersection{wxStreamBase::OnSysSeek}\label{wxstreambaseonsysseek} \func{off\_t}{OnSysSeek}{\param{off\_t}{ pos}, \param{wxSeekMode}{ mode}} @@ -77,6 +109,7 @@ specified size. It should return the size that was actually read. Internal function. It is called when the stream needs to change the current position. + \membersection{wxStreamBase::OnSysTell}\label{wxstreambaseonsystell} \constfunc{off\_t}{OnSysTell}{\void} @@ -84,21 +117,11 @@ current position. Internal function. Is is called when the stream needs to know the real position. + \membersection{wxStreamBase::OnSysWrite}\label{wxstreambaseonsyswrite} \func{size\_t}{OnSysWrite}{\param{void *}{buffer}, \param{size\_t}{ bufsize}} See \helpref{OnSysRead}{wxstreambaseonsysread}. -\membersection{wxStreamBase::GetSize}\label{wxstreambasegetsize} - -\constfunc{size\_t}{GetSize}{\void} - -This function returns the size of the stream. For example, for a file it is the size of -the file. - -\wxheading{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. diff --git a/include/wx/mstream.h b/include/wx/mstream.h index dbbaba2799..525c6d9ccc 100644 --- a/include/wx/mstream.h +++ b/include/wx/mstream.h @@ -21,7 +21,7 @@ class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream public: wxMemoryInputStream(const void *data, size_t length); virtual ~wxMemoryInputStream(); - virtual size_t GetSize() const { return m_length; } + virtual wxFileOffset GetLength() const { return m_length; } virtual bool Eof() const; char Peek(); @@ -50,7 +50,7 @@ public: // if data is !NULL it must be allocated with malloc() wxMemoryOutputStream(void *data = NULL, size_t length = 0); virtual ~wxMemoryOutputStream(); - virtual size_t GetSize() const { return m_o_streambuf->GetLastAccess(); } + virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); } size_t CopyTo(void *buffer, size_t len) const; diff --git a/include/wx/sstream.h b/include/wx/sstream.h index 0d44a30d82..9926e33700 100644 --- a/include/wx/sstream.h +++ b/include/wx/sstream.h @@ -31,7 +31,7 @@ public: m_pos = 0; } - virtual size_t GetSize() const { return m_str.length(); } + virtual wxFileOffset GetLength() const { return m_str.length(); } protected: virtual wxFileOffset OnSysSeek(wxFileOffset ofs, wxSeekMode mode); diff --git a/include/wx/stream.h b/include/wx/stream.h index 9f627b9be6..dc574b2200 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -82,7 +82,8 @@ public: void Reset() { m_lasterror = wxSTREAM_NO_ERROR; } // this doesn't make sense for all streams, always test its return value - virtual size_t GetSize() const { return 0; } + virtual size_t GetSize() const; + virtual wxFileOffset GetLength() const { return wxInvalidOffset; } #if WXWIN_COMPATIBILITY_2_2 // deprecated, for compatibility only @@ -283,7 +284,7 @@ class WXDLLIMPEXP_BASE wxCountingOutputStream : public wxOutputStream public: wxCountingOutputStream(); - size_t GetSize() const; + wxFileOffset GetLength() const; bool Ok() const { return true; } protected: @@ -309,7 +310,7 @@ public: char Peek() { return m_parent_i_stream->Peek(); } - size_t GetSize() const { return m_parent_i_stream->GetSize(); } + wxFileOffset GetLength() const { return m_parent_i_stream->GetLength(); } wxInputStream *GetFilterInputStream() const { return m_parent_i_stream; } @@ -326,7 +327,7 @@ public: wxFilterOutputStream(wxOutputStream& stream); virtual ~wxFilterOutputStream(); - size_t GetSize() const { return m_parent_o_stream->GetSize(); } + wxFileOffset GetLength() const { return m_parent_o_stream->GetLength(); } wxOutputStream *GetFilterOutputStream() const { return m_parent_o_stream; } @@ -515,7 +516,7 @@ public: void Sync(); - size_t GetSize() const; + wxFileOffset GetLength() const; // the buffer given to the stream will be deleted by it void SetOutputStreamBuffer(wxStreamBuffer *buffer); diff --git a/include/wx/wfstream.h b/include/wx/wfstream.h index a38322818f..514d795fff 100644 --- a/include/wx/wfstream.h +++ b/include/wx/wfstream.h @@ -37,7 +37,7 @@ class WXDLLIMPEXP_BASE wxFileInputStream: public wxInputStream { wxFileInputStream(int fd); ~wxFileInputStream(); - size_t GetSize() const; + wxFileOffset GetLength() const; bool Ok() const { return m_file->IsOpened(); } @@ -67,7 +67,7 @@ class WXDLLIMPEXP_BASE wxFileOutputStream: public wxOutputStream { // { return wxOutputStream::Write(buffer, size); } void Sync(); - size_t GetSize() const; + wxFileOffset GetLength() const; bool Ok() const { return m_file->IsOpened(); } @@ -106,7 +106,7 @@ class WXDLLIMPEXP_BASE wxFFileInputStream: public wxInputStream { wxFFileInputStream(FILE *file); ~wxFFileInputStream(); - size_t GetSize() const; + wxFileOffset GetLength() const; bool Ok() const { return m_file->IsOpened(); } @@ -136,7 +136,7 @@ class WXDLLIMPEXP_BASE wxFFileOutputStream: public wxOutputStream { // { return wxOutputStream::Write(buffer, size); } void Sync(); - size_t GetSize() const; + wxFileOffset GetLength() const; bool Ok() const { return m_file->IsOpened(); } diff --git a/include/wx/zipstrm.h b/include/wx/zipstrm.h index 489a73020d..632963b888 100644 --- a/include/wx/zipstrm.h +++ b/include/wx/zipstrm.h @@ -34,7 +34,7 @@ public: // Remember that archive must be local file accesible via fopen, fread functions! ~wxZipInputStream(); - virtual size_t GetSize() const {return m_Size;} + virtual wxFileOffset GetLength() const {return m_Size;} virtual bool Eof() const; protected: @@ -43,7 +43,7 @@ protected: virtual wxFileOffset OnSysTell() const {return m_Pos;} private: - size_t m_Size; + wxFileOffset m_Size; wxFileOffset m_Pos; // this void* is handle of archive . I'm sorry it is void and not proper diff --git a/include/wx/zstream.h b/include/wx/zstream.h index 7086472a21..1723d93702 100644 --- a/include/wx/zstream.h +++ b/include/wx/zstream.h @@ -46,7 +46,7 @@ class WXDLLIMPEXP_BASE wxZlibInputStream: public wxFilterInputStream { virtual ~wxZlibInputStream(); char Peek() { return wxInputStream::Peek(); } - size_t GetSize() const { return wxInputStream::GetSize(); } + wxFileOffset GetLength() const { return wxInputStream::GetLength(); } static bool CanHandleGZip(); @@ -72,7 +72,7 @@ class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream { virtual ~wxZlibOutputStream(); void Sync() { DoFlush(false); } - size_t GetSize() const { return (size_t)m_pos; } + wxFileOffset GetLength() const { return m_pos; } static bool CanHandleGZip(); diff --git a/src/common/stream.cpp b/src/common/stream.cpp index f1d432eb69..b2154a2d59 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -657,6 +657,12 @@ wxStreamBase::~wxStreamBase() { } +size_t wxStreamBase::GetSize() const +{ + wxFileOffset length = GetLength(); + return length == wxInvalidOffset ? 0 : (size_t)length; +} + wxFileOffset wxStreamBase::OnSysSeek(wxFileOffset WXUNUSED(seek), wxSeekMode WXUNUSED(mode)) { return wxInvalidOffset; @@ -957,7 +963,7 @@ wxCountingOutputStream::wxCountingOutputStream () m_currentPos = 0; } -size_t wxCountingOutputStream::GetSize() const +wxFileOffset wxCountingOutputStream::GetLength() const { return m_lastcount; } @@ -1218,9 +1224,9 @@ wxFileOffset wxBufferedOutputStream::OnSysTell() const return m_parent_o_stream->TellO(); } -size_t wxBufferedOutputStream::GetSize() const +wxFileOffset wxBufferedOutputStream::GetLength() const { - return m_parent_o_stream->GetSize() + m_o_streambuf->GetIntPosition(); + return m_parent_o_stream->GetLength() + m_o_streambuf->GetIntPosition(); } void wxBufferedOutputStream::SetOutputStreamBuffer(wxStreamBuffer *buffer) diff --git a/src/common/wfstream.cpp b/src/common/wfstream.cpp index a1b94af437..8e731791bf 100644 --- a/src/common/wfstream.cpp +++ b/src/common/wfstream.cpp @@ -62,7 +62,7 @@ wxFileInputStream::~wxFileInputStream() delete m_file; } -size_t wxFileInputStream::GetSize() const +wxFileOffset wxFileInputStream::GetLength() const { return m_file->Length(); } @@ -176,7 +176,7 @@ void wxFileOutputStream::Sync() m_file->Flush(); } -size_t wxFileOutputStream::GetSize() const +wxFileOffset wxFileOutputStream::GetLength() const { return m_file->Length(); } @@ -227,7 +227,7 @@ wxFFileInputStream::~wxFFileInputStream() delete m_file; } -size_t wxFFileInputStream::GetSize() const +wxFileOffset wxFFileInputStream::GetLength() const { return m_file->Length(); } @@ -343,7 +343,7 @@ void wxFFileOutputStream::Sync() m_file->Flush(); } -size_t wxFFileOutputStream::GetSize() const +wxFileOffset wxFFileOutputStream::GetLength() const { return m_file->Length(); } diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 6bf4f2aed3..93048447e3 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -60,7 +60,7 @@ wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file m_lasterror = wxSTREAM_READ_ERROR; return; } - m_Size = (size_t)zinfo.uncompressed_size; + m_Size = zinfo.uncompressed_size; } @@ -77,25 +77,25 @@ wxZipInputStream::~wxZipInputStream() bool wxZipInputStream::Eof() const { - wxASSERT_MSG( m_Pos <= (wxFileOffset)m_Size, + wxASSERT_MSG( m_Pos <= m_Size, _T("wxZipInputStream: invalid current position") ); - return m_Pos >= (wxFileOffset)m_Size; + return m_Pos >= m_Size; } size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize) { - wxASSERT_MSG( m_Pos <= (wxFileOffset)m_Size, + wxASSERT_MSG( m_Pos <= m_Size, _T("wxZipInputStream: invalid current position") ); - if ( m_Pos >= (wxFileOffset)m_Size ) + if ( m_Pos >= m_Size ) { m_lasterror = wxSTREAM_EOF; return 0; } - if (m_Pos + bufsize > m_Size) + if (m_Pos + bufsize > m_Size + (size_t)0) bufsize = m_Size - m_Pos; unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize); diff --git a/wxPython/include/wx/wxPython/pyistream.h b/wxPython/include/wx/wxPython/pyistream.h index 793315adaf..65d8d81589 100644 --- a/wxPython/include/wx/wxPython/pyistream.h +++ b/wxPython/include/wx/wxPython/pyistream.h @@ -69,7 +69,7 @@ public: class wxPyCBInputStream : public wxInputStream { public: ~wxPyCBInputStream(); - virtual size_t GetSize() const; + virtual wxFileOffset GetLength() const; // factory function static wxPyCBInputStream* create(PyObject *py, bool block=true); diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index aa4ebd2986..ae0ace5dc5 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -1385,7 +1385,7 @@ PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) { } -size_t wxPyCBInputStream::GetSize() const { +wxFileOffset wxPyCBInputStream::GetLength() const { wxPyCBInputStream* self = (wxPyCBInputStream*)this; // cast off const if (m_seek && m_tell) { wxFileOffset temp = self->OnSysTell(); @@ -1394,7 +1394,7 @@ size_t wxPyCBInputStream::GetSize() const { return ret; } else - return 0; + return wxInvalidOffset; }