all repos — mgba @ 0cf138775b2169241c54447a75e6032c0d4684bb

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 QString&, QIODevice::OpenMode, QObject* parent = nullptr);
23
24	virtual void close() override;
25	virtual bool seek(qint64 pos) override;
26	virtual qint64 size() const override;
27
28	bool resize(qint64 sz);
29
30	VFileDevice& operator=(VFile*);
31	operator VFile*() { return m_vf; }
32
33	static VFile* wrap(QIODevice*, QIODevice::OpenMode);
34	static VFile* wrap(QFileDevice*, QIODevice::OpenMode);
35	static VFile* wrap(QBuffer*, QIODevice::OpenMode);
36
37	static VFile* open(const QString& path, int mode);
38	static VFile* openMemory();
39	static VDir* openDir(const QString& path);
40	static VDir* openArchive(const QString& path);
41
42protected:
43	virtual qint64 readData(char* data, qint64 maxSize) override;
44	virtual qint64 writeData(const char* data, qint64 maxSize) override;
45
46private:
47	VFile* m_vf;
48};
49
50}