Move project in sub
This commit is contained in:
parent
f868166756
commit
ec1af1b8e5
43 changed files with 358 additions and 2 deletions
14
sea_transport/entities/IEntity.h
Normal file
14
sea_transport/entities/IEntity.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef IENTITY_H
|
||||
#define IENTITY_H
|
||||
|
||||
#include "ISerializable.h"
|
||||
|
||||
|
||||
typedef unsigned long long entity_id;
|
||||
|
||||
class IEntity : public ISerializable {
|
||||
public:
|
||||
virtual entity_id id() = 0;
|
||||
};
|
||||
|
||||
#endif // IENTITY_H
|
||||
13
sea_transport/entities/ISerializable.h
Normal file
13
sea_transport/entities/ISerializable.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef ISERIALIZABLE_H
|
||||
#define ISERIALIZABLE_H
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
|
||||
class ISerializable {
|
||||
public:
|
||||
virtual void serialize(QDataStream &output) = 0;
|
||||
virtual void deserialize(QDataStream &input) = 0;
|
||||
};
|
||||
|
||||
#endif // ISERIALIZABLE_H
|
||||
29
sea_transport/entities/cargo_entity.cpp
Normal file
29
sea_transport/entities/cargo_entity.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "cargo_entity.h"
|
||||
|
||||
cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(title), _volume(volume) {
|
||||
this->_id = volume;
|
||||
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
||||
for (auto bit : hash) {
|
||||
this->_id += bit;
|
||||
}
|
||||
}
|
||||
|
||||
entity_id cargo_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
QString cargo_entity::title() {
|
||||
return this->_title;
|
||||
}
|
||||
|
||||
unsigned int cargo_entity::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;
|
||||
}
|
||||
28
sea_transport/entities/cargo_entity.h
Normal file
28
sea_transport/entities/cargo_entity.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef CARGO_ENTITY_H
|
||||
#define CARGO_ENTITY_H
|
||||
|
||||
#include "IEntity.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
|
||||
class cargo_entity : public IEntity {
|
||||
private:
|
||||
entity_id _id;
|
||||
QString _title;
|
||||
unsigned int _volume;
|
||||
|
||||
public:
|
||||
cargo_entity() = default;
|
||||
cargo_entity(const QString &title, unsigned int volume);
|
||||
|
||||
entity_id id();
|
||||
QString title();
|
||||
unsigned int volume();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
};
|
||||
|
||||
#endif // CARGO_ENTITY_H
|
||||
37
sea_transport/entities/dpoint_entity.cpp
Normal file
37
sea_transport/entities/dpoint_entity.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "dpoint_entity.h"
|
||||
|
||||
dpoint_entity::dpoint_entity(const QString &title) : _title(title) {
|
||||
this->_id = 0;
|
||||
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
||||
for (auto bit : hash) {
|
||||
this->_id += bit;
|
||||
}
|
||||
}
|
||||
|
||||
entity_id dpoint_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
QString dpoint_entity::title() {
|
||||
return this->_title;
|
||||
}
|
||||
|
||||
const QVector<storage_entity> dpoint_entity::storages() {
|
||||
return this->_storages;
|
||||
}
|
||||
|
||||
void dpoint_entity::serialize(QDataStream &output) {
|
||||
output << this->_id << this->_title << this->_storages.size();
|
||||
for (auto &item : this->_storages) {
|
||||
item.serialize(output);
|
||||
}
|
||||
}
|
||||
|
||||
void dpoint_entity::deserialize(QDataStream &input) {
|
||||
int icnt;
|
||||
input >> this->_id >> this->_title >> icnt;
|
||||
this->_storages.resize(icnt);
|
||||
for (int i = 0; i < icnt; i++) {
|
||||
this->_storages[i].deserialize(input);
|
||||
}
|
||||
}
|
||||
30
sea_transport/entities/dpoint_entity.h
Normal file
30
sea_transport/entities/dpoint_entity.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef DPOINT_ENTITY_H
|
||||
#define DPOINT_ENTITY_H
|
||||
|
||||
#include "IEntity.h"
|
||||
#include "storage_entity.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
|
||||
class dpoint_entity : public IEntity {
|
||||
private:
|
||||
entity_id _id;
|
||||
QString _title;
|
||||
QVector<storage_entity> _storages;
|
||||
|
||||
public:
|
||||
dpoint_entity() = default;
|
||||
dpoint_entity(const QString &title);
|
||||
|
||||
entity_id id();
|
||||
QString title();
|
||||
const QVector<storage_entity> storages();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
};
|
||||
|
||||
#endif // DPOINT_ENTITY_H
|
||||
81
sea_transport/entities/storage_entity.cpp
Normal file
81
sea_transport/entities/storage_entity.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "storage_entity.h"
|
||||
|
||||
|
||||
entity_id storage_entity::__global_id = 0;
|
||||
|
||||
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
|
||||
this->_id = ++storage_entity::__global_id;
|
||||
}
|
||||
|
||||
|
||||
entity_id storage_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
unsigned int storage_entity::capacity() {
|
||||
return this->_capacity;
|
||||
}
|
||||
|
||||
const QVector<cargo_entity> storage_entity::cargo() {
|
||||
return this->_cargo;
|
||||
}
|
||||
|
||||
void storage_entity::add_cargo(cargo_entity object, bool &success) {
|
||||
success = ((int)this->_capacity - (int)object.volume()) > 0;
|
||||
if (success) {
|
||||
this->_cargo.push_back(object);
|
||||
this->_capacity -= object.volume();
|
||||
}
|
||||
}
|
||||
|
||||
cargo_entity storage_entity::get_cargo(entity_id oid, bool &found) {
|
||||
cargo_entity ent;
|
||||
found = false;
|
||||
|
||||
auto vit = this->_cargo.begin();
|
||||
for (; vit != this->_cargo.end(); vit++) {
|
||||
if ((*vit).id() == oid) {
|
||||
ent = *vit;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ent;
|
||||
}
|
||||
|
||||
void storage_entity::withdraw_cargo(entity_id oid, bool &success) {
|
||||
success = false;
|
||||
auto vit = this->_cargo.begin();
|
||||
for (; vit != this->_cargo.end(); vit++) {
|
||||
if ((*vit).id() == oid) {
|
||||
this->_capacity += (*vit).volume();
|
||||
this->_cargo.erase(vit);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void storage_entity::serialize(QDataStream &output) {
|
||||
output << this->_id << this->_capacity << this->_cargo.size();
|
||||
for (auto item : this->_cargo) {
|
||||
item.serialize(output);
|
||||
}
|
||||
}
|
||||
|
||||
void storage_entity::deserialize(QDataStream &input) {
|
||||
int icnt;
|
||||
input >> this->_id >> this->_capacity >> icnt;
|
||||
this->_cargo.resize(icnt);
|
||||
for (int i = 0; i < icnt; i++) {
|
||||
this->_cargo[i].deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
void storage_entity::preloadGlobalId(entity_id gid) {
|
||||
storage_entity::__global_id = gid;
|
||||
}
|
||||
|
||||
entity_id storage_entity::GID() {
|
||||
return storage_entity::__global_id;
|
||||
}
|
||||
37
sea_transport/entities/storage_entity.h
Normal file
37
sea_transport/entities/storage_entity.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef STORAGE_ENTITY_H
|
||||
#define STORAGE_ENTITY_H
|
||||
|
||||
#include "IEntity.h"
|
||||
#include "cargo_entity.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
|
||||
class storage_entity : public IEntity {
|
||||
private:
|
||||
static entity_id __global_id;
|
||||
|
||||
entity_id _id;
|
||||
unsigned int _capacity;
|
||||
QVector<cargo_entity> _cargo;
|
||||
|
||||
public:
|
||||
storage_entity() = default;
|
||||
storage_entity(unsigned int capacity);
|
||||
|
||||
entity_id id();
|
||||
unsigned int capacity();
|
||||
const QVector<cargo_entity> cargo();
|
||||
|
||||
void add_cargo(cargo_entity object, bool &success);
|
||||
cargo_entity get_cargo(entity_id oid, bool &found);
|
||||
void withdraw_cargo(entity_id oid, bool &success);
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
static void preloadGlobalId(entity_id gid);
|
||||
static entity_id GID();
|
||||
};
|
||||
|
||||
#endif // STORAGE_ENTITY_H
|
||||
29
sea_transport/entities/user_entity.cpp
Normal file
29
sea_transport/entities/user_entity.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "user_entity.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
entity_id user_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
const QString user_entity::login() {
|
||||
return this->_login;
|
||||
}
|
||||
|
||||
UserRole user_entity::role() {
|
||||
return this->_role;
|
||||
}
|
||||
|
||||
bool user_entity::verify_password(const QString &password) const {
|
||||
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;
|
||||
}
|
||||
35
sea_transport/entities/user_entity.h
Normal file
35
sea_transport/entities/user_entity.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef USER_ENTITY_H
|
||||
#define USER_ENTITY_H
|
||||
|
||||
#include "IEntity.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
|
||||
enum class UserRole {
|
||||
ADMINISTRATOR, DISPATCHER, SKIPPER
|
||||
};
|
||||
|
||||
|
||||
class user_entity : public IEntity {
|
||||
private:
|
||||
entity_id _id;
|
||||
QString _login;
|
||||
UserRole _role;
|
||||
QByteArray _pwd_hash;
|
||||
|
||||
public:
|
||||
user_entity() = default;
|
||||
user_entity(const QString &login, const QString &password, UserRole role);
|
||||
|
||||
entity_id id();
|
||||
const QString login();
|
||||
UserRole role();
|
||||
bool verify_password(const QString &password) const;
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
};
|
||||
|
||||
#endif // USER_ENTITY_H
|
||||
52
sea_transport/entities/vessel_entity.cpp
Normal file
52
sea_transport/entities/vessel_entity.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "vessel_entity.h"
|
||||
|
||||
|
||||
entity_id vessel_entity::__global_id = 0;
|
||||
|
||||
vessel_entity::vessel_entity(const dpoint_entity &harbor, unsigned int capacity) : _harbor(harbor), _capacity(capacity) {
|
||||
this->_id = ++vessel_entity::__global_id;
|
||||
}
|
||||
|
||||
entity_id vessel_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
const dpoint_entity vessel_entity::harbor() {
|
||||
return this->_harbor;
|
||||
}
|
||||
|
||||
unsigned int vessel_entity::capacity() {
|
||||
return this->_capacity;
|
||||
}
|
||||
|
||||
const QVector<cargo_entity> vessel_entity::cargo() {
|
||||
return this->_cargo;
|
||||
}
|
||||
|
||||
void vessel_entity::serialize(QDataStream &output) {
|
||||
output << this->_id;
|
||||
this->_harbor.serialize(output);
|
||||
output << this->_capacity << this->_cargo.size();
|
||||
for (auto item : this->_cargo) {
|
||||
item.serialize(output);
|
||||
}
|
||||
}
|
||||
|
||||
void vessel_entity::deserialize(QDataStream &input) {
|
||||
input >> this->_id;
|
||||
this->_harbor.deserialize(input);
|
||||
int icnt;
|
||||
input >> this->_capacity >> icnt;
|
||||
this->_cargo.resize(icnt);
|
||||
for (int i = 0; i < icnt; i++) {
|
||||
this->_cargo[i].deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
void vessel_entity::preloadGlobalId(entity_id gid) {
|
||||
vessel_entity::__global_id = gid;
|
||||
}
|
||||
|
||||
entity_id vessel_entity::GID() {
|
||||
return vessel_entity::__global_id;
|
||||
}
|
||||
33
sea_transport/entities/vessel_entity.h
Normal file
33
sea_transport/entities/vessel_entity.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef VESSEL_ENTITY_H
|
||||
#define VESSEL_ENTITY_H
|
||||
|
||||
#include "IEntity.h"
|
||||
#include "cargo_entity.h"
|
||||
#include "dpoint_entity.h"
|
||||
|
||||
|
||||
class vessel_entity : public IEntity {
|
||||
private:
|
||||
static entity_id __global_id;
|
||||
|
||||
entity_id _id;
|
||||
dpoint_entity _harbor;
|
||||
unsigned int _capacity;
|
||||
QVector<cargo_entity> _cargo;
|
||||
|
||||
public:
|
||||
vessel_entity() = default;
|
||||
vessel_entity(const dpoint_entity &harbor, unsigned int capacity);
|
||||
|
||||
entity_id id();
|
||||
const dpoint_entity harbor();
|
||||
unsigned int capacity();
|
||||
const QVector<cargo_entity> cargo();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
static void preloadGlobalId(entity_id gid);
|
||||
static entity_id GID();
|
||||
};
|
||||
|
||||
#endif // VESSEL_ENTITY_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue