Entities improvement

This commit is contained in:
Andrew nuark G 2020-12-15 21:44:41 +07:00
parent 19f223b474
commit 76ac624519
11 changed files with 39 additions and 27 deletions

View file

@ -4,9 +4,11 @@
#include "ISerializable.h" #include "ISerializable.h"
typedef unsigned long long entity_id;
class IEntity : public ISerializable { class IEntity : public ISerializable {
public: public:
virtual unsigned long long id() = 0; virtual entity_id id() = 0;
}; };
#endif // IENTITY_H #endif // IENTITY_H

View file

@ -8,7 +8,7 @@ cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(t
} }
} }
unsigned long long cargo_entity::id() { entity_id cargo_entity::id() {
return this->_id; return this->_id;
} }

View file

@ -9,7 +9,7 @@
class cargo_entity : public IEntity { class cargo_entity : public IEntity {
private: private:
unsigned long long _id; entity_id _id;
QString _title; QString _title;
unsigned int _volume; unsigned int _volume;
@ -17,7 +17,7 @@ public:
cargo_entity() = default; cargo_entity() = default;
cargo_entity(const QString &title, unsigned int volume); cargo_entity(const QString &title, unsigned int volume);
unsigned long long id(); entity_id id();
QString title(); QString title();
unsigned int volume(); unsigned int volume();

View file

@ -8,7 +8,7 @@ dpoint_entity::dpoint_entity(const QString &title) : _title(title) {
} }
} }
unsigned long long dpoint_entity::id() { entity_id dpoint_entity::id() {
return this->_id; return this->_id;
} }
@ -16,7 +16,7 @@ QString dpoint_entity::title() {
return this->_title; return this->_title;
} }
const QVector<unsigned long long> dpoint_entity::storages_ids() { const QVector<entity_id> dpoint_entity::storages_ids() {
return this->_storages_ids; return this->_storages_ids;
} }

View file

@ -10,17 +10,17 @@
class dpoint_entity : public IEntity { class dpoint_entity : public IEntity {
private: private:
unsigned long long _id; entity_id _id;
QString _title; QString _title;
QVector<unsigned long long> _storages_ids; QVector<entity_id> _storages_ids;
public: public:
dpoint_entity() = default; dpoint_entity() = default;
dpoint_entity(const QString &title); dpoint_entity(const QString &title);
unsigned long long id(); entity_id id();
QString title(); QString title();
const QVector<unsigned long long> storages_ids(); const QVector<entity_id> storages_ids();
void serialize(QDataStream &output); void serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);

View file

@ -1,14 +1,14 @@
#include "storage_entity.h" #include "storage_entity.h"
unsigned long long storage_entity::__global_id = 0; entity_id storage_entity::__global_id = 0;
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) { storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
this->_id = ++storage_entity::__global_id; this->_id = ++storage_entity::__global_id;
} }
unsigned long long storage_entity::id() { entity_id storage_entity::id() {
return this->_id; return this->_id;
} }
@ -28,7 +28,7 @@ void storage_entity::add_cargo(cargo_entity object, bool &success) {
} }
} }
cargo_entity storage_entity::get_cargo(unsigned long long oid, bool &found) { cargo_entity storage_entity::get_cargo(entity_id oid, bool &found) {
cargo_entity ent; cargo_entity ent;
found = false; found = false;
@ -43,7 +43,7 @@ cargo_entity storage_entity::get_cargo(unsigned long long oid, bool &found) {
return ent; return ent;
} }
void storage_entity::withdraw_cargo(unsigned long long oid, bool &success) { void storage_entity::withdraw_cargo(entity_id oid, bool &success) {
success = false; success = false;
auto vit = this->_cargo.begin(); auto vit = this->_cargo.begin();
for (; vit != this->_cargo.end(); vit++) { for (; vit != this->_cargo.end(); vit++) {
@ -71,3 +71,7 @@ void storage_entity::deserialize(QDataStream &input) {
this->_cargo[i].deserialize(input); this->_cargo[i].deserialize(input);
} }
} }
void storage_entity::preloadGlobalId(entity_id gid) {
storage_entity::__global_id = gid;
}

View file

@ -10,9 +10,9 @@
class storage_entity : public IEntity { class storage_entity : public IEntity {
private: private:
static unsigned long long __global_id; static entity_id __global_id;
unsigned long long _id; entity_id _id;
unsigned int _capacity; unsigned int _capacity;
QVector<cargo_entity> _cargo; QVector<cargo_entity> _cargo;
@ -20,16 +20,17 @@ public:
storage_entity() = default; storage_entity() = default;
storage_entity(unsigned int capacity); storage_entity(unsigned int capacity);
unsigned long long id(); entity_id id();
unsigned int capacity(); unsigned int capacity();
const QVector<cargo_entity> cargo(); const QVector<cargo_entity> cargo();
void add_cargo(cargo_entity object, bool &success); void add_cargo(cargo_entity object, bool &success);
cargo_entity get_cargo(unsigned long long oid, bool &found); cargo_entity get_cargo(entity_id oid, bool &found);
void withdraw_cargo(unsigned long long oid, bool &success); void withdraw_cargo(entity_id oid, bool &success);
void serialize(QDataStream &output); void serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);
void preloadGlobalId(entity_id gid);
}; };
#endif // STORAGE_ENTITY_H #endif // STORAGE_ENTITY_H

View file

@ -4,7 +4,7 @@ user_entity::user_entity(const QString &login, const QString &password, UserRole
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256); this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
} }
unsigned long long user_entity::id() { entity_id user_entity::id() {
return this->_id; return this->_id;
} }

