All entities now have GID

This commit is contained in:
Andrew nuark G 2020-12-23 19:00:57 +07:00
parent eb097588ba
commit 2be2e9f5e3
9 changed files with 59 additions and 11 deletions

View file

@ -1,8 +1,10 @@
#include "cargo_entity.h"
entity_id cargo_entity::__global_id = 0;
cargo_entity::cargo_entity() {
this->_id += QRandomGenerator().generate64();
this->_id = ++cargo_entity::__global_id + QRandomGenerator().generate64();
}
cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(title), _volume(volume) {
@ -33,3 +35,11 @@ void cargo_entity::serialize(QDataStream &output) {
void cargo_entity::deserialize(QDataStream &input) {
input >> this->_id >> this->_title >> this->_volume;
}
void cargo_entity::preloadGlobalId(entity_id gid) {
cargo_entity::__global_id = gid;
}
entity_id cargo_entity::GID() {
return cargo_entity::__global_id;
}

View file

@ -10,6 +10,8 @@
class cargo_entity : public IEntity {
private:
static entity_id __global_id;
entity_id _id = 0;
QString _title;
unsigned int _volume = 50000;
@ -24,6 +26,8 @@ public:
void serialize(QDataStream &output);
void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
};
#endif // CARGO_ENTITY_H

View file

@ -1,8 +1,10 @@
#include "dpoint_entity.h"
entity_id dpoint_entity::__global_id = 0;
dpoint_entity::dpoint_entity() {
this->_id += QRandomGenerator().generate64();
this->_id = ++dpoint_entity::__global_id + QRandomGenerator().generate64();
}
dpoint_entity::dpoint_entity(entity_id dispatcher_id, const QString &title) : _dispatcher_id(dispatcher_id), _title(title) {
@ -83,3 +85,11 @@ void dpoint_entity::deserialize(QDataStream &input) {
this->_storages[i].deserialize(input);
}
}
void dpoint_entity::preloadGlobalId(entity_id gid) {
dpoint_entity::__global_id = gid;
}
entity_id dpoint_entity::GID() {
return dpoint_entity::__global_id;
}

View file

@ -12,6 +12,8 @@
class dpoint_entity : public IEntity {
private:
static entity_id __global_id;
entity_id _id = 0;
entity_id _dispatcher_id;
QString _title;
@ -33,6 +35,8 @@ public:
void serialize(QDataStream &output);
void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
};
#endif // DPOINT_ENTITY_H

View file

@ -1,8 +1,10 @@
#include "user_entity.h"
entity_id user_entity::__global_id = 0;
user_entity::user_entity() {
this->_id += QRandomGenerator().generate64();
this->_id = ++user_entity::__global_id + QRandomGenerator().generate64();
}
user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) {
@ -47,3 +49,11 @@ void user_entity::serialize(QDataStream &output) {
void user_entity::deserialize(QDataStream &input) {
input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash;
}
void user_entity::preloadGlobalId(entity_id gid) {
user_entity::__global_id = gid;
}
entity_id user_entity::GID() {
return user_entity::__global_id;
}

View file

@ -15,6 +15,8 @@ enum class UserRole {
class user_entity : public IEntity {
private:
static entity_id __global_id;
entity_id _id = 0;
QString _login;
UserRole _role;
@ -33,6 +35,8 @@ public:
void serialize(QDataStream &output);
void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
};
#endif // USER_ENTITY_H