Fix return value of wxCountingOutputStream::LastWrite().
Don't reuse m_lastcount in wxCountingOutputStream to store the stream length, this doesn't make any sense and results in LastWrite() returning completely wrong results as it expects m_lastcount to be the number of bytes written by the last operation. Add m_lastPos member to store the stream length instead. Also correct wxCountingOutputStream documentation. Closes #15215. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74036 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0f5378d414
commit
9bc3af3e64
@ -577,6 +577,7 @@ All:
|
|||||||
- Allow testing for symlink/FIFO/socket existence in wxFileName (David Hart).
|
- Allow testing for symlink/FIFO/socket existence in wxFileName (David Hart).
|
||||||
- Many important bug fixes in wxFileSystemWatcher (David Hart).
|
- Many important bug fixes in wxFileSystemWatcher (David Hart).
|
||||||
- Add wxInputStream::ReadAll() and wxOutputStream::WriteAll() (Catalin Raceanu).
|
- Add wxInputStream::ReadAll() and wxOutputStream::WriteAll() (Catalin Raceanu).
|
||||||
|
- Fix wxCountingOutputStream::LastWrite() return value (Catalin Raceanu).
|
||||||
- Add new wxFSW_EVENT_ATTRIB and wxFSW_EVENT_UNMOUNT flags (David Hart).
|
- Add new wxFSW_EVENT_ATTRIB and wxFSW_EVENT_UNMOUNT flags (David Hart).
|
||||||
- Add separate read/written bytes counters and per-direction NOWAIT and WAITALL
|
- Add separate read/written bytes counters and per-direction NOWAIT and WAITALL
|
||||||
flags to wxSocket (Rob Bresalier).
|
flags to wxSocket (Rob Bresalier).
|
||||||
|
@ -281,16 +281,17 @@ class WXDLLIMPEXP_BASE wxCountingOutputStream : public wxOutputStream
|
|||||||
public:
|
public:
|
||||||
wxCountingOutputStream();
|
wxCountingOutputStream();
|
||||||
|
|
||||||
wxFileOffset GetLength() const;
|
virtual wxFileOffset GetLength() const;
|
||||||
bool Ok() const { return IsOk(); }
|
bool Ok() const { return IsOk(); }
|
||||||
bool IsOk() const { return true; }
|
virtual bool IsOk() const { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual size_t OnSysWrite(const void *buffer, size_t size);
|
virtual size_t OnSysWrite(const void *buffer, size_t size);
|
||||||
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
|
||||||
virtual wxFileOffset OnSysTell() const;
|
virtual wxFileOffset OnSysTell() const;
|
||||||
|
|
||||||
size_t m_currentPos;
|
size_t m_currentPos,
|
||||||
|
m_lastPos;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxCountingOutputStream)
|
DECLARE_DYNAMIC_CLASS(wxCountingOutputStream)
|
||||||
wxDECLARE_NO_COPY_CLASS(wxCountingOutputStream);
|
wxDECLARE_NO_COPY_CLASS(wxCountingOutputStream);
|
||||||
|
@ -753,9 +753,11 @@ public:
|
|||||||
virtual ~wxCountingOutputStream();
|
virtual ~wxCountingOutputStream();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the current size of the stream.
|
Returns the current length of the stream.
|
||||||
|
|
||||||
|
This is the amount of data written to the stream so far, in bytes.
|
||||||
*/
|
*/
|
||||||
size_t GetSize() const;
|
virtual wxFileOffset GetLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1117,22 +1117,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxCountingOutputStream, wxOutputStream)
|
|||||||
|
|
||||||
wxCountingOutputStream::wxCountingOutputStream ()
|
wxCountingOutputStream::wxCountingOutputStream ()
|
||||||
{
|
{
|
||||||
m_currentPos = 0;
|
m_currentPos =
|
||||||
|
m_lastPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOffset wxCountingOutputStream::GetLength() const
|
wxFileOffset wxCountingOutputStream::GetLength() const
|
||||||
{
|
{
|
||||||
return m_lastcount;
|
return m_lastPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer),
|
size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer),
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
m_currentPos += size;
|
m_currentPos += size;
|
||||||
if (m_currentPos > m_lastcount)
|
if ( m_currentPos > m_lastPos )
|
||||||
m_lastcount = m_currentPos;
|
m_lastPos = m_currentPos;
|
||||||
|
|
||||||
return m_currentPos;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
||||||
@ -1146,12 +1147,12 @@ wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFromEnd:
|
case wxFromEnd:
|
||||||
new_pos = m_lastcount + new_pos;
|
new_pos += m_lastPos;
|
||||||
wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastcount + pos), wxInvalidOffset, wxT("huge position not supported") );
|
wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastPos + pos), wxInvalidOffset, wxT("huge position not supported") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFromCurrent:
|
case wxFromCurrent:
|
||||||
new_pos = m_currentPos + new_pos;
|
new_pos += m_currentPos;
|
||||||
wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_currentPos + pos), wxInvalidOffset, wxT("huge position not supported") );
|
wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_currentPos + pos), wxInvalidOffset, wxT("huge position not supported") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1162,8 +1163,8 @@ wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode
|
|||||||
|
|
||||||
m_currentPos = new_pos;
|
m_currentPos = new_pos;
|
||||||
|
|
||||||
if (m_currentPos > m_lastcount)
|
if ( m_currentPos > m_lastPos )
|
||||||
m_lastcount = m_currentPos;
|
m_lastPos = m_currentPos;
|
||||||
|
|
||||||
return m_currentPos;
|
return m_currentPos;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user