View file

@ -14,7 +14,7 @@ enum class UserRole {
class user_entity : public IEntity { class user_entity : public IEntity {
private: private:
unsigned long long _id; entity_id _id;
QString _login; QString _login;
UserRole _role; UserRole _role;
QByteArray _pwd_hash; QByteArray _pwd_hash;
@ -23,7 +23,7 @@ public:
user_entity() = default; user_entity() = default;
user_entity(const QString &login, const QString &password, UserRole role); user_entity(const QString &login, const QString &password, UserRole role);
unsigned long long id(); entity_id id();
const QString login(); const QString login();
UserRole role(); UserRole role();
bool verify_password(const QString &password); bool verify_password(const QString &password);

View file

@ -1,13 +1,13 @@
#include "vessel_entity.h" #include "vessel_entity.h"
unsigned long long vessel_entity::__global_id = 0; entity_id vessel_entity::__global_id = 0;
vessel_entity::vessel_entity(const dpoint_entity &harbor, unsigned int capacity) : _harbor(harbor), _capacity(capacity) { vessel_entity::vessel_entity(const dpoint_entity &harbor, unsigned int capacity) : _harbor(harbor), _capacity(capacity) {
this->_id = ++vessel_entity::__global_id; this->_id = ++vessel_entity::__global_id;
} }
unsigned long long vessel_entity::id() { entity_id vessel_entity::id() {
return this->_id; return this->_id;
} }
@ -42,3 +42,7 @@ void vessel_entity::deserialize(QDataStream &input) {
this->_cargo[i].deserialize(input); this->_cargo[i].deserialize(input);
} }
} }
void vessel_entity::preloadGlobalId(entity_id gid) {
vessel_entity::__global_id = gid;
}

View file

@ -8,9 +8,9 @@
class vessel_entity : public IEntity { class vessel_entity : public IEntity {
private: private:
static unsigned long long __global_id; static entity_id __global_id;
unsigned long long _id; entity_id _id;
dpoint_entity _harbor; dpoint_entity _harbor;
unsigned int _capacity; unsigned int _capacity;
QVector<cargo_entity> _cargo; QVector<cargo_entity> _cargo;
@ -19,13 +19,14 @@ public:
vessel_entity() = default; vessel_entity() = default;
vessel_entity(const dpoint_entity &harbor, unsigned int capacity); vessel_entity(const dpoint_entity &harbor, unsigned int capacity);
unsigned long long id(); entity_id id();
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 serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
}; };
#endif // VESSEL_ENTITY_H #endif // VESSEL_ENTITY_H