2011-03-25 05:06:49 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-12-11 06:41:42 +00:00
|
|
|
#include <wx/stream.h>
|
2011-03-25 05:06:49 +00:00
|
|
|
#include "wx/filefn.h"
|
2016-01-27 17:51:08 +00:00
|
|
|
#include <memory>
|
2020-12-11 06:41:42 +00:00
|
|
|
#include "Dependencies.h"
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxStreamBase
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
class pxStreamBase
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
DeclareNoncopyableObject(pxStreamBase);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
protected:
|
2016-11-12 15:28:37 +00:00
|
|
|
// Filename of the stream, provided by the creator/caller. This is typically used *only*
|
|
|
|
// for generating comprehensive error messages when an error occurs (the stream name is
|
|
|
|
// passed to the exception handlers).
|
|
|
|
wxString m_filename;
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
public:
|
2016-11-12 15:28:37 +00:00
|
|
|
pxStreamBase(const wxString &filename);
|
2017-05-06 12:53:02 +00:00
|
|
|
virtual ~pxStreamBase() = default;
|
2016-11-12 15:28:37 +00:00
|
|
|
|
|
|
|
// Implementing classes should return the base wxStream object (usually either a wxInputStream
|
|
|
|
// or wxOputStream derivative).
|
|
|
|
virtual wxStreamBase *GetWxStreamBase() const = 0;
|
|
|
|
virtual void Close() = 0;
|
|
|
|
virtual wxFileOffset Tell() const = 0;
|
|
|
|
virtual wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart) = 0;
|
|
|
|
|
|
|
|
virtual wxFileOffset Length() const;
|
|
|
|
bool IsOk() const;
|
|
|
|
wxString GetStreamName() const { return m_filename; }
|
2011-03-25 05:06:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxOutputStream
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
class pxOutputStream : public pxStreamBase
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
DeclareNoncopyableObject(pxOutputStream);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
protected:
|
2016-11-12 15:28:37 +00:00
|
|
|
std::unique_ptr<wxOutputStream> m_stream_out;
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
public:
|
2016-11-12 15:28:37 +00:00
|
|
|
pxOutputStream(const wxString &filename, std::unique_ptr<wxOutputStream> &output);
|
|
|
|
pxOutputStream(const wxString &filename, wxOutputStream *output);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2017-05-06 12:53:02 +00:00
|
|
|
virtual ~pxOutputStream() = default;
|
2016-11-12 15:28:37 +00:00
|
|
|
virtual void Write(const void *data, size_t size);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
void SetStream(const wxString &filename, std::unique_ptr<wxOutputStream> &stream);
|
|
|
|
void SetStream(const wxString &filename, wxOutputStream *stream);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
void Close() { m_stream_out = nullptr; }
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
virtual wxStreamBase *GetWxStreamBase() const;
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template <typename T>
|
|
|
|
void Write(const T &data)
|
|
|
|
{
|
|
|
|
Write(&data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileOffset Tell() const;
|
|
|
|
wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
|
2011-03-25 05:06:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxInputStream
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
class pxInputStream : public pxStreamBase
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
DeclareNoncopyableObject(pxInputStream);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
protected:
|
2016-11-12 15:28:37 +00:00
|
|
|
std::unique_ptr<wxInputStream> m_stream_in;
|
2011-03-25 05:06:49 +00:00
|
|
|
|
|
|
|
public:
|
2016-11-12 15:28:37 +00:00
|
|
|
pxInputStream(const wxString &filename, std::unique_ptr<wxInputStream> &input);
|
|
|
|
pxInputStream(const wxString &filename, wxInputStream *input);
|
|
|
|
|
2017-05-06 12:53:02 +00:00
|
|
|
virtual ~pxInputStream() = default;
|
2016-11-12 15:28:37 +00:00
|
|
|
virtual void Read(void *dest, size_t size);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
void SetStream(const wxString &filename, std::unique_ptr<wxInputStream> &stream);
|
|
|
|
void SetStream(const wxString &filename, wxInputStream *stream);
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
void Close() { m_stream_in = nullptr; }
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
virtual wxStreamBase *GetWxStreamBase() const;
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template <typename T>
|
|
|
|
void Read(T &dest)
|
|
|
|
{
|
|
|
|
Read(&dest, sizeof(dest));
|
|
|
|
}
|
2011-03-25 05:06:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
wxFileOffset Tell() const;
|
|
|
|
wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
|
2011-03-25 05:06:49 +00:00
|
|
|
};
|