Abstraction and serialization for entities
This commit is contained in:
parent
5cb96fb793
commit
48ad2f1817
13 changed files with 106 additions and 12 deletions
12
entities/IEntity.h
Normal file
12
entities/IEntity.h
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef IENTITY_H
|
||||||
|
#define IENTITY_H
|
||||||
|
|
||||||
|
#include "ISerializable.h"
|
||||||
|
|
||||||
|
|
||||||
|
class IEntity : public ISerializable {
|
||||||
|
public:
|
||||||
|
virtual unsigned long long id() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IENTITY_H
|
||||||
23
entities/ISerializable.h
Normal file
23
entities/ISerializable.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef ISERIALIZABLE_H
|
||||||
|
#define ISERIALIZABLE_H
|
||||||
|
|
||||||
|
#include <QDataStream>
|
||||||
|
|
||||||
|
|
||||||
|
class ISerializable {
|
||||||
|
public:
|
||||||
|
virtual void serialize(QDataStream &output) = 0;
|
||||||
|
virtual void deserialize(QDataStream &input) = 0;
|
||||||
|
|
||||||
|
friend QDataStream &operator<<(QDataStream &output, ISerializable &s) {
|
||||||
|
s.serialize(output);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend QDataStream &operator>>(QDataStream &input, ISerializable &s) {
|
||||||
|
s.deserialize(input);
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ISERIALIZABLE_H
|
||||||
|
|
@ -19,3 +19,11 @@ QString cargo_entity::title() {
|
||||||
unsigned int cargo_entity::volume() {
|
unsigned int cargo_entity::volume() {
|
||||||
return this->_volume;
|
return this->_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cargo_entity::serialize(QDataStream &output) {
|
||||||
|
output << this->_id << this->_title << this->_volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cargo_entity::deserialize(QDataStream &input) {
|
||||||
|
input >> this->_id >> this->_title >> this->_volume;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
#ifndef CARGO_ENTITY_H
|
#ifndef CARGO_ENTITY_H
|
||||||
#define CARGO_ENTITY_H
|
#define CARGO_ENTITY_H
|
||||||
|
|
||||||
|
#include "IEntity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
class cargo_entity
|
class cargo_entity : public IEntity {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
unsigned long long _id;
|
unsigned long long _id;
|
||||||
QString _title;
|
QString _title;
|
||||||
|
|
@ -19,6 +20,9 @@ public:
|
||||||
unsigned long long id();
|
unsigned long long id();
|
||||||
QString title();
|
QString title();
|
||||||
unsigned int volume();
|
unsigned int volume();
|
||||||
|
|
||||||
|
void serialize(QDataStream &output);
|
||||||
|
void deserialize(QDataStream &input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARGO_ENTITY_H
|
#endif // CARGO_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,11 @@ QString dpoint_entity::title() {
|
||||||
const QVector<unsigned long long> dpoint_entity::storages_ids() {
|
const QVector<unsigned long long> dpoint_entity::storages_ids() {
|
||||||
return this->_storages_ids;
|
return this->_storages_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::serialize(QDataStream &output) {
|
||||||
|
output << this->_id << this->_title << this->_storages_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::deserialize(QDataStream &input) {
|
||||||
|
input >> this->_id >> this->_title >> this->_storages_ids;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
#ifndef DPOINT_ENTITY_H
|
#ifndef DPOINT_ENTITY_H
|
||||||
#define DPOINT_ENTITY_H
|
#define DPOINT_ENTITY_H
|
||||||
|
|
||||||
|
#include "IEntity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
class dpoint_entity
|
class dpoint_entity : public IEntity {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
unsigned long long _id;
|
unsigned long long _id;
|
||||||
QString _title;
|
QString _title;
|
||||||
|
|
@ -20,6 +21,9 @@ public:
|
||||||
unsigned long long id();
|
unsigned long long id();
|
||||||
QString title();
|
QString title();
|
||||||
const QVector<unsigned long long> storages_ids();
|
const QVector<unsigned long long> storages_ids();
|
||||||
|
|
||||||
|
void serialize(QDataStream &output);
|
||||||
|
void deserialize(QDataStream &input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DPOINT_ENTITY_H
|
#endif // DPOINT_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,11 @@ unsigned int storage_entity::capacity() {
|
||||||
const QVector<cargo_entity> storage_entity::cargo() {
|
const QVector<cargo_entity> storage_entity::cargo() {
|
||||||
return this->_cargo;
|
return this->_cargo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storage_entity::serialize(QDataStream &output) {
|
||||||
|
output << this->_id << this->_capacity << this->_cargo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void storage_entity::deserialize(QDataStream &input) {
|
||||||
|
input >> this->_id >> this->_capacity >> this->_cargo;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
#ifndef STORAGE_ENTITY_H
|
#ifndef STORAGE_ENTITY_H
|
||||||
#define STORAGE_ENTITY_H
|
#define STORAGE_ENTITY_H
|
||||||
|
|
||||||
|
#include "IEntity.h"
|
||||||
#include "cargo_entity.h"
|
#include "cargo_entity.h"
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
class storage_entity
|
class storage_entity : public IEntity {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
static unsigned long long __global_id;
|
static unsigned long long __global_id;
|
||||||
|
|
||||||
|
|
@ -23,6 +23,9 @@ public:
|
||||||
unsigned long long id();
|
unsigned long long id();
|
||||||
unsigned int capacity();
|
unsigned int capacity();
|
||||||
const QVector<cargo_entity> cargo();
|
const QVector<cargo_entity> cargo();
|
||||||
|
|
||||||
|
void serialize(QDataStream &output);
|
||||||
|
void deserialize(QDataStream &input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STORAGE_ENTITY_H
|
#endif // STORAGE_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "user_entity.h"
|
#include "user_entity.h"
|
||||||
|
|
||||||
user_entity::user_entity(const QString &login, const QString &password, UserRole role) {
|
user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) {
|
||||||
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,3 +19,11 @@ UserRole user_entity::role() {
|
||||||
bool user_entity::verify_password(const QString &password) {
|
bool user_entity::verify_password(const QString &password) {
|
||||||
return (this->_pwd_hash == QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256));
|
return (this->_pwd_hash == QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void user_entity::serialize(QDataStream &output) {
|
||||||
|
output << this->_id << this->_login << this->_role << this->_pwd_hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
void user_entity::deserialize(QDataStream &input) {
|
||||||
|
input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef USER_ENTITY_H
|
#ifndef USER_ENTITY_H
|
||||||
#define USER_ENTITY_H
|
#define USER_ENTITY_H
|
||||||
|
|
||||||
|
#include "IEntity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
@ -10,8 +12,7 @@ enum class UserRole {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class user_entity
|
class user_entity : public IEntity {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
unsigned long long _id;
|
unsigned long long _id;
|
||||||
QString _login;
|
QString _login;
|
||||||
|
|
@ -26,6 +27,9 @@ public:
|
||||||
const QString login();
|
const QString login();
|
||||||
UserRole role();
|
UserRole role();
|
||||||
bool verify_password(const QString &password);
|
bool verify_password(const QString &password);
|
||||||
|
|
||||||
|
void serialize(QDataStream &output);
|
||||||
|
void deserialize(QDataStream &input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USER_ENTITY_H
|
#endif // USER_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,11 @@ unsigned int vessel_entity::capacity() {
|
||||||
const QVector<cargo_entity> vessel_entity::cargo() {
|
const QVector<cargo_entity> vessel_entity::cargo() {
|
||||||
return this->_cargo;
|
return this->_cargo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vessel_entity::serialize(QDataStream &output) {
|
||||||
|
output << this->_id << this->_harbor << this->_capacity << this->_cargo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vessel_entity::deserialize(QDataStream &input) {
|
||||||
|
input >> this->_id >> this->_harbor >> this->_capacity >> this->_cargo;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
#ifndef VESSEL_ENTITY_H
|
#ifndef VESSEL_ENTITY_H
|
||||||
#define VESSEL_ENTITY_H
|
#define VESSEL_ENTITY_H
|
||||||
|
|
||||||
|
#include "IEntity.h"
|
||||||
#include "cargo_entity.h"
|
#include "cargo_entity.h"
|
||||||
#include "dpoint_entity.h"
|
#include "dpoint_entity.h"
|
||||||
|
|
||||||
|
|
||||||
|
class vessel_entity : public IEntity {
|
||||||
class vessel_entity
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
static unsigned long long __global_id;
|
static unsigned long long __global_id;
|
||||||
|
|
||||||
|
|
@ -24,6 +23,9 @@ public:
|
||||||
const dpoint_entity harbor();
|
const dpoint_entity harbor();
|
||||||
unsigned int capacity();
|
unsigned int capacity();
|
||||||
const QVector<cargo_entity> cargo();
|
const QVector<cargo_entity> cargo();
|
||||||
|
|
||||||
|
void serialize(QDataStream &output);
|
||||||
|
void deserialize(QDataStream &input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VESSEL_ENTITY_H
|
#endif // VESSEL_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ HEADERS += \
|
||||||
authwindow.h \
|
authwindow.h \
|
||||||
cargoeditdialog.h \
|
cargoeditdialog.h \
|
||||||
deliverypointeditdialog.h \
|
deliverypointeditdialog.h \
|
||||||
|
entities/IEntity.h \
|
||||||
|
entities/ISerializable.h \
|
||||||
entities/cargo_entity.h \
|
entities/cargo_entity.h \
|
||||||
entities/dpoint_entity.h \
|
entities/dpoint_entity.h \
|
||||||
entities/storage_entity.h \
|
entities/storage_entity.h \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue