Entities improvement
This commit is contained in:
parent
19f223b474
commit
76ac624519
11 changed files with 39 additions and 27 deletions
|
|
@ -4,9 +4,11 @@
|
|||
#include "ISerializable.h"
|
||||
|
||||
|
||||
typedef unsigned long long entity_id;
|
||||
|
||||
class IEntity : public ISerializable {
|
||||
public:
|
||||
virtual unsigned long long id() = 0;
|
||||
virtual entity_id id() = 0;
|
||||
};
|
||||
|
||||
#endif // IENTITY_H
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
class cargo_entity : public IEntity {
|
||||
private:
|
||||
unsigned long long _id;
|
||||
entity_id _id;
|
||||
QString _title;
|
||||
unsigned int _volume;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ public:
|
|||
cargo_entity() = default;
|
||||
cargo_entity(const QString &title, unsigned int volume);
|
||||
|
||||
unsigned long long id();
|
||||
entity_id id();
|
||||
QString title();
|
||||
unsigned int volume();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ QString dpoint_entity::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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@
|
|||
|
||||
class dpoint_entity : public IEntity {
|
||||
private:
|
||||
unsigned long long _id;
|
||||
entity_id _id;
|
||||
QString _title;
|
||||
QVector<unsigned long long> _storages_ids;
|
||||
QVector<entity_id> _storages_ids;
|
||||
|
||||
public:
|
||||
dpoint_entity() = default;
|
||||
dpoint_entity(const QString &title);
|
||||
|
||||
unsigned long long id();
|
||||
entity_id id();
|
||||
QString title();
|
||||
const QVector<unsigned long long> storages_ids();
|
||||
const QVector<entity_id> storages_ids();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#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) {
|
||||
this->_id = ++storage_entity::__global_id;
|
||||
}
|
||||
|
||||
|
||||
unsigned long long storage_entity::id() {
|
||||
entity_id storage_entity::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;
|
||||
found = false;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ cargo_entity storage_entity::get_cargo(unsigned long long oid, bool &found) {
|
|||
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;
|
||||
auto vit = this->_cargo.begin();
|
||||
for (; vit != this->_cargo.end(); vit++) {
|
||||
|
|
@ -71,3 +71,7 @@ void storage_entity::deserialize(QDataStream &input) {
|
|||
this->_cargo[i].deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
void storage_entity::preloadGlobalId(entity_id gid) {
|
||||
storage_entity::__global_id = gid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
class storage_entity : public IEntity {
|
||||
private:
|
||||
static unsigned long long __global_id;
|
||||
static entity_id __global_id;
|
||||
|
||||
unsigned long long _id;
|
||||
entity_id _id;
|
||||
unsigned int _capacity;
|
||||
QVector<cargo_entity> _cargo;
|
||||
|
||||
|
|
@ -20,16 +20,17 @@ public:
|
|||
storage_entity() = default;
|
||||
storage_entity(unsigned int capacity);
|
||||
|
||||
unsigned long long id();
|
||||
entity_id id();
|
||||
unsigned int capacity();
|
||||
const QVector<cargo_entity> cargo();
|
||||
|
||||
void add_cargo(cargo_entity object, bool &success);
|
||||
cargo_entity get_cargo(unsigned long long oid, bool &found);
|
||||
void withdraw_cargo(unsigned long long oid, 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);
|
||||
void preloadGlobalId(entity_id gid);
|
||||
};
|
||||
|
||||
#endif // STORAGE_ENTITY_H
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
unsigned long long user_entity::id() {
|
||||
entity_id user_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ enum class UserRole {
|
|||
|
||||
class user_entity : public IEntity {
|
||||
private:
|
||||
unsigned long long _id;
|
||||
entity_id _id;
|
||||
QString _login;
|
||||
UserRole _role;
|
||||
QByteArray _pwd_hash;
|
||||
|
|
@ -23,7 +23,7 @@ public:
|
|||
user_entity() = default;
|
||||
user_entity(const QString &login, const QString &password, UserRole role);
|
||||
|
||||
unsigned long long id();
|
||||
entity_id id();
|
||||
const QString login();
|
||||
UserRole role();
|
||||
bool verify_password(const QString &password);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#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) {
|
||||
this->_id = ++vessel_entity::__global_id;
|
||||
}
|
||||
|
||||
unsigned long long vessel_entity::id() {
|
||||
entity_id vessel_entity::id() {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
|
|
@ -42,3 +42,7 @@ void vessel_entity::deserialize(QDataStream &input) {
|
|||
this->_cargo[i].deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
void vessel_entity::preloadGlobalId(entity_id gid) {
|
||||
vessel_entity::__global_id = gid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
class vessel_entity : public IEntity {
|
||||
private:
|
||||
static unsigned long long __global_id;
|
||||
static entity_id __global_id;
|
||||
|
||||
unsigned long long _id;
|
||||
entity_id _id;
|
||||
dpoint_entity _harbor;
|
||||
unsigned int _capacity;
|
||||
QVector<cargo_entity> _cargo;
|
||||
|
|
@ -19,13 +19,14 @@ public:
|
|||
vessel_entity() = default;
|
||||
vessel_entity(const dpoint_entity &harbor, unsigned int capacity);
|
||||
|
||||
unsigned long long id();
|
||||
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);
|
||||
};
|
||||
|
||||
#endif // VESSEL_ENTITY_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue