-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonfile.hpp
52 lines (40 loc) · 1.3 KB
/
jsonfile.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <QtCore>
#include "file.hpp"
#include "world.hpp"
namespace Headway
{
/*! \brief Reads and writes Headway::World objects from/to json files.
*/
class JsonFile : public File
{
public:
/*! \brief Reads data from json file.
*
* \param filePath Location of json file.
* \throw FileException if file cannot be loaded.
*/
explicit JsonFile(const QString& filePath);
quint32 readWidth() const override { return width; }
quint32 readHeight() const override { return height; }
quint64 readGenerations() const override { return generations; }
void readCoordinate(quint32& x, quint32& y) override;
bool hasNext() const noexcept override;
void rewind() noexcept override;
/*! \brief Writes data to json file.
*
* \param filePath Location of json file.
* \param biotope World object to save.
*
* \throw FileException if file cannot be saved.
*/
static void write(const QString& filePath, const Headway::World& biotope);
private:
quint32 width;
quint32 height;
quint64 generations = 0;
QJsonDocument document;
QJsonArray cells;
QJsonArray::iterator iterator;
};
}