diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h index b80ca2ccd5931c9c3f3f2c11c309fbd3c2fde442..609920d1e6e80054f4526fffe4e76eca2c4a43a5 100644 --- a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h @@ -22,21 +22,27 @@ namespace armarx::armem::base using Base = detail::TypedEntityContainerBase<_ProviderSegmentT, typename _ProviderSegmentT::EntityT, _Derived>; public: + + using typename Base::DerivedT; + using typename Base::ContainerT; + using ProviderSegmentT = _ProviderSegmentT; using EntityT = typename ProviderSegmentT::EntityT; using EntitySnapshotT = typename EntityT::EntitySnapshotT; using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + public: + CoreSegmentBase& operator=(const CoreSegmentBase& other) { other._copySelf(*this); return *this; } - using Base::id; inline const std::string& name() const { - return id.coreSegmentName; + return this->id().coreSegmentName; } inline std::string& name() { @@ -44,10 +50,9 @@ namespace armarx::armem::base } - using Base::container; inline const std::map<std::string, ProviderSegmentT>& providerSegments() const { - return container; + return _container; } inline std::map<std::string, ProviderSegmentT>& providerSegments() { @@ -57,7 +62,7 @@ namespace armarx::armem::base bool hasProviderSegment(const std::string& name) const { - return container.count(name) > 0; + return _container.count(name) > 0; } ProviderSegmentT& getProviderSegment(const std::string& name) @@ -67,8 +72,8 @@ namespace armarx::armem::base const ProviderSegmentT& getProviderSegment(const std::string& name) const { - auto it = this->container.find(name); - if (it != container.end()) + auto it = this->_container.find(name); + if (it != _container.end()) { return it->second; } @@ -89,8 +94,8 @@ namespace armarx::armem::base { _checkContainerName(update.entityID.coreSegmentName, this->name()); - auto it = this->container.find(update.entityID.providerSegmentName); - if (it != container.end()) + auto it = this->_container.find(update.entityID.providerSegmentName); + if (it != _container.end()) { return it->second.update(update); } @@ -108,7 +113,7 @@ namespace armarx::armem::base */ ProviderSegmentT& addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType = nullptr) { - aron::typenavigator::ObjectNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType; + aron::typenavigator::ObjectNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType(); return addProviderSegment(ProviderSegmentT(name, type)); } @@ -127,9 +132,9 @@ namespace armarx::armem::base providerSegment.getLevelName(), providerSegment.name(), getLevelName(), this->getKeyString()); } - auto it = container.emplace(providerSegment.name(), std::move(providerSegment)).first; - it->second.id.setCoreSegmentID(id); - it->second.setMaxHistorySize(maxHistorySize); + auto it = _container.emplace(providerSegment.name(), std::move(providerSegment)).first; + it->second.id().setCoreSegmentID(this->id()); + it->second.setMaxHistorySize(_maxHistorySize); return it->second; } @@ -142,21 +147,20 @@ namespace armarx::armem::base void setMaxHistorySize(long maxSize) override { MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, seg] : container) + for (auto& [name, seg] : _container) { seg.setMaxHistorySize(maxSize); } } - using Base::size; virtual bool equalsDeep(const CoreSegmentBase& other) const { //std::cout << "CoreSegment::equalsDeep" << std::endl; - if (size() != other.size()) + if (this->size() != other.size()) { return false; } - for (const auto& [key, provider] : container) + for (const auto& [key, provider] : _container) { if (not other.hasProviderSegment(key)) { @@ -180,7 +184,10 @@ namespace armarx::armem::base return this->name(); } - public: + + protected: + + using Base::_container; }; diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index 08e7dc5bce3da50a4d1f479c6a88b4c57f87f98e..fa884ee115624b437182f35df5744863f206ddb2 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -5,10 +5,13 @@ #include <SimoxUtility/algorithm/get_map_keys_values.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + #include "../../core/Time.h" #include "../../core/MemoryID.h" #include "EntitySnapshotBase.h" +#include "detail/MaxHistorySize.h" #include "detail/MemoryContainerBase.h" @@ -36,29 +39,37 @@ namespace armarx::armem::base */ template <class _EntitySnapshotT, class _Derived> class EntityBase : - virtual public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived> + virtual public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>, + virtual public detail::MaxHistorySize { using Base = detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>; public: + + using typename Base::DerivedT; + using typename Base::ContainerT; + using EntitySnapshotT = _EntitySnapshotT; using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + public: + EntityBase& operator=(const EntityBase& other) { other._copySelf(*this); return *this; } - using Base::size; + virtual bool equalsDeep(const EntityBase& other) const { //std::cout << "Entity::equalsDeep" << std::endl; - if (size() != other.size()) + if (this->size() != other.size()) { return false; } - for (const auto& [key, snapshot] : container) + for (const auto& [key, snapshot] : _container) { if (not other.hasSnapshot(key)) { @@ -73,10 +84,9 @@ namespace armarx::armem::base } - using Base::id; inline const std::string& name() const { - return id.entityName; + return this->id().entityName; } inline std::string& name() { @@ -84,10 +94,9 @@ namespace armarx::armem::base } - using Base::container; inline const std::map<Time, EntitySnapshotT>& history() const { - return container; + return _container; } inline std::map<Time, EntitySnapshotT>& history() { @@ -100,7 +109,7 @@ namespace armarx::armem::base */ bool hasSnapshot(Time time) const { - return container.count(time) > 0; + return _container.count(time) > 0; } /** @@ -117,7 +126,7 @@ namespace armarx::armem::base */ std::vector<Time> getTimestamps() const { - return simox::alg::get_keys(container); + return simox::alg::get_keys(_container); } @@ -136,14 +145,14 @@ namespace armarx::armem::base const EntitySnapshotT& getSnapshot(Time time) const { - auto it = container.find(time); - if (it != container.end()) + auto it = _container.find(time); + if (it != _container.end()) { return it->second; } else { - throw error::MissingEntry("entity snapshot", toDateTimeMilliSeconds(time), getLevelName(), this->id.str()); + throw error::MissingEntry("entity snapshot", toDateTimeMilliSeconds(time), getLevelName(), this->id().str()); } } @@ -183,12 +192,12 @@ namespace armarx::armem::base virtual MemoryID update(const EntityUpdate& update) { checkEntityName(update.entityID.entityName); - id = update.entityID; + this->id() = update.entityID; EntitySnapshotT* snapshot; - auto it = container.find(update.timeCreated); - if (it == container.end()) + auto it = _container.find(update.timeCreated); + if (it == _container.end()) { // Insert into history. snapshot = &addSnapshot(update.timeCreated); @@ -201,7 +210,7 @@ namespace armarx::armem::base // Update entry. snapshot->update(update); - return snapshot->id; + return snapshot->id(); } /** @@ -216,8 +225,8 @@ namespace armarx::armem::base EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot) { - auto it = container.emplace(snapshot.time(), std::move(snapshot)).first; - it->second.id.setEntityID(id); + auto it = _container.emplace(snapshot.time(), std::move(snapshot)).first; + it->second.id().setEntityID(this->id()); return it->second; } @@ -232,15 +241,15 @@ namespace armarx::armem::base * * The current history is truncated if necessary. */ - void setMaxHistorySize(long maxSize) + void setMaxHistorySize(long maxSize) override { - this->maxHistorySize = maxSize; + MaxHistorySize::setMaxHistorySize(maxSize); truncateHistoryToSize(); } std::string getKeyString() const override { - return id.entityName; + return this->id().entityName; } std::string getLevelName() const override { @@ -261,28 +270,32 @@ namespace armarx::armem::base return d; } + protected: - virtual void _copySelf(_Derived& other) const override + + virtual void _copySelf(DerivedT& other) const override { Base::_copySelf(other); } - virtual void _copySelfEmpty(_Derived& other) const override + virtual void _copySelfEmpty(DerivedT& other) const override { Base::_copySelfEmpty(other); } + private: + /// If maximum size is set, ensure `history`'s is not higher. void truncateHistoryToSize() { - if (maxHistorySize >= 0) + if (_maxHistorySize >= 0) { - while (container.size() > size_t(maxHistorySize)) + while (_container.size() > size_t(_maxHistorySize)) { - container.erase(container.begin()); + _container.erase(_container.begin()); } - ARMARX_CHECK_LESS_EQUAL(container.size(), maxHistorySize); + ARMARX_CHECK_LESS_EQUAL(_container.size(), _maxHistorySize); } } @@ -301,22 +314,18 @@ namespace armarx::armem::base */ const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const { - if (container.empty()) + if (_container.empty()) { throw armem::error::EntityHistoryEmpty(name(), "when getting the latest snapshot."); } - return *container.rbegin(); + return *_container.rbegin(); } - public: - /** - * @brief Maximum size of `history` - * - * If negative, the size of `history` is not limited. - */ - long maxHistorySize = -1; - // ToDo: Add max age; - // ToDo in future: keep/remove predicate + + 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 1b82abd4110ba59b57e305de0a0e43841d97622d..c8609ac6280dcab6edb4d5bba6a96b08741cb282 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h @@ -11,7 +11,7 @@ namespace armarx::armem::base /** * @brief Data of a single entity instance. */ - template <class _Derived> + template <class _DerivedT> class EntityInstanceBase : virtual public detail::MemoryItem { @@ -20,25 +20,30 @@ namespace armarx::armem::base public: EntityInstanceBase& operator=(const EntityInstanceBase& other) + using DerivedT = _DerivedT; + + + public: + { //other._copySelf(*this); return *this; } - using Base::id; + inline int& index() { - return id.instanceIndex; + return id().instanceIndex; } inline int index() const { - return id.instanceIndex; + return id().instanceIndex; } // Copying - virtual _Derived copy() const + virtual DerivedT copy() const { - _Derived d; + DerivedT d; this->_copySelf(d); return d; } @@ -50,7 +55,9 @@ namespace armarx::armem::base */ virtual void update(const EntityUpdate& update, int index) = 0; - virtual bool equalsDeep(const _Derived& other) const = 0; + + virtual bool equalsDeep(const DerivedT& other) const = 0; + std::string getLevelName() const override { @@ -65,7 +72,7 @@ namespace armarx::armem::base protected: - virtual void _copySelf(_Derived& other) const + virtual void _copySelf(DerivedT& other) const { Base::_copySelf(other); } diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h index 408423b725a79b65a32946fc40adb61399dbb606..094608e2927991f5593922887ec17e11fe6ce440 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h @@ -22,24 +22,30 @@ namespace armarx::armem::base using Base = detail::MemoryContainerBase<std::vector<_EntityInstanceT>, _Derived>; public: + + using typename Base::DerivedT; + using typename Base::ContainerT; + using EntityInstanceT = _EntityInstanceT; + + public: + EntitySnapshotBase& operator=(const EntitySnapshotBase& other) { other._copySelf(*this); return *this; } - using Base::size; virtual bool equalsDeep(const EntitySnapshotBase& other) const { //std::cout << "EntitySnapshot::equalsDeep" << std::endl; - if (size() != other.size()) + if (this->size() != other.size()) { return false; } int i = 0; - for (const auto& instance : container) + for (const auto& instance : _container) { if (not instance.equalsDeep(other.getInstance(i))) { @@ -50,22 +56,20 @@ namespace armarx::armem::base return true; } - using Base::id; inline Time& time() { - return id.timestamp; + return this->id().timestamp; } inline const Time& time() const { - return id.timestamp; + return this->id().timestamp; } - using Base::container; inline const std::vector<EntityInstanceT>& instances() const { - return container; + return _container; } inline std::vector<EntityInstanceT>& instances() { @@ -77,14 +81,14 @@ namespace armarx::armem::base { if (parentID) { - id = *parentID; + this->id() = *parentID; } time() = update.timeCreated; - container.clear(); + _container.clear(); for (int i = 0; i < int(update.instancesData.size()); ++i) { - EntityInstanceT& data = container.emplace_back(i, id); + EntityInstanceT& data = _container.emplace_back(i, this->id()); data.update(update, i); } } @@ -93,7 +97,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 < _container.size(); } /** @@ -111,8 +115,7 @@ namespace armarx::armem::base { if (hasInstance(index)) { - size_t si = size_t(index); - return container[si]; + return _container[static_cast<size_t>(index)]; } else { @@ -155,19 +158,19 @@ namespace armarx::armem::base EntityInstanceT& addInstance(EntityInstanceT&& instance) { - if (instance.index() > 0 && (size_t) instance.index() < container.size()) + if (instance.index() > 0 && static_cast<size_t>(instance.index()) < _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 && (size_t) instance.index() > container.size()) + if (instance.index() > 0 && static_cast<size_t>(instance.index()) > _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 = _container.size(); + auto& it = _container.emplace_back(std::move(instance)); it.index() = new_index; return it; } @@ -182,7 +185,11 @@ namespace armarx::armem::base return "entity snapshot"; } - public: + + 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 084e2ff9e3dfa465a2d6c1cc9b94c6a742122f84..0d4c8020910ac140e61df0540136f2bcb0094e43 100644 --- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h @@ -3,9 +3,12 @@ #include <map> #include <string> +#include <ArmarXCore/core/logging/Logging.h> + #include "CoreSegmentBase.h" #include "detail/EntityContainerBase.h" + namespace armarx::armem::base { @@ -19,22 +22,29 @@ namespace armarx::armem::base using Base = detail::EntityContainerBase<_CoreSegmentT, typename _CoreSegmentT::ProviderSegmentT::EntityT, _Derived>; public: + + using typename Base::DerivedT; + using typename Base::ContainerT; + using CoreSegmentT = _CoreSegmentT; using ProviderSegmentT = typename CoreSegmentT::ProviderSegmentT; using EntityT = typename ProviderSegmentT::EntityT; using EntitySnapshotT = typename EntityT::EntitySnapshotT; using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + public: + MemoryBase& operator=(const MemoryBase& other) { other._copySelf(*this); return *this; } - using Base::id; + inline const std::string& name() const { - return id.memoryName; + return this->id().memoryName; } inline std::string& name() { @@ -42,10 +52,9 @@ namespace armarx::armem::base } - using Base::container; inline const std::map<std::string, CoreSegmentT>& coreSegments() const { - return container; + return _container; } inline std::map<std::string, CoreSegmentT>& coreSegments() { @@ -55,7 +64,7 @@ namespace armarx::armem::base bool hasCoreSegment(const std::string& name) const { - return container.count(name) > 0; + return _container.count(name) > 0; } CoreSegmentT& getCoreSegment(const std::string& name) @@ -65,8 +74,8 @@ namespace armarx::armem::base const CoreSegmentT& getCoreSegment(const std::string& name) const { - auto it = this->container.find(name); - if (it != container.end()) + auto it = this->_container.find(name); + if (it != _container.end()) { return it->second; } @@ -101,13 +110,13 @@ namespace armarx::armem::base /// Move and insert a core segment. CoreSegmentT& addCoreSegment(CoreSegmentT&& coreSegment) { - if (container.count(coreSegment.name()) > 0) + if (_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; - it->second.id.setMemoryID(id); + auto it = _container.emplace(coreSegment.name(), std::move(coreSegment)).first; + it->second.id().setMemoryID(this->id()); return it->second; } @@ -137,8 +146,8 @@ namespace armarx::armem::base { _checkContainerName(update.entityID.memoryName, this->name()); - auto it = this->container.find(update.entityID.coreSegmentName); - if (it != container.end()) + auto it = _container.find(update.entityID.coreSegmentName); + if (it != _container.end()) { return it->second.update(update); } @@ -148,15 +157,14 @@ namespace armarx::armem::base } } - using Base::size; virtual bool equalsDeep(const MemoryBase& other) const { //std::cout << "Memory::equalsDeep" << std::endl; - if (size() != other.size()) + if (this->size() != other.size()) { return false; } - for (const auto& [key, core] : container) + for (const auto& [key, core] : _container) { if (not other.hasCoreSegment(key)) { @@ -179,5 +187,11 @@ namespace armarx::armem::base { return this->name(); } + + + 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 d3589d55230c890a26c28c6ba6a75ef2a0d49700..f6f760bc6976c165399cfeeb57f7ebd19cf0a91c 100644 --- a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h @@ -22,20 +22,27 @@ namespace armarx::armem::base using Base = detail::TypedEntityContainerBase<_EntityT, _EntityT, _Derived>; public: + + using typename Base::DerivedT; + using typename Base::ContainerT; + using EntityT = _EntityT; using EntitySnapshotT = typename EntityT::EntitySnapshotT; using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + public: + ProviderSegmentBase& operator=(const ProviderSegmentBase& other) { other._copySelf(*this); return *this; } - using Base::id; + inline const std::string& name() const { - return id.providerSegmentName; + return this->id().providerSegmentName; } inline std::string& name() { @@ -43,10 +50,9 @@ namespace armarx::armem::base } - using Base::container; inline const std::map<std::string, EntityT>& entities() const { - return container; + return _container; } inline std::map<std::string, EntityT>& entities() { @@ -56,7 +62,7 @@ namespace armarx::armem::base bool hasEntity(const std::string& name) const { - return container.count(name) > 0; + return _container.count(name) > 0; } using Base::_checkContainerName; @@ -73,8 +79,8 @@ namespace armarx::armem::base const EntityT& getEntity(const std::string& name) const { - auto it = this->container.find(name); - if (it != container.end()) + auto it = this->_container.find(name); + if (it != _container.end()) { return it->second; } @@ -94,12 +100,12 @@ namespace armarx::armem::base _checkContainerName(update.entityID.providerSegmentName, this->name()); EntityT* entity; - auto it = this->container.find(update.entityID.providerSegmentName); - if (it == container.end()) + auto it = this->_container.find(update.entityID.providerSegmentName); + if (it == _container.end()) { // Add entity entry. entity = &addEntity(update.entityID.entityName); - entity->setMaxHistorySize(maxHistorySize); + entity->setMaxHistorySize(_maxHistorySize); } else { @@ -122,8 +128,8 @@ namespace armarx::armem::base /// Move and insert an entity. EntityT& addEntity(EntityT&& entity) { - auto it = container.emplace(entity.name(), std::move(entity)).first; - it->second.id.setProviderSegmentID(id); + auto it = _container.emplace(entity.name(), std::move(entity)).first; + it->second.id().setProviderSegmentID(this->id()); return it->second; } @@ -136,22 +142,21 @@ namespace armarx::armem::base void setMaxHistorySize(long maxSize) override { MaxHistorySize::setMaxHistorySize(maxSize); - for (auto& [name, entity] : container) + for (auto& [name, entity] : _container) { entity.setMaxHistorySize(maxSize); } } - using Base::size; virtual bool equalsDeep(const ProviderSegmentBase& other) const { //std::cout << "ProviderSegment::equalsDeep" << std::endl; - if (size() != other.size()) + if (this->size() != other.size()) { return false; } - for (const auto& [key, value] : container) + for (const auto& [key, value] : _container) { if (not other.hasEntity(key)) { @@ -176,7 +181,10 @@ namespace armarx::armem::base return this->name(); } - public: + + protected: + + using Base::_container; }; diff --git a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h index 0f28deeefef83a48e1ebea520bce14b800afd050..ba4f8cf9b7d3d975a63eff763c49f546dcae6ac7 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h @@ -24,10 +24,17 @@ namespace armarx::armem::base::detail using Base = MemoryContainerBase<std::map<std::string, _ValueT>, _Derived>; public: - using Derived = _Derived; - using EntitySnapshotT = typename _EntityT::EntitySnapshotT; + + using DerivedT = _Derived; + using ValueT = _ValueT; + + using EntityT = _EntityT; + using EntitySnapshotT = typename EntityT::EntitySnapshotT; using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + public: + EntityContainerBase& operator=(const EntityContainerBase& other) { other._copySelf(*this); diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp index 4fe12f7e2ec9038456d8701f4022f33387ea4cfa..2c3b0554c65523826db0a7709599ed8e5140e0a1 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp +++ b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.cpp @@ -9,11 +9,11 @@ namespace armarx::armem::base::detail void MaxHistorySize::setMaxHistorySize(long maxSize) { - this->maxHistorySize = maxSize; + this->_maxHistorySize = maxSize; } long MaxHistorySize::getMaxHistorySize() const { - return maxHistorySize; + return _maxHistorySize; } } diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h index edbc12fa6ba514513ee61c5c2e2cdb3148c0ad07..69539df5c4063b8d27cd751b79ee82eb90ff5b7e 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MaxHistorySize.h @@ -23,9 +23,12 @@ namespace armarx::armem::base::detail /** * @brief Maximum size of entity histories. + * + * If negative, the size of `history` is not limited. + * * @see Entity::maxHstorySize */ - long maxHistorySize = -1; + long _maxHistorySize = -1; }; } diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h index e29be04a3fc7aae3fb4301280eb8fc358a2fa6ef..f75b15d117276b14c970110672c3bd327fb0c0f1 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryContainerBase.h @@ -1,8 +1,6 @@ #pragma once -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include "../../error.h" +#include <RobotAPI/libraries/armem/core/error/ArMemError.h> #include "MemoryItem.h" @@ -14,79 +12,95 @@ namespace armarx::armem::base::detail * @class Provides default implmentations of `MemoryContainer`, as well as * iterators (which requires a template). */ - template <class _ContainerT, class _Derived> + template <class _ContainerT, class _DerivedT> class MemoryContainerBase : virtual public MemoryItem { using Base = MemoryItem; public: - using Derived = _Derived; + + using DerivedT = _DerivedT; using ContainerT = _ContainerT; + public: + MemoryContainerBase() {} - MemoryContainerBase(const MemoryContainerBase<ContainerT, Derived>& o) : + MemoryContainerBase(const MemoryContainerBase<ContainerT, DerivedT>& o) : MemoryItem(o.id), - container(o.container) + _container(o._container) {} + MemoryContainerBase& operator=(const MemoryContainerBase& other) { other._copySelf(*this); return *this; } + // Container methods virtual bool empty() const { - return container.empty(); + return _container.empty(); } virtual std::size_t size() const { - return container.size(); + return _container.size(); } virtual void clear() { - return container.clear(); + return _container.clear(); } typename ContainerT::const_iterator begin() const { - return container.begin(); + return _container.begin(); } typename ContainerT::iterator begin() { - return container.begin(); + return _container.begin(); } typename ContainerT::const_iterator end() const { - return container.end(); + return _container.end(); } typename ContainerT::iterator end() { - return container.end(); + return _container.end(); + } + + const ContainerT& container() const + { + return _container; + } + ContainerT& container() + { + return _container; } // Copying - virtual Derived copy() const + virtual DerivedT copy() const { - Derived d; + DerivedT d; this->_copySelf(d); return d; } /// Make a copy not containing any elements. - virtual Derived copyEmpty() const + virtual DerivedT copyEmpty() const { - Derived d; + DerivedT d; this->_copySelfEmpty(d); return d; } + protected: + /// @throw `armem::error::ContainerNameMismatch` Of `expectedName != actualName`. void _checkContainerName(const std::string& expectedName, const std::string& actualName) const { @@ -96,19 +110,22 @@ namespace armarx::armem::base::detail } } - virtual void _copySelf(Derived& other) const + virtual void _copySelf(DerivedT& other) const { Base::_copySelf(other); - other.container = container; + other.container() = _container; } - virtual void _copySelfEmpty(Derived& other) const + virtual void _copySelfEmpty(DerivedT& other) const { Base::_copySelf(other); } - public: - ContainerT container; + + protected: + + ContainerT _container; + }; } diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp index 602817fe5b587e971147f1eb9581d6279825da71..76cb4215475417ec15345067f5eab980bca96887 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.cpp @@ -1 +1,36 @@ #include "MemoryItem.h" + + +namespace armarx::armem::base::detail +{ + + MemoryItem::MemoryItem() + { + } + + MemoryItem::MemoryItem(const MemoryID& id) : + _id(id) + { + } + + 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 + { + other.id() = id(); + } + +} diff --git a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h index 9749e275a8c2f56bf25eb5ec02852cee139e551c..7867f645e39b9c6fca6ba7a92def993bb2f3fc40 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h @@ -14,40 +14,46 @@ namespace armarx::armem::base::detail class MemoryItem { public: - MemoryItem() - { - } - MemoryItem(const MemoryItem& other) : - id(other.id) - {} + MemoryItem(); + MemoryItem(const MemoryID& id); + MemoryItem(const MemoryItem& other); + + virtual ~MemoryItem(); + + + MemoryItem& operator=(const MemoryItem& other); - MemoryItem(const MemoryID& id) : - id(id) + + inline MemoryID& id() { + return _id; } - - MemoryItem& operator=(const MemoryItem& other) + inline const MemoryID& id() const { - other._copySelf(*this); - return *this; + return _id; } + // Introspection + /// Get a string version of `*this`' key. virtual std::string getKeyString() const = 0; /// Get a readable name of this level for messages, errors etc. virtual std::string getLevelName() const = 0; + protected: - virtual void _copySelf(MemoryItem& other) const - { - other.id = id; - } - public: - MemoryID id; + /// Copy `*this` to `other`. + virtual void _copySelf(MemoryItem& other) const; + + + protected: + + MemoryID _id; + }; } diff --git a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h index f4c511da0bf3b49375980d5afe4d98f03ef84384..81f21797dfd4ca8972efd736ba8660b5e48a68f8 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/TypedEntityContainerBase.h @@ -16,67 +16,79 @@ namespace armarx::armem::base::detail { using Base = EntityContainerBase<_ValueT, _EntityT, _Derived>; + public: - using Derived = _Derived; - using EntitySnapshotT = typename _EntityT::EntitySnapshotT; - using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT; + + 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) + _aronType(aronType) {} - TypedEntityContainerBase(const TypedEntityContainerBase<_ValueT, _EntityT, _Derived>& other) : + TypedEntityContainerBase(const TypedEntityContainerBase<_ValueT, _EntityT, DerivedT>& other) : MemoryItem(other), - MemoryContainerBase<std::map<std::string, _ValueT>, _Derived>(other), - aronType(other.aronType) + MemoryContainerBase<std::map<std::string, _ValueT>, DerivedT>(other), + _aronType(other._aronType) {} TypedEntityContainerBase(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : MemoryItem(id), - aronType(aronType) + _aronType(aronType) {} + TypedEntityContainerBase& operator=(const TypedEntityContainerBase& other) { other._copySelf(*this); return *this; } + bool hasAronType() const { - return aronType != nullptr; + return _aronType != nullptr; } - - virtual _Derived copy() const override + aron::typenavigator::ObjectNavigatorPtr& aronType() { - _Derived d; - this->_copySelf(d); - return d; + return _aronType; + } + aron::typenavigator::ObjectNavigatorPtr aronType() const + { + return _aronType; } - virtual _Derived copyEmpty() const override + virtual DerivedT copyEmpty() const override { - _Derived d; + DerivedT d; this->_copySelfEmpty(d); return d; } + protected: - virtual void _copySelf(_Derived& other) const override + + virtual void _copySelf(DerivedT& other) const override { Base::_copySelf(other); - other.aronType = aronType; + other._aronType = _aronType; } - virtual void _copySelfEmpty(_Derived& other) const override + virtual void _copySelfEmpty(DerivedT& other) const override { Base::_copySelfEmpty(other); - other.aronType = aronType; + other._aronType = _aronType; } - public: + + protected: + /// The expected Aron type. May be nullptr, in which case no type information is available. - aron::typenavigator::ObjectNavigatorPtr aronType; + 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 369dab76068c26474936b684df1dcc79311859e3..bc3104b74ea8c1f396dc6ce0aee5742cdafd7e94 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp @@ -54,15 +54,15 @@ namespace armarx::armem::d_ltm std::filesystem::path CoreSegment::_fullPath(const std::filesystem::path& path) const { - return path / id.memoryName / id.coreSegmentName; + return path / id().memoryName / id().coreSegmentName; } wm::CoreSegment CoreSegment::convert() const { wm::CoreSegment m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { - m.addProviderSegment(s.convert(aronType)); + m.addProviderSegment(s.convert(_aronType)); } return m; } @@ -79,7 +79,7 @@ namespace armarx::armem::d_ltm ARMARX_ERROR << "The entered path is leading to a file! Abort due to error."; } - container.clear(); + _container.clear(); path = p_ptr; if (!std::filesystem::exists(p)) @@ -93,7 +93,7 @@ namespace armarx::armem::d_ltm if (d.is_directory()) { std::string k = d.path().filename(); - auto wms = container.emplace(std::make_pair(k, id.withProviderSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withProviderSegmentName(k))); wms.first->second.reload(p_ptr); } @@ -110,16 +110,16 @@ namespace armarx::armem::d_ltm std::filesystem::create_directories(_fullPath()); writeAronType(_fullPath()); - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } else { std::filesystem::create_directory(_fullPath() / k); - auto wms = container.emplace(std::make_pair(k, id.withProviderSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withProviderSegmentName(k))); wms.first->second.path = path; wms.first->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp index 3847f0af9235f903f1a819e05b3bbccee1ecfa0e..77ff0d95f4cf7ac7b81ac933d478ce47ae1010a6 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp @@ -40,13 +40,13 @@ namespace armarx::armem::d_ltm std::filesystem::path Entity::_fullPath(const std::filesystem::path& path) const { - return path / id.memoryName / id.coreSegmentName / id.providerSegmentName / id.entityName; + return path / id().memoryName / id().coreSegmentName / id().providerSegmentName / id().entityName; } wm::Entity Entity::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { wm::Entity m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addSnapshot(s.convert(expectedStructure)); } @@ -65,7 +65,7 @@ namespace armarx::armem::d_ltm ARMARX_ERROR << "The entered path is leading to a file! Abort due to error."; } - container.clear(); + _container.clear(); path = p_ptr; if (!std::filesystem::exists(p)) @@ -80,7 +80,7 @@ namespace armarx::armem::d_ltm { std::string k = d.path().filename(); armem::Time t = armem::Time::microSeconds(std::stol(k)); - auto wms = container.emplace(std::make_pair(t, id.withTimestamp(t))); + auto wms = _container.emplace(std::make_pair(t, id().withTimestamp(t))); wms.first->second.reload(p_ptr); } } @@ -90,16 +90,16 @@ namespace armarx::armem::d_ltm void Entity::append(const wm::Entity& m) { std::filesystem::create_directories(_fullPath()); - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.setTo(s); } else { std::filesystem::create_directory(_fullPath() / std::to_string(k.toMicroSeconds())); - auto wms = container.emplace(std::make_pair(k, id.withTimestamp(k))); + auto wms = _container.emplace(std::make_pair(k, id().withTimestamp(k))); wms.first->second.path = path; wms.first->second.setTo(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp index 1f855d1a4ad583ccbedfb4c97e24b8fdb527a388..98654d7a854b4247d515887ba3e9e4d5996b46d8 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp @@ -46,13 +46,15 @@ namespace armarx::armem::d_ltm std::filesystem::path EntitySnapshot::_fullPath(const std::filesystem::path& path) const { - return path / id.memoryName / id.coreSegmentName / id.providerSegmentName / id.entityName / std::to_string(id.timestamp.toMicroSeconds()); + return path / id().memoryName / id().coreSegmentName / id().providerSegmentName + / id().entityName + / std::to_string(id().timestamp.toMicroSeconds()); } wm::EntitySnapshot EntitySnapshot::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { wm::EntitySnapshot m; - for (const auto& s : container) + for (const auto& s : _container) { m.addInstance(s.convert(expectedStructure)); } @@ -72,7 +74,7 @@ namespace armarx::armem::d_ltm } else { - container.clear(); + _container.clear(); path = p_ptr; // todo @@ -81,7 +83,7 @@ namespace armarx::armem::d_ltm std::filesystem::path d = p / std::to_string(i); if (std::filesystem::is_directory(d)) { - auto wms = container.emplace_back(id.withInstanceIndex(i)); + auto wms = _container.emplace_back(id().withInstanceIndex(i)); wms.reload(p_ptr); } else @@ -97,14 +99,14 @@ namespace armarx::armem::d_ltm std::filesystem::create_directories(_fullPath()); // We remove the contente here and reset it with new values - container.clear(); + _container.clear(); - unsigned int i = 0; - for (const auto& s : m.container) + int i = 0; + for (const auto& s : m.instances()) { std::filesystem::create_directory(_fullPath() / std::to_string(i)); - auto wms = container.emplace_back(id.withInstanceIndex(i++)); + auto wms = _container.emplace_back(id().withInstanceIndex(i++)); wms.path = path; wms.setTo(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp index 4ef34ffd13af2559ca0691c4bdcbdd950e2636ce..70ed79acc064f4c0fb3a222c75bd90321c39f0e2 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp @@ -47,13 +47,13 @@ namespace armarx::armem::d_ltm std::filesystem::path Memory::_fullPath(const std::filesystem::path& path) const { - return path / id.memoryName; + return path / id().memoryName; } wm::Memory Memory::convert() const { wm::Memory m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addCoreSegment(s.convert()); } @@ -67,7 +67,7 @@ namespace armarx::armem::d_ltm ARMARX_ERROR << "The entered path is leading to a file! Abort due to error."; } - container.clear(); + _container.clear(); path = std::make_shared<std::filesystem::path>(p.parent_path()); if (!std::filesystem::exists(p)) @@ -76,14 +76,14 @@ namespace armarx::armem::d_ltm } else { - id = MemoryID().withMemoryName(p.filename()); + id() = MemoryID().withMemoryName(p.filename()); for (const auto& d : std::filesystem::directory_iterator(p)) { if (d.is_directory()) { std::string k = d.path().filename(); - auto wms = container.emplace(std::make_pair(k, id.withCoreSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withCoreSegmentName(k))); wms.first->second.reload(path); } } @@ -93,9 +93,9 @@ namespace armarx::armem::d_ltm void Memory::append(const wm::Memory& m) { std::filesystem::create_directories(_fullPath()); - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } @@ -103,7 +103,7 @@ namespace armarx::armem::d_ltm { std::filesystem::create_directory(_fullPath() / k); - auto wms = container.emplace(std::make_pair(k, id.withCoreSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withCoreSegmentName(k))); wms.first->second.path = path; wms.first->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp index 60a8268ee4d0bb966510caa2960fd2f59506a117..ae84449bb7a55ccf5d7a525b5b27f50c34fb3815 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp @@ -54,17 +54,17 @@ namespace armarx::armem::d_ltm std::filesystem::path ProviderSegment::_fullPath(const std::filesystem::path& path) const { - return path / id.memoryName / id.coreSegmentName / id.providerSegmentName; + return path / id().memoryName / id().coreSegmentName / id().providerSegmentName; } wm::ProviderSegment ProviderSegment::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { wm::ProviderSegment m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { if (hasAronType()) { - m.addEntity(s.convert(aronType)); + m.addEntity(s.convert(_aronType)); } else { @@ -86,7 +86,7 @@ namespace armarx::armem::d_ltm ARMARX_ERROR << "The entered path is leading to a file! Abort due to error."; } - container.clear(); + _container.clear(); path = p_ptr; if (!std::filesystem::exists(p)) @@ -100,7 +100,7 @@ namespace armarx::armem::d_ltm if (d.is_directory()) { std::string k = d.path().filename(); - auto wms = container.emplace(std::make_pair(k, id.withEntityName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withEntityName(k))); wms.first->second.reload(p_ptr); } @@ -117,16 +117,16 @@ namespace armarx::armem::d_ltm std::filesystem::create_directories(_fullPath()); writeAronType(_fullPath()); - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } else { std::filesystem::create_directory(_fullPath() / k); - auto wms = container.emplace(std::make_pair(k, id.withEntityName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withEntityName(k))); wms.first->second.path = path; wms.first->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h index f17bbc077f1c3d7ef7c49ddc4d9dddb843a184e2..9163b9482dc880a667f810e43039a1ac81d52f0a 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/detail/TypedEntityContainer.h @@ -66,7 +66,7 @@ namespace armarx::armem::d_ltm::detail aron::typeIO::reader::NlohmannJSONReader typeReader(file_content); aron::typeIO::writer::NavigatorWriter navWriter; aron::typeIO::Converter::ReadAndConvert(typeReader, navWriter); - aronType = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); + this->aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); } } } @@ -80,7 +80,7 @@ namespace armarx::armem::d_ltm::detail ofs.open(d); aron::typeIO::writer::NlohmannJSONWriter typeWriter; - aron::typeIO::Visitor::VisitAndSetup(typeWriter, aronType); + aron::typeIO::Visitor::VisitAndSetup(typeWriter, this->aronType()); std::string new_file_full_content = typeWriter.getResult().dump(2); ofs << new_file_full_content; diff --git a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp index 0a9774020ba573f41a26f6be610e6464108ae194..d79acf1da2b86f94414205131173797e0354bc24 100644 --- a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp +++ b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp @@ -147,11 +147,11 @@ namespace armarx void armem::detail::toIceItem(data::detail::MemoryItem& ice, const armem::base::detail::MemoryItem& item) { - toIce(ice.id, item.id); + toIce(ice.id, item.id()); } void armem::detail::fromIceItem(const data::detail::MemoryItem& ice, armem::base::detail::MemoryItem& item) { - fromIce(ice.id, item.id); + fromIce(ice.id, item.id()); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp index b98a0d5efb654739de535284d816dfebc4a0b5fe..6bebc718e499ed311d3090aacd3dd6b71bc5078f 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp @@ -46,7 +46,7 @@ namespace armarx::armem::ltm wm::CoreSegment CoreSegment::convert() const { wm::CoreSegment m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addProviderSegment(s.convert()); } @@ -55,15 +55,15 @@ namespace armarx::armem::ltm void CoreSegment::append(const wm::CoreSegment& m) { - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } else { - auto wms = container.emplace(std::make_pair(k, id.withCoreSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withCoreSegmentName(k))); wms.first->second.append(s); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp index c0de42c689c4844b50f5bb8858e776057471a484..30c578d82a61a556720cb7089d033dc9120a16c8 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp @@ -32,7 +32,7 @@ namespace armarx::armem::ltm wm::Entity Entity::convert() const { wm::Entity m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addSnapshot(s.convert()); } @@ -41,15 +41,15 @@ namespace armarx::armem::ltm void Entity::append(const wm::Entity& m) { - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.setTo(s); } else { - auto wms = container.emplace(std::make_pair(k, id.withTimestamp(k))); + auto wms = _container.emplace(std::make_pair(k, id().withTimestamp(k))); wms.first->second.setTo(s); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp index 44bbca24d11d42d5741759fa2487c1434ce6a3b9..424dd732d74b777bb96b786302dc1a49782b8ec5 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp @@ -41,7 +41,7 @@ namespace armarx::armem::ltm bool EntityInstance::equalsDeep(const EntityInstance& other) const { - return id == other.id && _metadata == other.metadata(); + return id() == other.id() && _metadata == other.metadata(); } void EntityInstance::update(const EntityUpdate& update, int index) @@ -77,6 +77,6 @@ namespace armarx::armem::ltm void EntityInstance::setTo(const wm::EntityInstance& m) { - ARMARX_IMPORTANT << "Longtermmemory received an entity instance: " << m.id.str(); + ARMARX_IMPORTANT << "Longtermmemory received an entity instance: " << m.id().str(); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp index 0cf13f0210b1e9ee6499417770ef21d18550e7ee..9f3272eb9ba94c5751ea0b2d4f1c0893802eb0d6 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp @@ -38,7 +38,7 @@ namespace armarx::armem::ltm wm::EntitySnapshot EntitySnapshot::convert() const { wm::EntitySnapshot m; - for (const auto& s : container) + for (const auto& s : _container) { m.addInstance(s.convert()); } @@ -48,12 +48,12 @@ namespace armarx::armem::ltm void EntitySnapshot::setTo(const wm::EntitySnapshot& m) { // We remove the contente here and reset it with new values - container.clear(); + _container.clear(); - unsigned int i = 0; - for (const auto& s : m.container) + int i = 0; + for (const auto& s : m.container()) { - auto wms = container.emplace_back(id.withInstanceIndex(i++)); + auto wms = _container.emplace_back(id().withInstanceIndex(i++)); wms.setTo(s); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp index 9b5779c5970495171b93fb2c667cefd444182054..9f216cb0338fc9ff8b7f47fa430acf99bf0cb92c 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp @@ -39,7 +39,7 @@ namespace armarx::armem::ltm wm::Memory Memory::convert() const { wm::Memory m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addCoreSegment(s.convert()); } @@ -54,15 +54,15 @@ namespace armarx::armem::ltm void Memory::append(const wm::Memory& m) { - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } else { - auto wms = container.emplace(std::make_pair(k, id.withCoreSegmentName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withCoreSegmentName(k))); wms.first->second.append(s); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp index e527b2af574cc4a29a0e615069acfffd6901bb19..dbdbdb1189fd2efdac397992b3cad480da77f863 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp @@ -46,7 +46,7 @@ namespace armarx::armem::ltm wm::ProviderSegment ProviderSegment::convert() const { wm::ProviderSegment m; - for (const auto& [_, s] : container) + for (const auto& [_, s] : _container) { m.addEntity(s.convert()); } @@ -55,15 +55,15 @@ namespace armarx::armem::ltm void ProviderSegment::append(const wm::ProviderSegment& m) { - for (const auto& [k, s] : m.container) + for (const auto& [k, s] : m.container()) { - if (const auto& it = container.find(k); it != container.end()) + if (const auto& it = _container.find(k); it != _container.end()) { it->second.append(s); } else { - auto wms = container.emplace(std::make_pair(k, id.withEntityName(k))); + auto wms = _container.emplace(std::make_pair(k, id().withEntityName(k))); wms.first->second.append(s); } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp index 3c9fe036452c21992c82bce0d9ecad30d33c0491..4ef52fd749f9106d4ea1e9204fd0574392c18387 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp @@ -53,7 +53,7 @@ namespace armarx::armem::wm void CoreSegment::_copySelfWithoutData(CoreSegment& o) const { detail::TypedEntityContainer<ProviderSegment, CoreSegment>::_copySelfWithoutData(o); - for (const auto& [k, s] : o.container) + for (const auto& [k, s] : o) { o.addProviderSegment(s.copyWithoutData()); } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp index 75fddfd55094b7f007cf7a0e4775adbd16437dde..37b930656d8810ea0445c412d8992c23db2458aa 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp @@ -39,7 +39,7 @@ namespace armarx::armem::wm void Entity::_copySelfWithoutData(Entity& o) const { detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity>::_copySelfWithoutData(o); - for (const auto& [k, s] : o.container) + for (const auto& [k, s] : o) { o.addSnapshot(s.copyWithoutData()); } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp index ce62d0164e9adaefd6ea4d1ab3bc46d3c8038d9e..125dde02214783caa6abe9668b24b04dc407c42a 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp @@ -44,7 +44,9 @@ namespace armarx::armem::wm bool EntityInstance::equalsDeep(const EntityInstance& other) const { - return id == other.id && _metadata == other.metadata() && _data->equalsDeep(other.data()); + return id() == other.id() + && _metadata == other.metadata() + && _data->equalsDeep(other.data()); } void EntityInstance::update(const EntityUpdate& update, int index) diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp index 124645de98c90eae526f5ee5f23c9e79027e6f52..c33dd71b23b3c2c16c4b95894af63b46485d8ca2 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp @@ -23,6 +23,10 @@ namespace armarx::armem::wm { } + EntitySnapshot::~EntitySnapshot() + { + } + EntitySnapshot::EntitySnapshot(const EntitySnapshot& other) : base::detail::MemoryItem(other), base::detail::MemoryContainerBase<std::vector<EntityInstance>, EntitySnapshot>(other) @@ -45,7 +49,7 @@ namespace armarx::armem::wm void EntitySnapshot::_copySelfWithoutData(EntitySnapshot& o) const { detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot>::_copySelfWithoutData(o); - for (const auto& s : o.container) + for (const auto& s : o) { o.addInstance(s.copyWithoutData()); } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h index 5f18288ba698fd70eed0539532a9be3002967590..50332bf163f4b4595b0e53b64f3acf3497f3332c 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h @@ -19,10 +19,14 @@ namespace armarx::armem::wm 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); @@ -31,7 +35,10 @@ namespace armarx::armem::wm EntitySnapshot copyWithoutData() const override; + protected: + virtual void _copySelfWithoutData(EntitySnapshot& o) const override; + }; } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp index 706d26bcc3a94a8ddb0b0da6015abdc664857fb4..a5b1e4ab1346ed3b3d041320c4eade4d31176ced 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp @@ -46,7 +46,7 @@ namespace armarx::armem::wm void Memory::_copySelfWithoutData(Memory& o) const { detail::EntityContainer<CoreSegment, Memory>::_copySelfWithoutData(o); - for (const auto& [k, s] : o.container) + for (const auto& [k, s] : o) { o.addCoreSegment(s.copyWithoutData()); } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp index dbf436b65b078053a6405892b7f89082e89598ee..3b90c745c53a60c5d95feda1adc131c300d61beb 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp @@ -53,7 +53,7 @@ namespace armarx::armem::wm void ProviderSegment::_copySelfWithoutData(ProviderSegment& o) const { detail::TypedEntityContainer<Entity, ProviderSegment>::_copySelfWithoutData(o); - for (const auto& [k, s] : o.container) + for (const auto& [k, s] : o) { o.addEntity(s.copyWithoutData()); } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp index ad77c6dc16feb2f119051ef1b0d0cecc29c9b650..7dded894331809986a991351f0eb7c7675b11812 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp @@ -43,26 +43,26 @@ namespace armarx::armem { detail::toIceItem(ice, snapshot); - toIce(ice.instances, snapshot.container); + toIce(ice.instances, snapshot.instances()); } void fromIce(const data::EntitySnapshot& ice, wm::EntitySnapshot& snapshot) { detail::fromIceItem(ice, snapshot); - fromIce(ice.instances, snapshot.container); + fromIce(ice.instances, snapshot.instances()); } void toIce(data::Entity& ice, const wm::Entity& entity) { detail::toIceItem(ice, entity); - toIce(ice.history, entity.container); + toIce(ice.history, entity.history()); } void fromIce(const data::Entity& ice, wm::Entity& entity) { detail::fromIceItem(ice, entity); - fromIce(ice.history, entity.container); + fromIce(ice.history, entity.history()); } @@ -72,9 +72,9 @@ namespace armarx::armem if (providerSegment.hasAronType()) { - ice.aronType = providerSegment.aronType->getResult(); + ice.aronType = providerSegment.aronType()->getResult(); } - toIce(ice.entities, providerSegment.container); + toIce(ice.entities, providerSegment.entities()); } void fromIce(const data::ProviderSegment& ice, wm::ProviderSegment& providerSegment) { @@ -82,9 +82,9 @@ namespace armarx::armem if (ice.aronType) { - providerSegment.aronType = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); + providerSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); } - fromIce(ice.entities, providerSegment.container); + fromIce(ice.entities, providerSegment.entities()); } void toIce(data::CoreSegment& ice, const wm::CoreSegment& coreSegment) @@ -93,9 +93,9 @@ namespace armarx::armem if (coreSegment.hasAronType()) { - ice.aronType = coreSegment.aronType->getResult(); + ice.aronType = coreSegment.aronType()->getResult(); } - toIce(ice.providerSegments, coreSegment.container); + toIce(ice.providerSegments, coreSegment.providerSegments()); } void fromIce(const data::CoreSegment& ice, wm::CoreSegment& coreSegment) { @@ -103,22 +103,22 @@ namespace armarx::armem if (ice.aronType) { - coreSegment.aronType = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); + coreSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); } - fromIce(ice.providerSegments, coreSegment.container); + fromIce(ice.providerSegments, coreSegment.providerSegments()); } void toIce(data::Memory& ice, const wm::Memory& memory) { detail::toIceItem(ice, memory); - toIce(ice.coreSegments, memory.container); + toIce(ice.coreSegments, memory.coreSegments()); } void fromIce(const data::Memory& ice, wm::Memory& memory) { detail::fromIceItem(ice, memory); - fromIce(ice.coreSegments, memory.container); + fromIce(ice.coreSegments, memory.coreSegments()); } } diff --git a/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp index 1d016e78374082167a82730796e1950d09c158ac..36d8ac9cfa55816a086985f0de6f6f6c99155273 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp @@ -54,10 +54,10 @@ BOOST_AUTO_TEST_CASE(test_entity) armem::data::EntityPtr ice; armem::toIce(ice, entity); - BOOST_CHECK_EQUAL(ice->id.memoryName, entity.id.memoryName); - BOOST_CHECK_EQUAL(ice->id.coreSegmentName, entity.id.coreSegmentName); - BOOST_CHECK_EQUAL(ice->id.providerSegmentName, entity.id.providerSegmentName); - BOOST_CHECK_EQUAL(ice->id.entityName, entity.id.entityName); + BOOST_CHECK_EQUAL(ice->id().memoryName, entity.id.memoryName); + BOOST_CHECK_EQUAL(ice->id().coreSegmentName, entity.id.coreSegmentName); + BOOST_CHECK_EQUAL(ice->id().providerSegmentName, entity.id.providerSegmentName); + BOOST_CHECK_EQUAL(ice->id().entityName, entity.id.entityName); BOOST_CHECK_EQUAL(ice->history.size(), entity.history().size()); diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index b852295ff0e9957deabc8cbd901fd628f148b4ff..4cd548cff76136f2c08ebae4711a7d2de665cea9 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) providerSegment.update(update); // Check correctly inherited history size. - BOOST_CHECK_EQUAL(providerSegment.getEntity("C").maxHistorySize, 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("C").getMaxHistorySize(), 2); // Check actual history size. BOOST_CHECK_EQUAL(providerSegment.getEntity("C").history().size(), 2);