all repos — mgba @ 88212fc2deb72b3ab85313852b0b091edc88403b

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