all repos — mgba @ 517aa353caaa6484a2607d93265c4aafc14997ae

mGBA Game Boy Advance Emulator

src/platform/qt/VFileDevice.h (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#pragma once
 7
 8#include <QFileDevice>
 9
10struct VDir;
11struct VFile;
12
13class QBuffer;
14
15namespace QGBA {
16
17class VFileDevice : public QIODevice {
18Q_OBJECT
19
20public:
21	VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr);
22	VFileDevice(const QByteArray& mem, QObject* parent = nullptr);
23	VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr);
24	virtual ~VFileDevice();
25
26	virtual void close() override;
27	virtual bool seek(qint64 pos) override;
28	virtual qint64 size() const override;
29
30	bool resize(qint64 sz);
31
32	VFileDevice& operator=(VFile*);
33	operator VFile*() { return m_vf; }
34	VFile* take();
35
36	static VFile* wrap(QIODevice*, QIODevice::OpenMode);
37	static VFile* wrap(QFileDevice*, QIODevice::OpenMode);
38	static VFile* wrap(QBuffer*, QIODevice::OpenMode);
39
40	static VFile* open(const QString& path, int mode);
41	static VFile* openMemory();
42	static VDir* openDir(const QString& path);
43	static VDir* openArchive(const QString& path);
44
45protected:
46	virtual qint64 readData(char* data, qint64 maxSize) override;
47	virtual qint64 writeData(const char* data, qint64 maxSize) override;
48
49private:
50	VFile* m_vf;
51};
52
53}