diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 0e3d33e1950ebaade350c516dd9e6e66dab1fce4..be30284443c02aa0c4a90225855df5b2d753f6aa 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -23,7 +23,7 @@ set(LIB_FILES core/base/detail/MaxHistorySize.cpp core/base/detail/MemoryContainerBase.cpp core/base/detail/EntityContainerBase.cpp - core/base/detail/TypedEntityContainerBase.cpp + core/base/detail/AronTyped.cpp core/base/CoreSegmentBase.cpp core/base/EntityBase.cpp @@ -33,9 +33,7 @@ set(LIB_FILES core/base/ProviderSegmentBase.cpp core/workingmemory/ice_conversions.cpp - core/workingmemory/detail/MemoryContainer.cpp - core/workingmemory/detail/EntityContainer.cpp - core/workingmemory/detail/TypedEntityContainer.cpp + core/workingmemory/detail/CopyWithoutData.cpp core/workingmemory/CoreSegment.cpp core/workingmemory/Entity.cpp core/workingmemory/EntityInstance.cpp @@ -52,6 +50,7 @@ set(LIB_FILES core/longtermmemory/Memory.cpp core/longtermmemory/ProviderSegment.cpp + core/diskmemory/TypeIO.cpp core/diskmemory/CoreSegment.cpp core/diskmemory/Entity.cpp core/diskmemory/EntityInstance.cpp @@ -119,7 +118,7 @@ set(LIB_HEADERS core/base/detail/MaxHistorySize.h core/base/detail/MemoryContainerBase.h core/base/detail/EntityContainerBase.h - core/base/detail/TypedEntityContainerBase.h + core/base/detail/AronTyped.h core/base/CoreSegmentBase.h core/base/EntityBase.h @@ -128,9 +127,7 @@ set(LIB_HEADERS core/base/MemoryBase.h core/base/ProviderSegmentBase.h - core/workingmemory/detail/MemoryContainer.h - core/workingmemory/detail/EntityContainer.h - core/workingmemory/detail/TypedEntityContainer.h + core/workingmemory/detail/CopyWithoutData.h core/workingmemory/CoreSegment.h core/workingmemory/Entity.h core/workingmemory/EntityInstance.h @@ -148,7 +145,7 @@ set(LIB_HEADERS core/longtermmemory/ProviderSegment.h core/longtermmemory/mongodb/MongoDBConnectionManager.h - core/diskmemory/detail/TypedEntityContainer.h + core/diskmemory/TypeIO.h core/diskmemory/CoreSegment.h core/diskmemory/Entity.h core/diskmemory/EntityInstance.h diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h index 326a251a6a3a0a62034f01a9c11553bf8f180ec1..8b3d0ee2c00d8dad8c40bfbecb67b53bb1606b50 100644 --- a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h @@ -4,8 +4,9 @@ #include <string> #include "ProviderSegmentBase.h" +#include "detail/AronTyped.h" +#include "detail/EntityContainerBase.h" #include "detail/MaxHistorySize.h" -#include "detail/TypedEntityContainerBase.h" namespace armarx::armem::base @@ -16,10 +17,11 @@ namespace armarx::armem::base */ template <class _ProviderSegmentT, class _Derived> class CoreSegmentBase : - virtual public detail::TypedEntityContainerBase<_ProviderSegmentT, typename _ProviderSegmentT::EntityT, _Derived>, - virtual public detail::MaxHistorySize + public detail::EntityContainerBase<_ProviderSegmentT, typename _ProviderSegmentT::EntityT, _Derived>, + public detail::MaxHistorySize, + public detail::AronTyped { - using Base = detail::TypedEntityContainerBase<_ProviderSegmentT, typename _ProviderSegmentT::EntityT, _Derived>; + using Base = detail::EntityContainerBase<_ProviderSegmentT, typename _ProviderSegmentT::EntityT, _Derived>; public: @@ -34,11 +36,36 @@ namespace armarx::armem::base public: + CoreSegmentBase() + { + } + CoreSegmentBase(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + CoreSegmentBase(MemoryID().withCoreSegmentName(name), aronType) + { + } + CoreSegmentBase(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + CoreSegmentBase(parentID.withProviderSegmentName(name), aronType) + { + } + CoreSegmentBase(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + Base(id), + AronTyped(aronType) + { + } + + /* + CoreSegmentBase(const CoreSegmentBase& other) : + Base(other), + AronTyped(other) + { + } + CoreSegmentBase& operator=(const CoreSegmentBase& other) { other._copySelf(*this); return *this; } + */ inline const std::string& name() const { @@ -52,7 +79,7 @@ namespace armarx::armem::base inline const std::map<std::string, ProviderSegmentT>& providerSegments() const { - return _container; + return this->_container; } inline std::map<std::string, ProviderSegmentT>& providerSegments() { @@ -62,7 +89,7 @@ namespace armarx::armem::base bool hasProviderSegment(const std::string& name) const { - return _container.count(name) > 0; + return this->_container.count(name) > 0; } ProviderSegmentT& getProviderSegment(const std::string& name) @@ -73,7 +100,7 @@ namespace armarx::armem::base const ProviderSegmentT& getProviderSegment(const std::string& name) const { auto it = this->_container.find(name); - if (it != _container.end()) + if (it != this->_container.end()) { return it->second; } @@ -95,7 +122,7 @@ namespace armarx::armem::base this->_checkContainerName(update.entityID.coreSegmentName, this->name()); auto it = this->_container.find(update.entityID.providerSegmentName); - if (it != _container.end()) + if (it != this->_container.end()) { return it->second.update(update); } @@ -132,7 +159,7 @@ namespace armarx::armem::base providerSegment.getLevelName(), providerSegment.name(), getLevelName(), this->getKeyString()); } - auto it = _container.emplace(providerSegment.name(), std::move(providerSegment)).first; + auto it = this->_container.emplace(providerSegment.name(), std::move(providerSegment)).first; it->second.id().setCoreSegmentID(this->id()); it->second.setMaxHistorySize(_maxHistorySize); return it->second; @@ -147,7 +174,7 @@ namespace armarx::armem::base void setMaxHistorySize(long maxSize) override { MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, seg] : _container) + for (auto& [name, seg] : this->_container) { seg.setMaxHistorySize(maxSize); } @@ -160,7 +187,7 @@ namespace armarx::armem::base { return false; } - for (const auto& [key, provider] : _container) + for (const auto& [key, provider] : this->_container) { if (not other.hasProviderSegment(key)) { @@ -187,7 +214,11 @@ namespace armarx::armem::base protected: - using Base::_container; + virtual void _copySelf(DerivedT& other) const override + { + Base::_copySelf(other); + other.aronType() = _aronType; + } }; diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index fa884ee115624b437182f35df5744863f206ddb2..90cd503a1c5763d24ae5d72bff891c943b76bef9 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -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,31 @@ namespace armarx::armem::base public: + EntityBase() + { + } + EntityBase(const std::string& name, const MemoryID& parentID = {}) : + EntityBase(parentID.withEntityName(name)) + { + } + EntityBase(const MemoryID& id) : + Base(id) + { + } + + /* + EntityBase(const EntityBase& other) : + Base(other) + { + } + + EntityBase& operator=(const EntityBase& other) { other._copySelf(*this); return *this; } + */ virtual bool equalsDeep(const EntityBase& other) const @@ -69,7 +89,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 +116,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 +129,7 @@ namespace armarx::armem::base */ bool hasSnapshot(Time time) const { - return _container.count(time) > 0; + return this->_container.count(time) > 0; } /** @@ -126,7 +146,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 +165,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 +216,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 +245,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; } @@ -291,11 +311,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 +334,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; - }; } diff --git a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h index d385ee26bb9a17f73535d15b68822c17c5bfd278..fdf8d2be748fcacf94735db4ed570a154f2662a3 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h @@ -13,7 +13,7 @@ namespace armarx::armem::base */ template <class _DerivedT> class EntityInstanceBase : - virtual public detail::MemoryItem + public detail::MemoryItem { using Base = detail::MemoryItem; @@ -24,11 +24,25 @@ namespace armarx::armem::base public: - EntityInstanceBase& operator=(const EntityInstanceBase& other) + EntityInstanceBase() { - //other._copySelf(*this); - return *this; } + EntityInstanceBase(int index, const MemoryID& parentID = {}) : + EntityInstanceBase(parentID.withInstanceIndex(index)) + { + } + EntityInstanceBase(const MemoryID& id) : + Base(id) + { + } + + /* + EntityInstanceBase& operator=(const EntityInstanceBase& other) + { + other._copySelf(*this); + return *this; + } + */ inline int& index() diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h index 094608e2927991f5593922887ec17e11fe6ce440..db1370f1ba081bfc35466698bdb70f9b5b07193d 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h @@ -17,7 +17,7 @@ namespace armarx::armem::base */ template <class _EntityInstanceT, class _Derived> class EntitySnapshotBase : - virtual public detail::MemoryContainerBase<std::vector<_EntityInstanceT>, _Derived> + public detail::MemoryContainerBase<std::vector<_EntityInstanceT>, _Derived> { using Base = detail::MemoryContainerBase<std::vector<_EntityInstanceT>, _Derived>; @@ -31,11 +31,31 @@ namespace armarx::armem::base public: + EntitySnapshotBase() + { + } + EntitySnapshotBase(Time time, const MemoryID& parentID = {}) : + EntitySnapshotBase(parentID.withTimestamp(time)) + { + } + EntitySnapshotBase(const MemoryID& id) : + Base(id) + { + } + + /* + EntitySnapshotBase(const EntitySnapshotBase& other) : + Base(other) + { + } + EntitySnapshotBase& operator=(const EntitySnapshotBase& other) { - other._copySelf(*this); + Base::operator=(other); return *this; } + */ + virtual bool equalsDeep(const EntitySnapshotBase& other) const { @@ -45,7 +65,7 @@ namespace armarx::armem::base return false; } int i = 0; - for (const auto& instance : _container) + for (const auto& instance : this->_container) { if (not instance.equalsDeep(other.getInstance(i))) { @@ -69,7 +89,7 @@ namespace armarx::armem::base inline const std::vector<EntityInstanceT>& instances() const { - return _container; + return this->_container; } inline std::vector<EntityInstanceT>& instances() { @@ -85,10 +105,10 @@ namespace armarx::armem::base } time() = update.timeCreated; - _container.clear(); + this->_container.clear(); for (int i = 0; i < int(update.instancesData.size()); ++i) { - EntityInstanceT& data = _container.emplace_back(i, this->id()); + EntityInstanceT& data = this->_container.emplace_back(i, this->id()); data.update(update, i); } } @@ -97,7 +117,7 @@ namespace armarx::armem::base bool hasInstance(int index) const { size_t si = size_t(index); - return index >= 0 && si < _container.size(); + return index >= 0 && si < this->_container.size(); } /** @@ -115,7 +135,7 @@ namespace armarx::armem::base { if (hasInstance(index)) { - return _container[static_cast<size_t>(index)]; + return this->_container[static_cast<size_t>(index)]; } else { @@ -158,19 +178,19 @@ namespace armarx::armem::base EntityInstanceT& addInstance(EntityInstanceT&& instance) { - if (instance.index() > 0 && static_cast<size_t>(instance.index()) < _container.size()) + if (instance.index() > 0 && static_cast<size_t>(instance.index()) < this->_container.size()) { throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", "Cannot add an EntityInstance because its index already exists."); } - if (instance.index() > 0 && static_cast<size_t>(instance.index()) > _container.size()) + if (instance.index() > 0 && static_cast<size_t>(instance.index()) > this->_container.size()) { throw error::InvalidArgument(std::to_string(instance.index()), "EntitySnapshot::addInstance", "Cannot add an EntityInstance because its index is too big."); } - int new_index = _container.size(); - auto& it = _container.emplace_back(std::move(instance)); + int new_index = this->_container.size(); + auto& it = this->_container.emplace_back(std::move(instance)); it.index() = new_index; return it; } @@ -185,11 +205,6 @@ namespace armarx::armem::base return "entity snapshot"; } - - protected: - - using Base::_container; - }; } diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h index 60f7ee86098c26463ffe14007362eadc114f3e9e..b97faceca4e1bf693ec265002e69f922dd83dda5 100644 --- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h @@ -17,7 +17,7 @@ namespace armarx::armem::base */ template <class _CoreSegmentT, class _Derived> class MemoryBase : - virtual public detail::EntityContainerBase<_CoreSegmentT, typename _CoreSegmentT::ProviderSegmentT::EntityT, _Derived> + public detail::EntityContainerBase<_CoreSegmentT, typename _CoreSegmentT::ProviderSegmentT::EntityT, _Derived> { using Base = detail::EntityContainerBase<_CoreSegmentT, typename _CoreSegmentT::ProviderSegmentT::EntityT, _Derived>; @@ -35,11 +35,31 @@ namespace armarx::armem::base public: + MemoryBase() + { + } + MemoryBase(const std::string& name) : + MemoryBase(MemoryID().withMemoryName(name)) + { + } + MemoryBase(const MemoryID& id) : + Base(id) + { + } + + /* + MemoryBase(const MemoryBase& other) : + Base(other) + { + } + + MemoryBase& operator=(const MemoryBase& other) { other._copySelf(*this); return *this; } + */ inline const std::string& name() const @@ -54,7 +74,7 @@ namespace armarx::armem::base inline const std::map<std::string, CoreSegmentT>& coreSegments() const { - return _container; + return this->_container; } inline std::map<std::string, CoreSegmentT>& coreSegments() { @@ -64,7 +84,7 @@ namespace armarx::armem::base bool hasCoreSegment(const std::string& name) const { - return _container.count(name) > 0; + return this->_container.count(name) > 0; } CoreSegmentT& getCoreSegment(const std::string& name) @@ -75,7 +95,7 @@ namespace armarx::armem::base const CoreSegmentT& getCoreSegment(const std::string& name) const { auto it = this->_container.find(name); - if (it != _container.end()) + if (it != this->_container.end()) { return it->second; } @@ -110,12 +130,12 @@ namespace armarx::armem::base /// Move and insert a core segment. CoreSegmentT& addCoreSegment(CoreSegmentT&& coreSegment) { - if (_container.count(coreSegment.name()) > 0) + if (this->_container.count(coreSegment.name()) > 0) { throw armem::error::ContainerEntryAlreadyExists(coreSegment.getLevelName(), coreSegment.name(), this->getLevelName(), this->name()); } - auto it = _container.emplace(coreSegment.name(), std::move(coreSegment)).first; + auto it = this->_container.emplace(coreSegment.name(), std::move(coreSegment)).first; it->second.id().setMemoryID(this->id()); return it->second; } @@ -146,8 +166,8 @@ namespace armarx::armem::base { this->_checkContainerName(update.entityID.memoryName, this->name()); - auto it = _container.find(update.entityID.coreSegmentName); - if (it != _container.end()) + auto it = this->_container.find(update.entityID.coreSegmentName); + if (it != this->_container.end()) { return it->second.update(update); } @@ -164,7 +184,7 @@ namespace armarx::armem::base { return false; } - for (const auto& [key, core] : _container) + for (const auto& [key, core] : this->_container) { if (not other.hasCoreSegment(key)) { @@ -191,7 +211,6 @@ namespace armarx::armem::base protected: - using Base::_container; }; } diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h index 9cbfd4facde379fc5d3cc1f8f0d26631899e5811..5e29186c17cfede91af9de96e9c9dd4089382406 100644 --- a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h @@ -4,7 +4,8 @@ #include <string> #include "EntityBase.h" -#include "detail/TypedEntityContainerBase.h" +#include "detail/AronTyped.h" +#include "detail/EntityContainerBase.h" #include "detail/MaxHistorySize.h" @@ -16,10 +17,11 @@ namespace armarx::armem::base */ template <class _EntityT, class _Derived> class ProviderSegmentBase : - virtual public detail::TypedEntityContainerBase<_EntityT, _EntityT, _Derived>, - virtual public detail::MaxHistorySize + public detail::EntityContainerBase<_EntityT, _EntityT, _Derived>, + public detail::MaxHistorySize, + public detail::AronTyped { - using Base = detail::TypedEntityContainerBase<_EntityT, _EntityT, _Derived>; + using Base = detail::EntityContainerBase<_EntityT, _EntityT, _Derived>; public: @@ -33,11 +35,38 @@ namespace armarx::armem::base public: + ProviderSegmentBase() + { + } + + ProviderSegmentBase(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + ProviderSegmentBase(MemoryID().withProviderSegmentName(name), aronType) + { + } + ProviderSegmentBase(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + ProviderSegmentBase(parentID.withProviderSegmentName(name), aronType) + { + } + ProviderSegmentBase(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : + Base(id), + AronTyped(aronType) + { + } + + /* + ProviderSegmentBase(const ProviderSegmentBase& other) : + Base(other), + AronTyped(other) + { + } + + ProviderSegmentBase& operator=(const ProviderSegmentBase& other) { other._copySelf(*this); return *this; } + */ inline const std::string& name() const @@ -52,7 +81,7 @@ namespace armarx::armem::base inline const std::map<std::string, EntityT>& entities() const { - return _container; + return this->_container; } inline std::map<std::string, EntityT>& entities() { @@ -62,7 +91,7 @@ namespace armarx::armem::base bool hasEntity(const std::string& name) const { - return _container.count(name) > 0; + return this->_container.count(name) > 0; } using Base::getEntity; @@ -80,7 +109,7 @@ namespace armarx::armem::base const EntityT& getEntity(const std::string& name) const { auto it = this->_container.find(name); - if (it != _container.end()) + if (it != this->_container.end()) { return it->second; } @@ -101,7 +130,7 @@ namespace armarx::armem::base EntityT* entity; auto it = this->_container.find(update.entityID.providerSegmentName); - if (it == _container.end()) + if (it == this->_container.end()) { // Add entity entry. entity = &addEntity(update.entityID.entityName); @@ -128,7 +157,7 @@ namespace armarx::armem::base /// Move and insert an entity. EntityT& addEntity(EntityT&& entity) { - auto it = _container.emplace(entity.name(), std::move(entity)).first; + auto it = this->_container.emplace(entity.name(), std::move(entity)).first; it->second.id().setProviderSegmentID(this->id()); return it->second; } @@ -142,7 +171,7 @@ namespace armarx::armem::base void setMaxHistorySize(long maxSize) override { MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, entity] : _container) + for (auto& [name, entity] : this->_container) { entity.setMaxHistorySize(maxSize); } @@ -156,7 +185,7 @@ namespace armarx::armem::base { return false; } - for (const auto& [key, value] : _container) + for (const auto& [key, value] : this->_container) { if (not other.hasEntity(key)) { @@ -184,7 +213,11 @@ namespace armarx::armem::base protected: - using Base::_container; + virtual void _copySelf(DerivedT& other) const override + { + Base::_copySelf(other); + other.aronType() = _aronType; + } }; diff --git a/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.cpp b/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec7ca0402ad128dc6d342aa28279929c376df557 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.cpp @@ -0,0 +1,26 @@ +#include "AronTyped.h" + +namespace armarx::armem::base::detail +{ + + AronTyped::AronTyped(aron::typenavigator::ObjectNavigatorPtr aronType) : + _aronType(aronType) + {} + + bool AronTyped::hasAronType() const + { + return _aronType != nullptr; + } + + aron::typenavigator::ObjectNavigatorPtr& AronTyped::aronType() + { + return _aronType; + } + + aron::typenavigator::ObjectNavigatorPtr AronTyped::aronType() const + { + return _aronType; + } + + +} diff --git a/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.h b/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.h new file mode 100644 index 0000000000000000000000000000000000000000..fb0ad088fb4fb27ca39cf09f034ea7eb3b202cfe --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/AronTyped.h @@ -0,0 +1,32 @@ +#pragma once + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + + +namespace armarx::armem::base::detail +{ + + /** + * @brief Something with a specific ARON type. + */ + class AronTyped + { + public: + + AronTyped(aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + + bool hasAronType() const; + aron::typenavigator::ObjectNavigatorPtr& aronType(); + aron::typenavigator::ObjectNavigatorPtr aronType() const; + + + protected: + + /// The expected Aron type. May be nullptr, in which case no type information is available. + aron::typenavigator::ObjectNavigatorPtr _aronType; + + }; + + +} diff --git a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h index ba4f8cf9b7d3d975a63eff763c49f546dcae6ac7..4aafc3df39f1ae964d7188eab3e694ab457f8f1a 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h @@ -19,7 +19,7 @@ namespace armarx::armem::base::detail */ template <class _ValueT, class _EntityT, class _Derived> class EntityContainerBase : - virtual public MemoryContainerBase<std::map<std::string, _ValueT>, _Derived> + public MemoryContainerBase<std::map<std::string, _ValueT>, _Derived> { using Base = MemoryContainerBase<std::map<std::string, _ValueT>, _Derived>; @@ -35,11 +35,16 @@ namespace armarx::armem::base::detail public: + using Base::MemoryContainerBase; + + /* EntityContainerBase& operator=(const EntityContainerBase& other) { other._copySelf(*this); return *this; } + */ + /** * @brief Store all updates in `commit`. diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h index 233985ebab9bee9353fd23f1b5e92ed570b0ccd2..9c4596a979173414e7a79840472dd6a0deb95612 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h @@ -14,7 +14,7 @@ namespace armarx::armem::base::detail */ template <class _ContainerT, class _DerivedT> class MemoryContainerBase : - virtual public MemoryItem + public MemoryItem { using Base = MemoryItem; @@ -26,11 +26,17 @@ namespace armarx::armem::base::detail public: + MemoryContainerBase() {} - MemoryContainerBase(const MemoryContainerBase<ContainerT, DerivedT>& o) : - MemoryItem(o.id), - _container(o._container) + MemoryContainerBase(const MemoryID& id) : + MemoryItem(id) + { + } + /* + MemoryContainerBase(const MemoryContainerBase& other) : + MemoryItem(other), + _container(other._container) {} @@ -39,6 +45,7 @@ namespace armarx::armem::base::detail other._copySelf(*this); return *this; } + */ // Container methods diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp index 76cb4215475417ec15345067f5eab980bca96887..a6a9f73e17443091503c09472bc3cee7259644ac 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp @@ -13,20 +13,24 @@ namespace armarx::armem::base::detail { } + /* MemoryItem::MemoryItem(const MemoryItem& other) : _id(other.id()) {} + */ MemoryItem::~MemoryItem() { } + /* MemoryItem& MemoryItem::operator=(const MemoryItem& other) { other._copySelf(*this); return *this; } + */ void MemoryItem::_copySelf(MemoryItem& other) const { diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h index 7867f645e39b9c6fca6ba7a92def993bb2f3fc40..07e799a13d083ea25b46e726f7ecabfaee472b1e 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h @@ -17,12 +17,12 @@ namespace armarx::armem::base::detail MemoryItem(); MemoryItem(const MemoryID& id); - MemoryItem(const MemoryItem& other); + //MemoryItem(const MemoryItem& other); virtual ~MemoryItem(); - MemoryItem& operator=(const MemoryItem& other); + //MemoryItem& operator=(const MemoryItem& other); inline MemoryID& id() diff --git a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.cpp b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.cpp deleted file mode 100644 index cd42021d8a566ecca4a5e4662a560660d08b3630..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "TypedEntityContainerBase.h" diff --git a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h deleted file mode 100644 index 81f21797dfd4ca8972efd736ba8660b5e48a68f8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "EntityContainerBase.h" - -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> - -namespace armarx::armem::base::detail -{ - - /** - * @brief An entity container with a specific (Aron) type. - */ - template <class _ValueT, class _EntityT, class _Derived> - class TypedEntityContainerBase : - virtual public EntityContainerBase<_ValueT, _EntityT, _Derived> - { - using Base = EntityContainerBase<_ValueT, _EntityT, _Derived>; - - - public: - - using typename Base::DerivedT; - using typename Base::ValueT; - using typename Base::EntityT; - using typename Base::EntitySnapshotT; - using typename Base::EntityInstanceT; - - - TypedEntityContainerBase(aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : - _aronType(aronType) - {} - - TypedEntityContainerBase(const TypedEntityContainerBase<_ValueT, _EntityT, DerivedT>& other) : - MemoryItem(other), - MemoryContainerBase<std::map<std::string, _ValueT>, DerivedT>(other), - _aronType(other._aronType) - {} - - TypedEntityContainerBase(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : - MemoryItem(id), - _aronType(aronType) - {} - - - TypedEntityContainerBase& operator=(const TypedEntityContainerBase& other) - { - other._copySelf(*this); - return *this; - } - - - bool hasAronType() const - { - return _aronType != nullptr; - } - aron::typenavigator::ObjectNavigatorPtr& aronType() - { - return _aronType; - } - aron::typenavigator::ObjectNavigatorPtr aronType() const - { - return _aronType; - } - - virtual DerivedT copyEmpty() const override - { - DerivedT d; - this->_copySelfEmpty(d); - return d; - } - - - protected: - - virtual void _copySelf(DerivedT& other) const override - { - Base::_copySelf(other); - other._aronType = _aronType; - } - - virtual void _copySelfEmpty(DerivedT& other) const override - { - Base::_copySelfEmpty(other); - other._aronType = _aronType; - } - - - protected: - - /// The expected Aron type. May be nullptr, in which case no type information is available. - aron::typenavigator::ObjectNavigatorPtr _aronType; - - }; - - -} diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp index bc3104b74ea8c1f396dc6ce0aee5742cdafd7e94..d98f3a339835faf7066c2f1f3d5a3c8da6251f3a 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp @@ -2,38 +2,15 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include "error.h" +#include "TypeIO.h" namespace armarx::armem::d_ltm { - CoreSegment::CoreSegment() - { - } - - CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(MemoryID().withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(parentID.withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(id, aronType) - { - } - CoreSegment::CoreSegment(const CoreSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, ProviderSegment>, CoreSegment>(other), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(other) + Base(other), + path(other.path) { } @@ -99,7 +76,10 @@ namespace armarx::armem::d_ltm if (d.is_regular_file()) { - readAronType(d.path()); + if (auto type = TypeIO::readAronType(d.path())) + { + _aronType = type; + } } } } @@ -108,7 +88,7 @@ namespace armarx::armem::d_ltm void CoreSegment::append(const wm::CoreSegment& m) { std::filesystem::create_directories(_fullPath()); - writeAronType(_fullPath()); + TypeIO::writeAronType(_aronType, _fullPath()); for (const auto& [k, s] : m) { diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.h index f26c01c67ed90ab5467b32e4ed755b3ddee2e1cf..896be97761041fb45ef29f00b5c1f64e29581051 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.h @@ -3,12 +3,10 @@ #include <filesystem> #include "../base/CoreSegmentBase.h" -#include "detail/TypedEntityContainer.h" +#include "../workingmemory/CoreSegment.h" #include "ProviderSegment.h" -#include "../workingmemory/CoreSegment.h" - namespace armarx::armem::d_ltm { @@ -17,16 +15,13 @@ namespace armarx::armem::d_ltm * @brief Data of a core segment containing multiple provider segments. */ class CoreSegment : - virtual public base::CoreSegmentBase<ProviderSegment, CoreSegment>, - virtual public detail::TypedEntityContainer<ProviderSegment, CoreSegment> + public base::CoreSegmentBase<ProviderSegment, CoreSegment> { using Base = base::CoreSegmentBase<ProviderSegment, CoreSegment>; public: - CoreSegment(); - CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + using Base::CoreSegmentBase; CoreSegment(const CoreSegment& other); CoreSegment& operator=(const CoreSegment& other); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp index 77ff0d95f4cf7ac7b81ac933d478ce47ae1010a6..bf14fe6464532ad02857696ac8fe2c31e9aaaed9 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp @@ -3,23 +3,9 @@ namespace armarx::armem::d_ltm { - Entity::Entity() - { - } - - Entity::Entity(const std::string& name, const MemoryID& parentID) : - base::detail::MemoryItem(parentID.withEntityName(name)) - { - } - - Entity::Entity(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - Entity::Entity(const Entity& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<Time, EntitySnapshot>, Entity>(other) + Base(other), + path(other.path) { } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h index 756f3eb69dd3499333532187ee207fd4cec4e102..9174ffb73d326ec947ac7c8265f26b12b07805bc 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h @@ -3,10 +3,10 @@ #include <filesystem> #include "../base/EntityBase.h" +#include "../workingmemory/Entity.h" #include "EntitySnapshot.h" -#include "../workingmemory/Entity.h" namespace armarx::armem::d_ltm @@ -31,18 +31,15 @@ namespace armarx::armem::d_ltm * each containing a single `AronData` object of a specific `AronType`. */ class Entity : - virtual public base::EntityBase<EntitySnapshot, Entity> + public base::EntityBase<EntitySnapshot, Entity> { using Base = base::EntityBase<EntitySnapshot, Entity>; public: - Entity(); - Entity(const std::string& name, const MemoryID& parentID = {}); - Entity(const MemoryID& id); - /// Copy the history from `other` to this. + using Base::EntityBase; + Entity(const Entity& other); - /// Copy the history from `other` to this. Entity& operator=(const Entity& other); // Conversion diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp index 28bcf696369fedfa9bd39ab9cce3f694033211d6..1ee7691f41d3d55c903d70bf9cd144bb62765d06 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp @@ -13,22 +13,9 @@ namespace armarx::armem::d_ltm { - EntityInstance::EntityInstance() - { - } - EntityInstance::EntityInstance(const EntityInstance& other) : - base::detail::MemoryItem(other.id()) - { - } - - EntityInstance::EntityInstance(int index, const MemoryID& parentID) : - EntityInstance(parentID.withInstanceIndex(index)) - { - } - - EntityInstance::EntityInstance(const MemoryID& id) : - base::detail::MemoryItem(id) + Base(other), + path(other.path) { } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h index 8e7a0fed18959090f05196ba32565f507e19faf4..37bebb7b64cad3c07ffecb88ad1ccacda6db37ce 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h @@ -3,25 +3,24 @@ #include <filesystem> #include "../base/EntityInstanceBase.h" - #include "../workingmemory/EntityInstance.h" + namespace armarx::armem::d_ltm { /** * @brief Data of a single entity instance. */ class EntityInstance : - virtual public base::EntityInstanceBase<EntityInstance> + public base::EntityInstanceBase<EntityInstance> { using Base = base::EntityInstanceBase<EntityInstance>; public: - EntityInstance(); - EntityInstance(const EntityInstance&); - EntityInstance(int index, const MemoryID& parentID = {}); - EntityInstance(const MemoryID& id); + using Base::EntityInstanceBase; + + EntityInstance(const EntityInstance&); EntityInstance& operator=(const EntityInstance& other); /** diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp index 98654d7a854b4247d515887ba3e9e4d5996b46d8..8de49551aeeea65331240123b3c3e8c5e72c003d 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp @@ -8,24 +8,9 @@ namespace armarx::armem::d_ltm { - - EntitySnapshot::EntitySnapshot() - { - } - - EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : - EntitySnapshot(parentID.withTimestamp(time)) - { - } - - EntitySnapshot::EntitySnapshot(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) + Base(other), + path(other.path) { } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h index 5c3cf02ff6cb452797ac0c0433bbef294d92a29f..d3402d634218d9afaffd46aa5c0bf62525b9f1f7 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h @@ -3,11 +3,10 @@ #include <filesystem> #include "../base/EntitySnapshotBase.h" +#include "../workingmemory/EntitySnapshot.h" #include "EntityInstance.h" -#include "../workingmemory/EntitySnapshot.h" - namespace armarx::armem::d_ltm { @@ -16,19 +15,15 @@ namespace armarx::armem::d_ltm * @brief Data of an entity at one point in time. */ class EntitySnapshot : - virtual public base::EntitySnapshotBase<EntityInstance, EntitySnapshot> + public base::EntitySnapshotBase<EntityInstance, EntitySnapshot> { using Base = base::EntitySnapshotBase<EntityInstance, EntitySnapshot>; public: - EntitySnapshot(); - EntitySnapshot(Time time, const MemoryID& parentID = {}); - EntitySnapshot(const MemoryID& id); - /// Copy the instances from `other` to this. - EntitySnapshot(const EntitySnapshot& other); + using Base::EntitySnapshotBase; - /// Copy the instances from `other` to this. + EntitySnapshot(const EntitySnapshot& other); EntitySnapshot& operator=(const EntitySnapshot& other); // Conversion diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp index 70ed79acc064f4c0fb3a222c75bd90321c39f0e2..f7461b4cf9633e6b722fa97fda6aa5debee632d0 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp @@ -8,26 +8,10 @@ namespace armarx::armem::d_ltm { - - Memory::Memory() - { - } - - Memory::Memory(const std::string& name) : - base::detail::MemoryItem(MemoryID().withMemoryName(name)) - { - } - - Memory::Memory(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - Memory::Memory(const Memory& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, CoreSegment>, Memory>(other) + Base(other), + path(other.path) { - *this = other; } Memory& Memory::operator=(const Memory& other) diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h index 32bd30fa69c4dff87ef9d13e599cac8442936003..f1a9d446dcf982c9bb9e44d08a7ea9d8e3bfcc5e 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h @@ -3,10 +3,10 @@ #include <filesystem> #include "../base/MemoryBase.h" +#include "../workingmemory/Memory.h" #include "CoreSegment.h" -#include "../workingmemory/Memory.h" namespace armarx::armem::d_ltm { @@ -15,14 +15,13 @@ namespace armarx::armem::d_ltm * @brief Data of a memory consisting of multiple core segments. */ class Memory : - virtual public base::MemoryBase<CoreSegment, Memory> + public base::MemoryBase<CoreSegment, Memory> { using Base = base::MemoryBase<CoreSegment, Memory>; public: - Memory(); - Memory(const std::string& name); - Memory(const MemoryID& id); + + using Base::MemoryBase; Memory(const Memory& other); Memory& operator=(const Memory& other); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp index ae84449bb7a55ccf5d7a525b5b27f50c34fb3815..04d906cca6fd8429e848662ae8685d9da19e7056 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp @@ -2,38 +2,15 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include "error.h" +#include "TypeIO.h" namespace armarx::armem::d_ltm { - ProviderSegment::ProviderSegment() - { - } - - ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(MemoryID().withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(parentID.withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(parentID.withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(id, aronType) - { - } - ProviderSegment::ProviderSegment(const ProviderSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, Entity>, ProviderSegment>(other), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(other) + Base(other), + path(other.path) { } @@ -106,7 +83,10 @@ namespace armarx::armem::d_ltm if (d.is_regular_file()) { - readAronType(d.path()); + if (auto type = TypeIO::readAronType(d.path())) + { + _aronType = type; + } } } } @@ -115,7 +95,7 @@ namespace armarx::armem::d_ltm void ProviderSegment::append(const wm::ProviderSegment& m) { std::filesystem::create_directories(_fullPath()); - writeAronType(_fullPath()); + TypeIO::writeAronType(_aronType, _fullPath()); for (const auto& [k, s] : m.container()) { diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.h index c3a5f1dfd2b75e49d8d20c54816a793c0ba85c4b..0be4a70c1acbfa81492ef279189f4b7bac2165b7 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.h @@ -3,12 +3,10 @@ #include <filesystem> #include "../base/ProviderSegmentBase.h" -#include "detail/TypedEntityContainer.h" +#include "../workingmemory/ProviderSegment.h" #include "Entity.h" -#include "../workingmemory/ProviderSegment.h" - namespace armarx::armem::d_ltm { @@ -17,16 +15,13 @@ namespace armarx::armem::d_ltm * @brief Data of a provider segment containing multiple entities. */ class ProviderSegment : - virtual public base::ProviderSegmentBase<Entity, ProviderSegment>, - virtual public detail::TypedEntityContainer<Entity, ProviderSegment> + public base::ProviderSegmentBase<Entity, ProviderSegment> { using Base = base::ProviderSegmentBase<Entity, ProviderSegment>; public: - ProviderSegment(); - ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + + using Base::ProviderSegmentBase; ProviderSegment(const ProviderSegment& other); ProviderSegment& operator=(const ProviderSegment& other); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc7f7a83706c7b9f69cc05a6e81bcf810c10a249 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.cpp @@ -0,0 +1,71 @@ +#include "TypeIO.h" + +#include <iostream> +#include <fstream> +#include <filesystem> + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> + + +namespace armarx::armem::d_ltm +{ + + aron::typenavigator::ObjectNavigatorPtr TypeIO::unwrapType(const aron::typenavigator::ObjectNavigatorPtr& type) + { + return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(type->getMemberType(TYPE_WRAPPER_DATA_FIELD)); + } + + aron::typenavigator::ObjectNavigatorPtr TypeIO::wrapType(const aron::typenavigator::ObjectNavigatorPtr& type) + { + aron::typenavigator::ObjectNavigatorPtr typeWrapped(new aron::typenavigator::ObjectNavigator()); + typeWrapped->setObjectName(type->getObjectName() + "__ltm_type_export"); + typeWrapped->addMemberType(TYPE_WRAPPER_DATA_FIELD, type); + + typeWrapped->addMemberType(TYPE_WRAPPER_TIME_STORED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); + typeWrapped->addMemberType(TYPE_WRAPPER_TIME_CREATED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); + typeWrapped->addMemberType(TYPE_WRAPPER_TIME_SENT_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); + typeWrapped->addMemberType(TYPE_WRAPPER_TIME_ARRIVED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); + typeWrapped->addMemberType(TYPE_WRAPPER_CONFIDENCE_FIELD, std::make_shared<aron::typenavigator::DoubleNavigator>()); + + return typeWrapped; + } + + aron::typenavigator::ObjectNavigatorPtr TypeIO::readAronType(const std::filesystem::__cxx11::path& filepath) + { + if (std::filesystem::is_regular_file(filepath)) + { + if (filepath.filename() == (std::string(TYPE_FILENAME) + ".json")) + { + std::ifstream ifs(filepath); + std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); + + aron::typeIO::reader::NlohmannJSONReader typeReader(file_content); + aron::typeIO::writer::NavigatorWriter navWriter; + aron::typeIO::Converter::ReadAndConvert(typeReader, navWriter); + return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); + } + } + return nullptr; + } + + void TypeIO::writeAronType(const aron::typenavigator::ObjectNavigatorPtr& type, const std::filesystem::__cxx11::path& filepath) + { + if (type) + { + std::ofstream ofs(filepath); + + aron::typeIO::writer::NlohmannJSONWriter typeWriter; + aron::typeIO::Visitor::VisitAndSetup(typeWriter, type); + std::string new_file_full_content = typeWriter.getResult().dump(2); + + ofs << new_file_full_content; + } + } + + +} diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.h b/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.h new file mode 100644 index 0000000000000000000000000000000000000000..4311bdcd7034a08b30b7c7f6ae9ee3eab0952fac --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/diskmemory/TypeIO.h @@ -0,0 +1,37 @@ +#pragma once + +#include <filesystem> + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + + +namespace armarx::armem::d_ltm +{ + + /** + * @brief An entity container with a specific (Aron) type. + */ + class TypeIO + { + public: + + static aron::typenavigator::ObjectNavigatorPtr unwrapType(const aron::typenavigator::ObjectNavigatorPtr& type); + static aron::typenavigator::ObjectNavigatorPtr wrapType(const aron::typenavigator::ObjectNavigatorPtr& type); + + static aron::typenavigator::ObjectNavigatorPtr readAronType(const std::filesystem::path& filepath); + static void writeAronType(const aron::typenavigator::ObjectNavigatorPtr& type, const std::filesystem::path& filepath); + + + private: + + static const constexpr char* TYPE_FILENAME = "type"; + static constexpr const char* TYPE_WRAPPER_DATA_FIELD = "__ARON_DATA"; + static constexpr const char* TYPE_WRAPPER_TIME_STORED_FIELD = "__WRITER_METADATA__TIME_STORED"; + static constexpr const char* TYPE_WRAPPER_TIME_CREATED_FIELD = "__ENTITY_METADATA__TIME_CREATED"; + static constexpr const char* TYPE_WRAPPER_TIME_SENT_FIELD = "__ENTITY_METADATA__TIME_SENT"; + static constexpr const char* TYPE_WRAPPER_TIME_ARRIVED_FIELD = "__ENTITY_METADATA__TIME_ARRIVED"; + static constexpr const char* TYPE_WRAPPER_CONFIDENCE_FIELD = "__ENTITY_METADATA__CONFIDENCE"; + + }; + +} diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h deleted file mode 100644 index 9163b9482dc880a667f810e43039a1ac81d52f0a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h +++ /dev/null @@ -1,100 +0,0 @@ -#pragma once - -#include <iostream> -#include <fstream> - -#include "../../base/detail/TypedEntityContainerBase.h" -#include "../Entity.h" - -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> - -namespace armarx::armem::d_ltm::detail -{ - - /** - * @brief An entity container with a specific (Aron) type. - */ - template <class _ValueT, class Derived> - class TypedEntityContainer : - virtual public base::detail::TypedEntityContainerBase<_ValueT, Entity, Derived> - { - using Base = base::detail::TypedEntityContainerBase<_ValueT, Entity, Derived>; - - public: - TypedEntityContainer& operator=(const TypedEntityContainer& other) - { - other._copySelf(*this); - return *this; - } - - protected: - aron::typenavigator::ObjectNavigatorPtr unwrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const - { - return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(t->getMemberType(TYPE_WRAPPER_DATA_FIELD)); - } - - aron::typenavigator::ObjectNavigatorPtr wrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const - { - aron::typenavigator::ObjectNavigatorPtr typeWrapped(new aron::typenavigator::ObjectNavigator()); - typeWrapped->setObjectName(t->getObjectName() + "__ltm_type_export"); - typeWrapped->addMemberType(TYPE_WRAPPER_DATA_FIELD, t); - - typeWrapped->addMemberType(TYPE_WRAPPER_TIME_STORED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(TYPE_WRAPPER_TIME_CREATED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(TYPE_WRAPPER_TIME_SENT_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(TYPE_WRAPPER_TIME_ARRIVED_FIELD, std::make_shared<aron::typenavigator::LongNavigator>()); - typeWrapped->addMemberType(TYPE_WRAPPER_CONFIDENCE_FIELD, std::make_shared<aron::typenavigator::DoubleNavigator>()); - - return typeWrapped; - } - - using Base::aronType; - void readAronType(const std::filesystem::path& d) - { - if (std::filesystem::is_regular_file(d)) - { - if (d.filename() == (std::string(TYPE_FILENAME) + ".json")) - { - std::ifstream ifs(d); - std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - - aron::typeIO::reader::NlohmannJSONReader typeReader(file_content); - aron::typeIO::writer::NavigatorWriter navWriter; - aron::typeIO::Converter::ReadAndConvert(typeReader, navWriter); - this->aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); - } - } - } - - using Base::hasAronType; - void writeAronType(const std::filesystem::path& d) - { - if (hasAronType()) - { - std::ofstream ofs; - ofs.open(d); - - aron::typeIO::writer::NlohmannJSONWriter typeWriter; - aron::typeIO::Visitor::VisitAndSetup(typeWriter, this->aronType()); - std::string new_file_full_content = typeWriter.getResult().dump(2); - - ofs << new_file_full_content; - ofs.close(); - } - } - - private: - static const constexpr char* TYPE_FILENAME = "type"; - static constexpr const char* TYPE_WRAPPER_DATA_FIELD = "__ARON_DATA"; - static constexpr const char* TYPE_WRAPPER_TIME_STORED_FIELD = "__WRITER_METADATA__TIME_STORED"; - static constexpr const char* TYPE_WRAPPER_TIME_CREATED_FIELD = "__ENTITY_METADATA__TIME_CREATED"; - static constexpr const char* TYPE_WRAPPER_TIME_SENT_FIELD = "__ENTITY_METADATA__TIME_SENT"; - static constexpr const char* TYPE_WRAPPER_TIME_ARRIVED_FIELD = "__ENTITY_METADATA__TIME_ARRIVED"; - static constexpr const char* TYPE_WRAPPER_CONFIDENCE_FIELD = "__ENTITY_METADATA__CONFIDENCE"; - }; -} diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp index 6bebc718e499ed311d3090aacd3dd6b71bc5078f..2cd7aa55c3b369a0b73dd787399db44f550b97c7 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp @@ -8,35 +8,6 @@ namespace armarx::armem::ltm { - CoreSegment::CoreSegment() - { - } - - CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(MemoryID().withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(parentID.withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(id, aronType) - { - } - - CoreSegment::CoreSegment(const CoreSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, ProviderSegment>, CoreSegment>(other), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(other) - { - } - CoreSegment& CoreSegment::operator=(const CoreSegment& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h index 59bb7830d66e1b5ec2e15c904ae967a93534b8a3..f2ee3dc7298e5921f62e98e6f6f70e0228fefc7f 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h @@ -14,17 +14,14 @@ namespace armarx::armem::ltm * @brief Data of a core segment containing multiple provider segments. */ class CoreSegment : - virtual public base::CoreSegmentBase<ProviderSegment, CoreSegment> + public base::CoreSegmentBase<ProviderSegment, CoreSegment> { using Base = base::CoreSegmentBase<ProviderSegment, CoreSegment>; public: - CoreSegment(); - CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const CoreSegment& other); + using Base::CoreSegmentBase; + CoreSegment& operator=(const CoreSegment& other); // Conversion diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp index 30c578d82a61a556720cb7089d033dc9120a16c8..92eb8e29be2d6a74303534b4ed3f825f3ba183a6 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp @@ -3,26 +3,6 @@ namespace armarx::armem::ltm { - Entity::Entity() - { - } - - Entity::Entity(const std::string& name, const MemoryID& parentID) : - base::detail::MemoryItem(parentID.withEntityName(name)) - { - } - - Entity::Entity(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - - Entity::Entity(const Entity& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<Time, EntitySnapshot>, Entity>(other) - { - } - Entity& Entity::operator=(const Entity& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h index 79d81340e35381228ffa8875c8723a349bdb4035..7bce33fe15f5a012313105a3f39a7fade99cacb7 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h @@ -29,17 +29,14 @@ namespace armarx::armem::ltm * each containing a single `AronData` object of a specific `AronType`. */ class Entity : - virtual public base::EntityBase<EntitySnapshot, Entity> + public base::EntityBase<EntitySnapshot, Entity> { using Base = base::EntityBase<EntitySnapshot, Entity>; public: - Entity(); - Entity(const std::string& name, const MemoryID& parentID = {}); - Entity(const MemoryID& id); - /// Copy the history from `other` to this. - Entity(const Entity& other); + using Base::EntityBase; + /// Copy the history from `other` to this. Entity& operator=(const Entity& other); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp index 17535db36fda2e165df2e7a41489193699ac4754..b83f77e74c84563764ab1527f828a1e31b28a978 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp @@ -13,25 +13,12 @@ namespace armarx::armem::ltm && std::abs(confidence - other.confidence) < 1e-6f; } - EntityInstance::EntityInstance() - { - } - EntityInstance::EntityInstance(const EntityInstance& other) : - MemoryItem(other.id()), + Base(other), _metadata(other._metadata) { } - EntityInstance::EntityInstance(int index, const MemoryID& parentID) : - EntityInstance(parentID.withInstanceIndex(index)) - { - } - - EntityInstance::EntityInstance(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } EntityInstance& EntityInstance::operator=(const EntityInstance& other) { @@ -65,7 +52,7 @@ namespace armarx::armem::ltm void EntityInstance::_copySelf(EntityInstance& other) const { - EntityInstanceBase<EntityInstance>::_copySelf(other); + Base::_copySelf(other); other._metadata = _metadata; } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h index ee94fbfbbe9e79dd74916612e49a4a6eee0b90cc..39225dd6eecd341035b797d5fbebc80522e11148 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h @@ -34,16 +34,15 @@ namespace armarx::armem::ltm * @brief Data of a single entity instance. */ class EntityInstance : - virtual public base::EntityInstanceBase<EntityInstance> + public base::EntityInstanceBase<EntityInstance> { using Base = base::EntityInstanceBase<EntityInstance>; public: - EntityInstance(); - EntityInstance(const EntityInstance&); - EntityInstance(int index, const MemoryID& parentID = {}); - EntityInstance(const MemoryID& id); + using Base::EntityInstanceBase; + + EntityInstance(const EntityInstance& other); EntityInstance& operator=(const EntityInstance& other); EntityInstanceMetadata& metadata() diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp index 9f3272eb9ba94c5751ea0b2d4f1c0893802eb0d6..e89154efcf545b34b6c91e355b384d21df59be3e 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp @@ -8,27 +8,6 @@ namespace armarx::armem::ltm { - - EntitySnapshot::EntitySnapshot() - { - } - - EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : - EntitySnapshot(parentID.withTimestamp(time)) - { - } - - EntitySnapshot::EntitySnapshot(const MemoryID& id) : - MemoryItem(id) - { - } - - EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) - { - } - EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h index b8c3f491dc8b87979856786abe931ab1fc7eaeb7..bea3c55b7981f1c4a43f15a3fe931df8043b3a9e 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h @@ -14,17 +14,13 @@ namespace armarx::armem::ltm * @brief Data of an entity at one point in time. */ class EntitySnapshot : - virtual public base::EntitySnapshotBase<EntityInstance, EntitySnapshot> + public base::EntitySnapshotBase<EntityInstance, EntitySnapshot> { using Base = base::EntitySnapshotBase<EntityInstance, EntitySnapshot>; public: - EntitySnapshot(); - EntitySnapshot(Time time, const MemoryID& parentID = {}); - EntitySnapshot(const MemoryID& id); - /// Copy the instances from `other` to this. - EntitySnapshot(const EntitySnapshot& other); + using Base::EntitySnapshotBase; /// Copy the instances from `other` to this. EntitySnapshot& operator=(const EntitySnapshot& other); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp index 9f216cb0338fc9ff8b7f47fa430acf99bf0cb92c..cf012cc37baac05ccaba6f62ecb1212af98eaae6 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp @@ -9,27 +9,6 @@ namespace armarx::armem::ltm { - Memory::Memory() - { - } - - Memory::Memory(const std::string& name) : - base::detail::MemoryItem(MemoryID().withMemoryName(name)) - { - } - - Memory::Memory(const MemoryID& id) : - MemoryItem(id) - { - } - - Memory::Memory(const Memory& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, CoreSegment>, Memory>(other) - { - *this = other; - } - Memory& Memory::operator=(const Memory& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h index 1085de776eda6ac8e913d24c840b867a7fef969d..dcf6b7e559862533818f4cadd7fdb263b41f0e88 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h @@ -13,16 +13,14 @@ namespace armarx::armem::ltm * @brief Data of a memory consisting of multiple core segments. */ class Memory : - virtual public base::MemoryBase<CoreSegment, Memory> + public base::MemoryBase<CoreSegment, Memory> { using Base = base::MemoryBase<CoreSegment, Memory>; public: - Memory(); - Memory(const std::string& name); - Memory(const MemoryID& id); - Memory(const Memory& other); + using Base::MemoryBase; + Memory& operator=(const Memory& other); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp index dbdbdb1189fd2efdac397992b3cad480da77f863..80e6187864145bc60474ac2183cf8d11da857b16 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp @@ -8,35 +8,6 @@ namespace armarx::armem::ltm { - ProviderSegment::ProviderSegment() - { - } - - ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(MemoryID().withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(parentID.withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(parentID.withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(id, aronType) - { - } - - ProviderSegment::ProviderSegment(const ProviderSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, Entity>, ProviderSegment>(other), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(other) - { - } - ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h index 5ac77dad663e34a3b3da6d39c53629d6a9415864..7b3cbcc01e2c06da14a8325d5618c372cce0a246 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h @@ -14,17 +14,14 @@ namespace armarx::armem::ltm * @brief Data of a provider segment containing multiple entities. */ class ProviderSegment : - virtual public base::ProviderSegmentBase<Entity, ProviderSegment> + public base::ProviderSegmentBase<Entity, ProviderSegment> { using Base = base::ProviderSegmentBase<Entity, ProviderSegment>; public: - ProviderSegment(); - ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const ProviderSegment& other); + using Base::ProviderSegmentBase; + ProviderSegment& operator=(const ProviderSegment& other); // Conversion diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp index 4ef52fd749f9106d4ea1e9204fd0574392c18387..21889472fb1a4d963c3fb5e2a466a1b178c20860 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp @@ -8,54 +8,21 @@ namespace armarx::armem::wm { - CoreSegment::CoreSegment() - { - } - - CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(MemoryID().withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withCoreSegmentName(name)), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(parentID.withCoreSegmentName(name), aronType) - { - } - - CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(id, aronType) - { - } - - CoreSegment::CoreSegment(const CoreSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, ProviderSegment>, CoreSegment>(other), - base::detail::TypedEntityContainerBase<ProviderSegment, Entity, CoreSegment>(other) - { - } - - CoreSegment& CoreSegment::operator=(const CoreSegment& other) - { - other._copySelf(*this); - return *this; - } - - CoreSegment CoreSegment::copyWithoutData() const - { - CoreSegment m; - _copySelfWithoutData(m); - return m; - } + /* + CoreSegment& CoreSegment::operator=(const CoreSegment& other) + { + other._copySelf(*this); + return *this; + } + */ - void CoreSegment::_copySelfWithoutData(CoreSegment& o) const + void CoreSegment::_copySelfWithoutData(CoreSegment& other) const { - detail::TypedEntityContainer<ProviderSegment, CoreSegment>::_copySelfWithoutData(o); - for (const auto& [k, s] : o) + other.id() = _id; + other.setMaxHistorySize(_maxHistorySize); + for (const auto& [k, s] : _container) { - o.addProviderSegment(s.copyWithoutData()); + other.addProviderSegment(s.copyWithoutData()); } } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h index d727b408bb9672afdbf842d742f27e889ea96489..74b168235ccfa36a2cfb1788ed7bab47b28b4822 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h @@ -3,7 +3,7 @@ #include "../base/CoreSegmentBase.h" #include "ProviderSegment.h" -#include "detail/TypedEntityContainer.h" +#include "detail/CopyWithoutData.h" namespace armarx::armem::wm @@ -13,24 +13,23 @@ namespace armarx::armem::wm * @brief Data of a core segment containing multiple provider segments. */ class CoreSegment : - virtual public base::CoreSegmentBase<ProviderSegment, CoreSegment>, - virtual public detail::TypedEntityContainer<ProviderSegment, CoreSegment> + public base::CoreSegmentBase<ProviderSegment, CoreSegment>, + public detail::CopyWithoutData<CoreSegment> { using Base = base::CoreSegmentBase<ProviderSegment, CoreSegment>; public: - CoreSegment(); - CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - CoreSegment(const CoreSegment& other); - CoreSegment& operator=(const CoreSegment& other); + using Base::CoreSegmentBase; + virtual ~CoreSegment() override = default; + + // CoreSegment& operator=(const CoreSegment& other); - CoreSegment copyWithoutData() const override; protected: - virtual void _copySelfWithoutData(CoreSegment& o) const override; + + virtual void _copySelfWithoutData(CoreSegment& other) const override; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp index 37b930656d8810ea0445c412d8992c23db2458aa..6d129eaa2f06df4ed53341bd8de6cc082d56f9f6 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp @@ -3,45 +3,21 @@ namespace armarx::armem::wm { - Entity::Entity() - { - } - - Entity::Entity(const std::string& name, const MemoryID& parentID) : - base::detail::MemoryItem(parentID.withEntityName(name)) - { - } - - Entity::Entity(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - - Entity::Entity(const Entity& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<Time, EntitySnapshot>, Entity>(other) - { - } - - Entity& Entity::operator=(const Entity& other) - { - other._copySelf(*this); - return *this; - } - - Entity Entity::copyWithoutData() const - { - Entity m; - _copySelfWithoutData(m); - return m; - } + /* + Entity& Entity::operator=(const Entity& other) + { + other._copySelf(*this); + return *this; + } + */ - void Entity::_copySelfWithoutData(Entity& o) const + void Entity::_copySelfWithoutData(Entity& other) const { - detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity>::_copySelfWithoutData(o); - for (const auto& [k, s] : o) + other.id() = _id; + other.setMaxHistorySize(_maxHistorySize); + for (const auto& [k, s] : _container) { - o.addSnapshot(s.copyWithoutData()); + other.addSnapshot(s.copyWithoutData()); } } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h index 9d213e92f0d6756e90cf9fd7090f472ce52effa5..a0c14ed9c7ea86a5b3697d0a303d244526f091e2 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h @@ -3,7 +3,7 @@ #include "../base/EntityBase.h" #include "EntitySnapshot.h" -#include "detail/MemoryContainer.h" +#include "detail/CopyWithoutData.h" namespace armarx::armem::wm @@ -28,25 +28,23 @@ namespace armarx::armem::wm * each containing a single `AronData` object of a specific `AronType`. */ class Entity : - virtual public base::EntityBase<EntitySnapshot, Entity>, - virtual public detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity> + public base::EntityBase<EntitySnapshot, Entity>, + public detail::CopyWithoutData<Entity> { using Base = base::EntityBase<EntitySnapshot, Entity>; public: - Entity(); - Entity(const std::string& name, const MemoryID& parentID = {}); - Entity(const MemoryID& id); - /// Copy the history from `other` to this. - Entity(const Entity& other); - /// Copy the history from `other` to this. - Entity& operator=(const Entity& other); + using Base::EntityBase; + virtual ~Entity() override = default; + + //Entity& operator=(const Entity& other); - Entity copyWithoutData() const override; protected: - virtual void _copySelfWithoutData(Entity& o) const override; + + virtual void _copySelfWithoutData(Entity& other) const override; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp index cc2aed88a9dd43f326cde8cc8448bbee466369b0..4d8de5156949c61b18c059494971924df92d4a88 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp @@ -14,32 +14,21 @@ namespace armarx::armem::wm && std::abs(confidence - other.confidence) < 1e-6f; } - EntityInstance::EntityInstance() - { - } + /* EntityInstance::EntityInstance(const EntityInstance& other) : - base::detail::MemoryItem(other.id()), + Base(other), _metadata(other._metadata), _data(other._data) { } - EntityInstance::EntityInstance(int index, const MemoryID& parentID) : - EntityInstance(parentID.withInstanceIndex(index)) - { - } - - EntityInstance::EntityInstance(const MemoryID& id) : - base::detail::MemoryItem(id) - { - } - EntityInstance& EntityInstance::operator=(const EntityInstance& other) { other._copySelf(*this); return *this; } + */ bool EntityInstance::equalsDeep(const EntityInstance& other) const @@ -70,22 +59,16 @@ namespace armarx::armem::wm return d; } - EntityInstance EntityInstance::copyWithoutData() const - { - EntityInstance d; - this->_copySelfWithoutData(d); - return d; - } - void EntityInstance::_copySelf(EntityInstance& other) const { - EntityInstanceBase<EntityInstance>::_copySelf(other); + Base::_copySelf(other); other._metadata = _metadata; other._data = _data; } void EntityInstance::_copySelfWithoutData(EntityInstance& other) const { - EntityInstanceBase<EntityInstance>::_copySelf(other); + Base::_copySelf(other); + other._metadata = _metadata; } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h index cbfe38200b129cdcbd32819560fda6cfb2cbdaa0..0a289c7870dd985f90d008a8fe9bca7dee1f0eb5 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h @@ -2,6 +2,9 @@ #include "../base/EntityInstanceBase.h" +#include "detail/CopyWithoutData.h" + + namespace armarx::armem::wm { @@ -32,17 +35,19 @@ namespace armarx::armem::wm * @brief Data of a single entity instance. */ class EntityInstance : - virtual public base::EntityInstanceBase<EntityInstance> + public base::EntityInstanceBase<EntityInstance>, + public detail::CopyWithoutData<EntityInstance> { using Base = base::EntityInstanceBase<EntityInstance>; public: - EntityInstance(); - EntityInstance(const EntityInstance&); - EntityInstance(int index, const MemoryID& parentID = {}); - EntityInstance(const MemoryID& id); + using Base::EntityInstanceBase; + + /* + EntityInstance(const EntityInstance& other); EntityInstance& operator=(const EntityInstance& other); + */ EntityInstanceMetadata& metadata() { @@ -74,18 +79,21 @@ namespace armarx::armem::wm virtual bool equalsDeep(const EntityInstance& other) const override; virtual EntityInstance copy() const override; - virtual EntityInstance copyWithoutData() const; + protected: + virtual void _copySelf(EntityInstance& other) const override; - virtual void _copySelfWithoutData(EntityInstance& other) const; + virtual void _copySelfWithoutData(EntityInstance& other) const override; private: + /// The metadata. EntityInstanceMetadata _metadata; /// The data. May be nullptr. armarx::aron::datanavigator::DictNavigatorPtr _data; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp index c33dd71b23b3c2c16c4b95894af63b46485d8ca2..6ce3103c378499124fb26d526db1ef3d936b9326 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp @@ -8,50 +8,20 @@ namespace armarx::armem::wm { + /* + EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) + { + other._copySelf(*this); + return *this; + } + */ - EntitySnapshot::EntitySnapshot() - { - } - - EntitySnapshot::EntitySnapshot(Time time, const MemoryID& parentID) : - EntitySnapshot(parentID.withTimestamp(time)) - { - } - - EntitySnapshot::EntitySnapshot(const MemoryID& id) : - MemoryItem(id) - { - } - - EntitySnapshot::~EntitySnapshot() - { - } - - EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) - { - } - - EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) - { - other._copySelf(*this); - return *this; - } - - EntitySnapshot EntitySnapshot::copyWithoutData() const - { - EntitySnapshot m; - _copySelfWithoutData(m); - return m; - } - - void EntitySnapshot::_copySelfWithoutData(EntitySnapshot& o) const + void EntitySnapshot::_copySelfWithoutData(EntitySnapshot& other) const { - detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot>::_copySelfWithoutData(o); - for (const auto& s : o) + other.id() = _id; + for (const auto& s : _container) { - o.addInstance(s.copyWithoutData()); + other.addInstance(s.copyWithoutData()); } } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h index 50332bf163f4b4595b0e53b64f3acf3497f3332c..5b4b80c0b8f97078c27beae30e2100510e4da449 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h @@ -3,7 +3,7 @@ #include "../base/EntitySnapshotBase.h" #include "EntityInstance.h" -#include "detail/MemoryContainer.h" +#include "detail/CopyWithoutData.h" namespace armarx::armem::wm @@ -13,32 +13,25 @@ namespace armarx::armem::wm * @brief Data of an entity at one point in time. */ class EntitySnapshot : - virtual public base::EntitySnapshotBase<EntityInstance, EntitySnapshot>, - virtual public detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot> + public base::EntitySnapshotBase<EntityInstance, EntitySnapshot>, + public detail::CopyWithoutData<EntitySnapshot> { using Base = base::EntitySnapshotBase<EntityInstance, EntitySnapshot>; public: - EntitySnapshot(); - EntitySnapshot(Time time, const MemoryID& parentID = {}); - EntitySnapshot(const MemoryID& id); - - virtual ~EntitySnapshot() override; - - - /// Copy the instances from `other` to this. - EntitySnapshot(const EntitySnapshot& other); + using Base::EntitySnapshotBase; + virtual ~EntitySnapshot() override = default; + /* /// Copy the instances from `other` to this. EntitySnapshot& operator=(const EntitySnapshot& other); - - EntitySnapshot copyWithoutData() const override; + */ protected: - virtual void _copySelfWithoutData(EntitySnapshot& o) const override; + virtual void _copySelfWithoutData(EntitySnapshot& other) const override; }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp index a5b1e4ab1346ed3b3d041320c4eade4d31176ced..85aa8c394b0b641bd354ea1108aef8681e2c2724 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp @@ -1,54 +1,17 @@ #include "Memory.h" -#include <ArmarXCore/core/logging/Logging.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "error.h" - namespace armarx::armem::wm { - Memory::Memory() - { - } - - Memory::Memory(const std::string& name) : - base::detail::MemoryItem(MemoryID().withMemoryName(name)) - { - } - - Memory::Memory(const MemoryID& id) : - MemoryItem(id) - { - } - - Memory::Memory(const Memory& other) : - base::detail::MemoryItem(other), - MemoryContainerBase<std::map<std::string, CoreSegment>, Memory>(other) - { - *this = other; - } - - Memory& Memory::operator=(const Memory& other) - { - other._copySelf(*this); - return *this; - } - - Memory Memory::copyWithoutData() const - { - Memory m; - _copySelfWithoutData(m); - return m; - } + static Memory _memory("mymem"); - void Memory::_copySelfWithoutData(Memory& o) const + void Memory::_copySelfWithoutData(Memory& other) const { - detail::EntityContainer<CoreSegment, Memory>::_copySelfWithoutData(o); - for (const auto& [k, s] : o) + other.id() = _id; + for (const auto& [k, s] : _container) { - o.addCoreSegment(s.copyWithoutData()); + other.addCoreSegment(s.copyWithoutData()); } } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h index d747ded5ef9618a9c4a2c891c493e3816c15a851..463695b4431764b8447029c2c18b7a7035887bf8 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h @@ -3,7 +3,8 @@ #include "../base/MemoryBase.h" #include "CoreSegment.h" -#include "detail/EntityContainer.h" +#include "detail/CopyWithoutData.h" + namespace armarx::armem::wm { @@ -12,22 +13,20 @@ namespace armarx::armem::wm * @brief Data of a memory consisting of multiple core segments. */ class Memory : - virtual public base::MemoryBase<CoreSegment, Memory>, - virtual public detail::EntityContainer<CoreSegment, Memory> + public base::MemoryBase<CoreSegment, Memory>, + public detail::CopyWithoutData<Memory> { using Base = base::MemoryBase<CoreSegment, Memory>; public: - Memory(); - Memory(const std::string& name); - Memory(const MemoryID& id); - Memory(const Memory& other); - Memory& operator=(const Memory& other); + using Base::MemoryBase; + virtual ~Memory() override = default; - Memory copyWithoutData() const override; protected: - virtual void _copySelfWithoutData(Memory& o) const override; + + virtual void _copySelfWithoutData(Memory& other) const override; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp index 3b90c745c53a60c5d95feda1adc131c300d61beb..13d70a332e3e1e95f59f205b749ede5834e25181 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp @@ -8,54 +8,22 @@ namespace armarx::armem::wm { - ProviderSegment::ProviderSegment() - { - } - - ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(MemoryID().withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(MemoryID().withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(parentID.withProviderSegmentName(name)), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(parentID.withProviderSegmentName(name), aronType) - { - } - - ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : - base::detail::MemoryItem(id), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(id, aronType) - { - } - - ProviderSegment::ProviderSegment(const ProviderSegment& other) : - base::detail::MemoryItem(other), - base::detail::MemoryContainerBase<std::map<std::string, Entity>, ProviderSegment>(other), - base::detail::TypedEntityContainerBase<Entity, Entity, ProviderSegment>(other) - { - } - - ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) - { - other._copySelf(*this); - return *this; - } + /* + ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) + { + other._copySelf(*this); + return *this; + } + */ - ProviderSegment ProviderSegment::copyWithoutData() const - { - ProviderSegment m; - _copySelfWithoutData(m); - return m; - } - void ProviderSegment::_copySelfWithoutData(ProviderSegment& o) const + void ProviderSegment::_copySelfWithoutData(ProviderSegment& other) const { - detail::TypedEntityContainer<Entity, ProviderSegment>::_copySelfWithoutData(o); - for (const auto& [k, s] : o) + other.id() = _id; + other.setMaxHistorySize(_maxHistorySize); + for (const auto& [k, s] : _container) { - o.addEntity(s.copyWithoutData()); + other.addEntity(s.copyWithoutData()); } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h index 542ec3dc5ee0fc2dcbbface02bf11006eaa497a1..30e9e6e995c5a861a6e6165117c0dde703351627 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h @@ -3,7 +3,7 @@ #include "../base/ProviderSegmentBase.h" #include "Entity.h" -#include "detail/TypedEntityContainer.h" +#include "detail/CopyWithoutData.h" namespace armarx::armem::wm @@ -13,24 +13,24 @@ namespace armarx::armem::wm * @brief Data of a provider segment containing multiple entities. */ class ProviderSegment : - virtual public base::ProviderSegmentBase<Entity, ProviderSegment>, - virtual public detail::TypedEntityContainer<Entity, ProviderSegment> + public base::ProviderSegmentBase<Entity, ProviderSegment>, + public detail::CopyWithoutData<ProviderSegment> + { using Base = base::ProviderSegmentBase<Entity, ProviderSegment>; public: - ProviderSegment(); - ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); - ProviderSegment(const ProviderSegment& other); - ProviderSegment& operator=(const ProviderSegment& other); + using Base::ProviderSegmentBase; + virtual ~ProviderSegment() override = default; + + // ProviderSegment& operator=(const ProviderSegment& other); - ProviderSegment copyWithoutData() const override; protected: - virtual void _copySelfWithoutData(ProviderSegment& o) const override; + + virtual void _copySelfWithoutData(ProviderSegment& other) const override; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..70441033dd0fcb24a502bcd4e552764c7c2f5d3c --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp @@ -0,0 +1 @@ +#include "CopyWithoutData.h" diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h new file mode 100644 index 0000000000000000000000000000000000000000..caabd1e6002c803aa6a1015afd7ce660abd2482f --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h @@ -0,0 +1,30 @@ +#pragma once + + +namespace armarx::armem::wm::detail +{ + + /** + * @class Allows copying `*this` without data in the leaf + * data structures. + */ + template <class DerivedT> + class CopyWithoutData + { + public: + + /// Get a copy of `this` without data. + virtual DerivedT copyWithoutData() const + { + DerivedT t; + _copySelfWithoutData(t); + return t; + } + + + protected: + + virtual void _copySelfWithoutData(DerivedT& other) const = 0; + + }; +} diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.cpp deleted file mode 100644 index 20872a805368246aca047563e0094b055568e8db..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "EntityContainer.h" diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.h b/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.h deleted file mode 100644 index 431d13624ab3f004020d13ba77c3fdf4a60c380d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/EntityContainer.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../base/detail/EntityContainerBase.h" -#include "MemoryContainer.h" - -#include "../Entity.h" -#include "../EntitySnapshot.h" -#include "../EntityInstance.h" - - -namespace armarx::armem::wm::detail -{ - - /** - * @brief A container of entities at some point in the hierarchy. - * - * Can be updated by multiple entity updates. - */ - template <class _ValueT, class _Derived> - class EntityContainer : - virtual public base::detail::EntityContainerBase<_ValueT, Entity, _Derived>, - virtual public MemoryContainer<std::map<std::string, _ValueT>, _Derived> - { - public: - EntityContainer& operator=(const EntityContainer& other) - { - other._copySelf(*this); - return *this; - } - }; - -} diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.cpp deleted file mode 100644 index 733cd6f240a52944d6c18fb60bab928242b5b122..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MemoryContainer.h" diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.h deleted file mode 100644 index a915c8714a299ab18a671c18814c77441d6b28af..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/MemoryContainer.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "../../error.h" - -#include "../../base/detail/MemoryContainerBase.h" - - -namespace armarx::armem::wm::detail -{ - - /** - * @class Provides default implmentations of `MemoryContainer`, as well as - * iterators (which requires a template). - */ - template <class _ContainerT, class _Derived> - class MemoryContainer : - virtual public base::detail::MemoryContainerBase<_ContainerT, _Derived> - { - using Base = base::detail::MemoryContainerBase<_ContainerT, _Derived>; - - public: - MemoryContainer& operator=(const MemoryContainer& other) - { - other._copySelf(*this); - return *this; - } - - // Copying - virtual _Derived copyWithoutData() const - { - _Derived t; - _copySelfWithoutData(t); - return t; - } - - protected: - virtual void _copySelfWithoutData(_Derived& o) const - { - Base::_copySelfEmpty(o); - } - }; -} diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.cpp deleted file mode 100644 index 7bec77f349c1e45f7a434d499a5a8b1c952b3317..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "TypedEntityContainer.h" diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.h deleted file mode 100644 index f90925ff1de57a63542dd70adadff1e762224783..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/TypedEntityContainer.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../base/detail/TypedEntityContainerBase.h" -#include "EntityContainer.h" - -#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> - -namespace armarx::armem::wm::detail -{ - - /** - * @brief An entity container with a specific (Aron) type. - */ - template <class _ValueT, class _Derived> - class TypedEntityContainer : - virtual public base::detail::TypedEntityContainerBase<_ValueT, Entity, _Derived>, - virtual public EntityContainer<_ValueT, _Derived> - { - public: - TypedEntityContainer& operator=(const TypedEntityContainer& other) - { - other._copySelf(*this); - return *this; - } - }; -}