Skip to content
Snippets Groups Projects

Refactor inheritance in armem/core

Merged Rainer Kartmann requested to merge armem/refactor-inheritance into armem/dev
3 files
+ 57
35
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -39,8 +39,8 @@ namespace armarx::armem::base
*/
template <class _EntitySnapshotT, class _Derived>
class EntityBase :
virtual public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>,
virtual public detail::MaxHistorySize
public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>,
public detail::MaxHistorySize
{
using Base = detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>;
@@ -55,11 +55,23 @@ namespace armarx::armem::base
public:
EntityBase& operator=(const EntityBase& other)
EntityBase()
{
other._copySelf(*this);
return *this;
}
EntityBase(const std::string& name, const MemoryID& parentID = {}) :
EntityBase(parentID.withEntityName(name))
{
}
EntityBase(const MemoryID& id) :
Base(id)
{
}
EntityBase(const EntityBase& other) = default;
EntityBase(EntityBase&& other) = default;
EntityBase& operator=(const EntityBase& other) = default;
EntityBase& operator=(EntityBase&& other) = default;
virtual bool equalsDeep(const EntityBase& other) const
@@ -69,7 +81,7 @@ namespace armarx::armem::base
{
return false;
}
for (const auto& [key, snapshot] : _container)
for (const auto& [key, snapshot] : this->_container)
{
if (not other.hasSnapshot(key))
{
@@ -96,7 +108,7 @@ namespace armarx::armem::base
inline const std::map<Time, EntitySnapshotT>& history() const
{
return _container;
return this->_container;
}
inline std::map<Time, EntitySnapshotT>& history()
{
@@ -109,7 +121,7 @@ namespace armarx::armem::base
*/
bool hasSnapshot(Time time) const
{
return _container.count(time) > 0;
return this->_container.count(time) > 0;
}
/**
@@ -126,7 +138,7 @@ namespace armarx::armem::base
*/
std::vector<Time> getTimestamps() const
{
return simox::alg::get_keys(_container);
return simox::alg::get_keys(this->_container);
}
@@ -145,8 +157,8 @@ namespace armarx::armem::base
const EntitySnapshotT& getSnapshot(Time time) const
{
auto it = _container.find(time);
if (it != _container.end())
auto it = this->_container.find(time);
if (it != this->_container.end())
{
return it->second;
}
@@ -196,8 +208,8 @@ namespace armarx::armem::base
EntitySnapshotT* snapshot;
auto it = _container.find(update.timeCreated);
if (it == _container.end())
auto it = this->_container.find(update.timeCreated);
if (it == this->_container.end())
{
// Insert into history.
snapshot = &addSnapshot(update.timeCreated);
@@ -225,7 +237,7 @@ namespace armarx::armem::base
EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot)
{
auto it = _container.emplace(snapshot.time(), std::move(snapshot)).first;
auto it = this->_container.emplace(snapshot.time(), std::move(snapshot)).first;
it->second.id().setEntityID(this->id());
return it->second;
}
@@ -256,33 +268,6 @@ namespace armarx::armem::base
return "entity";
}
virtual _Derived copy() const override
{
_Derived d;
this->_copySelf(d);
return d;
}
virtual _Derived copyEmpty() const override
{
_Derived d;
this->_copySelfEmpty(d);
return d;
}
protected:
virtual void _copySelf(DerivedT& other) const override
{
Base::_copySelf(other);
}
virtual void _copySelfEmpty(DerivedT& other) const override
{
Base::_copySelfEmpty(other);
}
private:
@@ -291,11 +276,11 @@ namespace armarx::armem::base
{
if (_maxHistorySize >= 0)
{
while (_container.size() > size_t(_maxHistorySize))
while (this->_container.size() > size_t(_maxHistorySize))
{
_container.erase(_container.begin());
this->_container.erase(this->_container.begin());
}
ARMARX_CHECK_LESS_EQUAL(_container.size(), _maxHistorySize);
ARMARX_CHECK_LESS_EQUAL(this->_container.size(), _maxHistorySize);
}
}
@@ -314,18 +299,13 @@ namespace armarx::armem::base
*/
const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const
{
if (_container.empty())
if (this->_container.empty())
{
throw armem::error::EntityHistoryEmpty(name(), "when getting the latest snapshot.");
}
return *_container.rbegin();
return *this->_container.rbegin();
}
protected:
using Base::_container;
};
}
Loading