Update on main system framework
This commit is contained in:
parent
1ef4044479
commit
43aefada4c
2 changed files with 105 additions and 2 deletions
|
|
@ -1,6 +1,84 @@
|
||||||
#include "apparatus.h"
|
#include "apparatus.h"
|
||||||
|
|
||||||
apparatus::apparatus()
|
|
||||||
{
|
apparatus *apparatus::_instance = nullptr;
|
||||||
|
|
||||||
|
void apparatus::open_reading_stream() {
|
||||||
|
this->_bin_file = new QFile("data.bin");
|
||||||
|
this->_bin_file->open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
stream.setDevice(_bin_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::open_writing_stream() {
|
||||||
|
this->_bin_file = new QFile("data.bin");
|
||||||
|
this->_bin_file->open(QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
stream.setDevice(_bin_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::close_stream() {
|
||||||
|
stream.setDevice(nullptr);
|
||||||
|
|
||||||
|
this->_bin_file->close();
|
||||||
|
delete this->_bin_file;
|
||||||
|
this->_bin_file = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
apparatus::apparatus() {
|
||||||
|
this->open_reading_stream();
|
||||||
|
this->loadGIDS();
|
||||||
|
this->deserialize_data();
|
||||||
|
this->close_stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
apparatus::~apparatus() {
|
||||||
|
if (this->_bin_file) {
|
||||||
|
this->_bin_file->flush();
|
||||||
|
this->_bin_file->close();
|
||||||
|
delete this->_bin_file;
|
||||||
|
this->_bin_file = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apparatus& apparatus::instance() {
|
||||||
|
if (apparatus::_instance == nullptr) {
|
||||||
|
apparatus::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *apparatus::_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::init() {
|
||||||
|
apparatus::_instance = new apparatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::shutdown() {
|
||||||
|
if (apparatus::_instance != nullptr) {
|
||||||
|
apparatus::_instance->open_writing_stream();
|
||||||
|
apparatus::_instance->writeGIDS();
|
||||||
|
apparatus::_instance->serialize_data();
|
||||||
|
apparatus::_instance->close_stream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::writeGIDS() {
|
||||||
|
entity_id vgid = vessel_entity::GID();
|
||||||
|
entity_id sgid = storage_entity::GID();
|
||||||
|
this->stream << vgid << sgid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::loadGIDS() {
|
||||||
|
entity_id vgid, sgid;
|
||||||
|
this->stream >> vgid >> sgid;
|
||||||
|
vessel_entity::preloadGlobalId(vgid);
|
||||||
|
storage_entity::preloadGlobalId(sgid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::serialize_data() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void apparatus::deserialize_data() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,36 @@
|
||||||
#ifndef APPARATUS_H
|
#ifndef APPARATUS_H
|
||||||
#define APPARATUS_H
|
#define APPARATUS_H
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDataStream>
|
||||||
|
|
||||||
|
|
||||||
class apparatus
|
class apparatus
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
static apparatus *_instance;
|
||||||
|
|
||||||
|
QFile _bin_file;
|
||||||
|
QDataStream stream;
|
||||||
|
|
||||||
|
void open_reading_stream();
|
||||||
|
void close_reading_stream();
|
||||||
|
|
||||||
|
void open_writing_stream();
|
||||||
|
void close_writing_stream();
|
||||||
|
|
||||||
|
void writeGIDS();
|
||||||
|
void loadGIDS();
|
||||||
|
|
||||||
|
void serialize_data();
|
||||||
|
void deserialize_data();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
apparatus();
|
apparatus();
|
||||||
|
|
||||||
|
static apparatus& instance();
|
||||||
|
static void init();
|
||||||
|
static void shutdown();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPARATUS_H
|
#endif // APPARATUS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue