Add VFileDevice QIODevice subclass
Jeffrey Pfau jeffrey@endrift.com
Tue, 14 Oct 2014 23:14:25 -0700
3 files changed,
59 insertions(+),
1 deletions(-)
M
src/platform/qt/CMakeLists.txt
→
src/platform/qt/CMakeLists.txt
@@ -28,7 +28,8 @@ AudioProcessor.cpp
Display.cpp GameController.cpp LogView.cpp - Window.cpp) + Window.cpp + VFileDevice.cpp) qt5_wrap_ui(UI_FILES LogView.ui)
A
src/platform/qt/VFileDevice.cpp
@@ -0,0 +1,30 @@
+#include "VFileDevice.h" + +extern "C" { +#include "util/vfs.h" +} + +using namespace QGBA; + +VFileDevice::VFileDevice(VFile* vf, QObject* parent) + : QIODevice(parent) + , m_vf(vf) +{ + // Nothing to do +} + +qint64 VFileDevice::readData(char* data, qint64 maxSize) { + return m_vf->read(m_vf, data, maxSize); +} + +qint64 VFileDevice::writeData(const char* data, qint64 maxSize) { + return m_vf->write(m_vf, data, maxSize); +} + +qint64 VFileDevice::size() const { + // TODO: Add size method to VFile so this can be actually const + ssize_t pos = m_vf->seek(m_vf, 0, SEEK_CUR); + qint64 size = m_vf->seek(m_vf, 0, SEEK_END); + m_vf->seek(m_vf, pos, SEEK_SET); + return size; +}
A
src/platform/qt/VFileDevice.h
@@ -0,0 +1,27 @@
+#ifndef QGBA_VFILE_DEVICE +#define QGBA_VFILE_DEVICE + +#include <QFileDevice> + +struct VFile; + +namespace QGBA { + +class VFileDevice : public QIODevice { +Q_OBJECT + +public: + VFileDevice(VFile* vf, QObject* parent = nullptr); + +protected: + virtual qint64 readData(char* data, qint64 maxSize) override; + virtual qint64 writeData(const char* data, qint64 maxSize) override; + virtual qint64 size() const override; + +private: + mutable VFile* m_vf; +}; + +} + +#endif