Skip to content
Snippets Groups Projects
Commit d48d4885 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Copy copy constructors and copy assigment operators

parent 045a49f5
No related branches found
No related tags found
1 merge request!94ArMem Queries
......@@ -16,6 +16,33 @@ namespace armarx::armem
{
}
Entity::Entity(const Entity& other)
{
*this = other;
}
Entity& Entity::operator=(const Entity& other)
{
this->name = other.name;
this->maxHistorySize = other.maxHistorySize;
this->history.clear();
for (const auto& [time, snapshot] : other.history)
{
this->addSnapshot(*snapshot);
}
return *this;
}
EntityPtr Entity::getEmptyCopy() const
{
EntityPtr other = std::make_unique<Entity>();
other->name = this->name;
other->maxHistorySize = this->maxHistorySize;
return other;
}
bool Entity::hasSnapshot(Time time) const
{
return history.count(time) > 0;
......@@ -43,6 +70,11 @@ namespace armarx::armem
}
EntitySnapshot& Entity::getLatestSnapshot()
{
return const_cast<EntitySnapshot&>(const_cast<const Entity*>(this)->getLatestSnapshot());
}
const EntitySnapshot& Entity::getLatestSnapshot() const
{
if (history.empty())
{
......@@ -53,6 +85,13 @@ namespace armarx::armem
}
EntitySnapshot& Entity::addSnapshot(const EntitySnapshot& snapshot)
{
auto it = history.emplace(snapshot.time, std::make_unique<EntitySnapshot>(snapshot)).first;
return *it->second;
}
MemoryID Entity::update(const InternalEntityUpdate& update)
{
checkEntityName(update.entityID.entityName);
......
......@@ -12,6 +12,9 @@
namespace armarx::armem
{
class Entity;
using EntityPtr = std::unique_ptr<Entity>;
/**
* @brief Data of an entity over a period of time.
*/
......@@ -22,6 +25,16 @@ namespace armarx::armem
Entity();
Entity(const std::string& name);
/// Copy the history from `other` to this.
Entity(const Entity& other);
/// Copy the history from `other` to this.
Entity& operator=(const Entity& other);
/// Get an empty copy of `*this`.
EntityPtr getEmptyCopy() const;
bool hasSnapshot(Time time) const;
EntitySnapshot& getSnapshot(Time time);
EntitySnapshot& getSnapshot(const MemoryID& id);
......@@ -31,6 +44,7 @@ namespace armarx::armem
* @return The latest snapshot.
*/
EntitySnapshot& getLatestSnapshot();
const EntitySnapshot& getLatestSnapshot() const;
/**
......@@ -40,6 +54,9 @@ namespace armarx::armem
*/
MemoryID update(const InternalEntityUpdate& update);
/// Add a single snapshot.
EntitySnapshot& addSnapshot(const EntitySnapshot& snapshot);
/**
* @brief Sets the maximum history size.
*
......@@ -71,6 +88,4 @@ namespace armarx::armem
};
using EntityPtr = std::unique_ptr<Entity>;
}
......@@ -9,6 +9,24 @@ namespace armarx::armem
{
EntitySnapshot::EntitySnapshot(const EntitySnapshot& other)
{
*this = other;
}
EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other)
{
this->time = other.time;
this->instances.clear();
this->instances.reserve(other.instances.size());
for (const auto& data : other.instances)
{
this->instances.emplace_back(std::make_unique<EntityData>(*data));
}
return *this;
}
void EntitySnapshot::update(const InternalEntityUpdate& update)
{
time = update.timeCreated;
......
......@@ -21,6 +21,11 @@ namespace armarx::armem
EntitySnapshot() = default;
/// Copy the instances from `other` to this.
EntitySnapshot(const EntitySnapshot& other);
/// Copy the instances from `other` to this.
EntitySnapshot& operator=(const EntitySnapshot& other);
void update(const InternalEntityUpdate& update);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment