Add entity files to git

This commit is contained in:
Martin Brodbeck 2019-10-04 15:22:15 +02:00
parent 63f9822f34
commit a33b9896b3
4 changed files with 25 additions and 50 deletions

View file

@ -1,33 +1,6 @@
#include "entity.h" #include "entity.h"
#include <iostream>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
Entity::~Entity() = default;
void Entity::createUuid()
{
static boost::uuids::random_generator generator{};
uuid_ = generator();
}
void Entity::setUuidFromString(const std::string& uuidString)
{
boost::uuids::string_generator generator{};
uuid_ = generator(uuidString);
}
Entity::State Entity::getState() const Entity::State Entity::getState() const
{ {
return state_; return state_;
} }
void Entity::setSourceNo(int sourceNo) {
sourceNo_ = sourceNo;
}
int Entity::getSourceNo() const {
return sourceNo_;
}

View file

@ -1,34 +1,15 @@
#ifndef ENTITY_H #ifndef ENTITY_H
#define ENTITY_H #define ENTITY_H
#include <string>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
class Entity class Entity
{ {
public: public:
enum class State { NEW, UPDATE, DELETE, OK }; enum class State { NEW, UPDATE, DELETE, OK };
//virtual ~Entity() = 0;
// Entity() = default;
virtual ~Entity() = 0;
void createUuid();
void setUuidFromString(const std::string& uuidString);
void setState(State state) { state_ = state; } void setState(State state) { state_ = state; }
void setSourceNo(int sourceNo);
const boost::uuids::uuid& getUuid() const { return uuid_; };
std::string getUuidAsString() const { return boost::uuids::to_string(uuid_); }
virtual State getState() const; virtual State getState() const;
virtual int getSourceNo() const;
protected:
int sourceNo_{};
private: private:
boost::uuids::uuid uuid_{};
State state_{State::NEW}; State state_{State::NEW};
}; };

5
src/core/entityint.cpp Normal file
View file

@ -0,0 +1,5 @@
#include "entityint.h"
void EntityInt::setId(int id) {
id_ = id;
}

16
src/core/entityint.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef ENTITY_INT_H
#define ENTITY_INT_H
#include "entity.h"
class EntityInt : public Entity
{
public:
void setId(int id);
int getId() const {return id_;};
protected:
int id_{};
};
#endif // ENTITY_INT_H