diff --git a/scenarios/ArMemExample/config/ExampleMemory.cfg b/scenarios/ArMemExample/config/ExampleMemory.cfg index d0a545f7a2a6c2d0fe730d3169b208760aec0abe..d9e24e657c2b57a11bac7d34b2df65dff2e9eb8d 100644 --- a/scenarios/ArMemExample/config/ExampleMemory.cfg +++ b/scenarios/ArMemExample/config/ExampleMemory.cfg @@ -84,6 +84,14 @@ ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener = MemoryUpdates # ArmarX.EnableProfiling = false +# ArmarX.ExampleMemory.: +# Attributes: +# - Default: "" +# - Case sensitivity: yes +# - Required: no +# ArmarX.ExampleMemory. = "" + + # ArmarX.ExampleMemory.EnableProfiling: enable profiler which is used for logging performance events # Attributes: # - Default: false @@ -155,10 +163,10 @@ ArmarX.ArMemExampleMemory.tpc.pub.MemoryListener = MemoryUpdates # ArmarX.ExampleMemory.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. # Attributes: -# - Default: ArMemMemoryNameSystem +# - Default: MemoryNameSystem # - Case sensitivity: yes # - Required: no -# ArmarX.ExampleMemory.mns.MemoryNameSystemName = ArMemMemoryNameSystem +# ArmarX.ExampleMemory.mns.MemoryNameSystemName = MemoryNameSystem # ArmarX.ExampleMemory.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. diff --git a/scenarios/ArMemExample/config/ExampleMemoryClient.cfg b/scenarios/ArMemExample/config/ExampleMemoryClient.cfg index 76d3d877581dc891a0aa8a4092e1072d9d06dc87..10325be750b47ccdfa1827265cce4d881d58d2ed 100644 --- a/scenarios/ArMemExample/config/ExampleMemoryClient.cfg +++ b/scenarios/ArMemExample/config/ExampleMemoryClient.cfg @@ -138,10 +138,10 @@ ArmarX.ArMemExampleClient.tpc.sub.MemoryListener = MemoryUpdates # ArmarX.ExampleMemoryClient.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component. # Attributes: -# - Default: ArMemMemoryNameSystem +# - Default: MemoryNameSystem # - Case sensitivity: yes # - Required: no -# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemName = ArMemMemoryNameSystem +# ArmarX.ExampleMemoryClient.mns.MemoryNameSystemName = MemoryNameSystem # ArmarX.ExampleMemoryClient.tpc.pub.DebugObserver: Name of the `DebugObserver` topic to publish data to. diff --git a/scenarios/ArMemExample/config/MemoryNameSystem.cfg b/scenarios/ArMemExample/config/MemoryNameSystem.cfg index 869022057679ebbbe32a28eb4a9962b11239e6f7..7dd22218243ca4f9e67e843da8b42916f3b8568a 100644 --- a/scenarios/ArMemExample/config/MemoryNameSystem.cfg +++ b/scenarios/ArMemExample/config/MemoryNameSystem.cfg @@ -115,7 +115,7 @@ # - Default: "" # - Case sensitivity: yes # - Required: no -ArmarX.MemoryNameSystem.ObjectName = "ArMemMemoryNameSystem" +# ArmarX.MemoryNameSystem.ObjectName = "" # ArmarX.MemoryNameSystem.RemoteGuiName: Name of the remote gui provider diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui index 3e94dc5e5c3e13bd866c92c428f5d619317806ac..819331b5f27f58c036bb867e8a17dda8a0c8b977 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui @@ -15,39 +15,43 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QHBoxLayout" name="ltmControlWidgetLayout"> - <property name="spacing"> - <number>6</number> - </property> + <layout class="QHBoxLayout" name="topRowLayout"> <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> + <layout class="QHBoxLayout" name="updateWidgetLayout"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="updateWidgetLayout"> <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> + <layout class="QHBoxLayout" name="ltmControlWidgetLayout"> + <property name="spacing"> + <number>6</number> </property> - </spacer> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> </item> </layout> </item> diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp index f313b6951c2f201251787ec6a6e6b4b5b0026e4c..83d1d8743a3b6ed0ebfeca5c704c96334b22108a 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp @@ -41,9 +41,9 @@ namespace armarx widget.setupUi(getWidget()); viewer = std::make_unique<MemoryViewer>( - widget.ltmControlWidgetLayout, widget.updateWidgetLayout, + widget.ltmControlWidgetLayout, widget.memoryGroupBox, widget.treesLayout, 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..4c4e50c920d87273d701378befd982823e2f00ea 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,28 @@ namespace armarx::armem::base public: - CoreSegmentBase& operator=(const CoreSegmentBase& other) + CoreSegmentBase() { - other._copySelf(*this); - return *this; } + 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) = default; + CoreSegmentBase(CoreSegmentBase&& other) = default; + CoreSegmentBase& operator=(const CoreSegmentBase& other) = default; + CoreSegmentBase& operator=(CoreSegmentBase&& other) = default; + inline const std::string& name() const { @@ -52,7 +71,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 +81,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 +92,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 +114,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 +151,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 +166,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 +179,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 +206,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..39dcc12c92902bad4c7a2e0c9cb7385de8e0a40c 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,23 @@ namespace armarx::armem::base public: - EntityBase& operator=(const EntityBase& other) + EntityBase() { - other._copySelf(*this); - return *this; } + EntityBase(const std::string& name, const MemoryID& parentID = {}) : + EntityBase(parentID.withEntityName(name)) + { + } + EntityBase(const MemoryID& id) : + Base(id) + { + } + + + EntityBase(const EntityBase& other) = default; + EntityBase(EntityBase&& other) = default; + EntityBase& operator=(const EntityBase& other) = default; + EntityBase& operator=(EntityBase&& other) = default; virtual bool equalsDeep(const EntityBase& other) const @@ -69,7 +81,7 @@ namespace armarx::armem::base { return false; } - for (const auto& [key, snapshot] : _container) + for (const auto& [key, snapshot] : this->_container) { if (not other.hasSnapshot(key)) { @@ -96,7 +108,7 @@ namespace armarx::armem::base inline const std::map<Time, EntitySnapshotT>& history() const { - return _container; + return this->_container; } inline std::map<Time, EntitySnapshotT>& history() { @@ -109,7 +121,7 @@ namespace armarx::armem::base */ bool hasSnapshot(Time time) const { - return _container.count(time) > 0; + return this->_container.count(time) > 0; } /** @@ -126,7 +138,7 @@ namespace armarx::armem::base */ std::vector<Time> getTimestamps() const { - return simox::alg::get_keys(_container); + return simox::alg::get_keys(this->_container); } @@ -145,8 +157,8 @@ namespace armarx::armem::base const EntitySnapshotT& getSnapshot(Time time) const { - auto it = _container.find(time); - if (it != _container.end()) + auto it = this->_container.find(time); + if (it != this->_container.end()) { return it->second; } @@ -196,8 +208,8 @@ namespace armarx::armem::base EntitySnapshotT* snapshot; - auto it = _container.find(update.timeCreated); - if (it == _container.end()) + auto it = this->_container.find(update.timeCreated); + if (it == this->_container.end()) { // Insert into history. snapshot = &addSnapshot(update.timeCreated); @@ -225,7 +237,7 @@ namespace armarx::armem::base EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot) { - auto it = _container.emplace(snapshot.time(), std::move(snapshot)).first; + auto it = this->_container.emplace(snapshot.time(), std::move(snapshot)).first; it->second.id().setEntityID(this->id()); return it->second; } @@ -256,33 +268,6 @@ namespace armarx::armem::base return "entity"; } - virtual _Derived copy() const override - { - _Derived d; - this->_copySelf(d); - return d; - } - - virtual _Derived copyEmpty() const override - { - _Derived d; - this->_copySelfEmpty(d); - return d; - } - - - protected: - - virtual void _copySelf(DerivedT& other) const override - { - Base::_copySelf(other); - } - - virtual void _copySelfEmpty(DerivedT& other) const override - { - Base::_copySelfEmpty(other); - } - private: @@ -291,11 +276,11 @@ namespace armarx::armem::base { if (_maxHistorySize >= 0) { - while (_container.size() > size_t(_maxHistorySize)) + while (this->_container.size() > size_t(_maxHistorySize)) { - _container.erase(_container.begin()); + this->_container.erase(this->_container.begin()); } - ARMARX_CHECK_LESS_EQUAL(_container.size(), _maxHistorySize); + ARMARX_CHECK_LESS_EQUAL(this->_container.size(), _maxHistorySize); } } @@ -314,18 +299,13 @@ namespace armarx::armem::base */ const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const { - if (_container.empty()) + if (this->_container.empty()) { throw armem::error::EntityHistoryEmpty(name(), "when getting the latest snapshot."); } - return *_container.rbegin(); + return *this->_container.rbegin(); } - - protected: - - using Base::_container; - }; } diff --git a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h index d385ee26bb9a17f73535d15b68822c17c5bfd278..aab70193435c7eec54b9e2127e7c57528ebba842 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,10 +24,16 @@ namespace armarx::armem::base public: - EntityInstanceBase& operator=(const EntityInstanceBase& other) + EntityInstanceBase() + { + } + EntityInstanceBase(int index, const MemoryID& parentID = {}) : + EntityInstanceBase(parentID.withInstanceIndex(index)) + { + } + EntityInstanceBase(const MemoryID& id) : + Base(id) { - //other._copySelf(*this); - return *this; } @@ -40,14 +46,6 @@ namespace armarx::armem::base return id().instanceIndex; } - // Copying - virtual DerivedT copy() const - { - DerivedT d; - this->_copySelf(d); - return d; - } - /** * @brief Fill `*this` with the update's values. * @param update The update. @@ -58,6 +56,13 @@ namespace armarx::armem::base virtual bool equalsDeep(const DerivedT& other) const = 0; + virtual DerivedT copy() const + { + DerivedT d; + this->_copySelf(d); + return d; + } + std::string getLevelName() const override { diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h index 094608e2927991f5593922887ec17e11fe6ce440..defdf1c049fa5274b0d112f42d78037730d9eff5 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,23 @@ namespace armarx::armem::base public: - EntitySnapshotBase& operator=(const EntitySnapshotBase& other) + EntitySnapshotBase() { - other._copySelf(*this); - return *this; } + EntitySnapshotBase(Time time, const MemoryID& parentID = {}) : + EntitySnapshotBase(parentID.withTimestamp(time)) + { + } + EntitySnapshotBase(const MemoryID& id) : + Base(id) + { + } + + EntitySnapshotBase(const EntitySnapshotBase& other) = default; + EntitySnapshotBase(EntitySnapshotBase&& other) = default; + EntitySnapshotBase& operator=(const EntitySnapshotBase& other) = default; + EntitySnapshotBase& operator=(EntitySnapshotBase&& other) = default; + virtual bool equalsDeep(const EntitySnapshotBase& other) const { @@ -45,7 +57,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 +81,7 @@ namespace armarx::armem::base inline const std::vector<EntityInstanceT>& instances() const { - return _container; + return this->_container; } inline std::vector<EntityInstanceT>& instances() { @@ -85,10 +97,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 +109,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 +127,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 +170,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 +197,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..7bcef9350941e86ea5f3e290afcf70d1c42f1010 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,22 @@ namespace armarx::armem::base public: - MemoryBase& operator=(const MemoryBase& other) + MemoryBase() { - other._copySelf(*this); - return *this; } + MemoryBase(const std::string& name) : + MemoryBase(MemoryID().withMemoryName(name)) + { + } + MemoryBase(const MemoryID& id) : + Base(id) + { + } + + MemoryBase(const MemoryBase& other) = default; + MemoryBase(MemoryBase&& other) = default; + MemoryBase& operator=(const MemoryBase& other) = default; + MemoryBase& operator=(MemoryBase&& other) = default; inline const std::string& name() const @@ -54,7 +65,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 +75,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 +86,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 +121,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 +157,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 +175,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)) { @@ -187,11 +198,5 @@ 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 9cbfd4facde379fc5d3cc1f8f0d26631899e5811..81be753a74ea9887ce11b7b93b364993679caf23 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,12 +35,29 @@ namespace armarx::armem::base public: - ProviderSegmentBase& operator=(const ProviderSegmentBase& other) + ProviderSegmentBase() { - other._copySelf(*this); - return *this; } + 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) = default; + ProviderSegmentBase(ProviderSegmentBase&& other) = default; + ProviderSegmentBase& operator=(const ProviderSegmentBase& other) = default; + ProviderSegmentBase& operator=(ProviderSegmentBase&& other) = default; + inline const std::string& name() const { @@ -52,7 +71,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 +81,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 +99,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 +120,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 +147,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 +161,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 +175,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 +203,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..9e5c869c333196c4ae9f1d32a803458ef34d27b4 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,9 @@ namespace armarx::armem::base::detail public: - EntityContainerBase& operator=(const EntityContainerBase& other) - { - other._copySelf(*this); - return *this; - } + using Base::MemoryContainerBase; + using Base::operator=; + /** * @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..b2155c70dbf645ebe0e2783fd3189bf9b58800af 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,22 +26,22 @@ namespace armarx::armem::base::detail public: + MemoryContainerBase() {} - MemoryContainerBase(const MemoryContainerBase<ContainerT, DerivedT>& o) : - MemoryItem(o.id), - _container(o._container) - {} - - - MemoryContainerBase& operator=(const MemoryContainerBase& other) + MemoryContainerBase(const MemoryID& id) : + MemoryItem(id) { - other._copySelf(*this); - return *this; } + MemoryContainerBase(const MemoryContainerBase& other) = default; + MemoryContainerBase(MemoryContainerBase&& other) = default; + MemoryContainerBase& operator=(const MemoryContainerBase& other) = default; + MemoryContainerBase& operator=(MemoryContainerBase&& other) = default; + // Container methods + virtual bool empty() const { return _container.empty(); @@ -83,6 +83,7 @@ namespace armarx::armem::base::detail // Copying + virtual DerivedT copy() const { DerivedT d; 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..45226e6327520b7bbddc198364c16c2b8229352c 100644 --- a/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h +++ b/source/RobotAPI/libraries/armem/core/base/detail/MemoryItem.h @@ -17,12 +17,16 @@ namespace armarx::armem::base::detail MemoryItem(); MemoryItem(const MemoryID& id); - MemoryItem(const MemoryItem& other); + + MemoryItem(const MemoryItem& other) = default; + MemoryItem(MemoryItem&& other) = default; + MemoryItem& operator=(const MemoryItem& other) = default; + MemoryItem& operator=(MemoryItem&& other) = default; 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..6a26be9c7915a54b081e5d03b4f67cb6ae9eeaee 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp @@ -2,47 +2,12 @@ #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) - { - } - - CoreSegment& CoreSegment::operator=(const CoreSegment& other) - { - other._copySelf(*this); - return *this; - } - std::filesystem::path CoreSegment::_fullPath() const { if (path) @@ -99,7 +64,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 +76,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..76bb297e76d268ce8517449686ffae1cdb3ed2cd 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,19 +15,15 @@ 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); - CoreSegment(const CoreSegment& other); - CoreSegment& operator=(const CoreSegment& other); + using Base::CoreSegmentBase; + using Base::operator=; + // Conversion wm::CoreSegment convert() const; diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp index 77ff0d95f4cf7ac7b81ac933d478ce47ae1010a6..a616914ede5c279d11daea7afcfe81a681b0c460 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp @@ -2,33 +2,6 @@ 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) - { - } - - Entity& Entity::operator=(const Entity& other) - { - other._copySelf(*this); - return *this; - } - std::filesystem::path Entity::_fullPath() const { if (path) diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.h index 756f3eb69dd3499333532187ee207fd4cec4e102..35022275570c93378cbe0c767aad1776da594838 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,19 +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. - Entity(const Entity& other); - /// Copy the history from `other` to this. - Entity& operator=(const Entity& other); + + using Base::EntityBase; + using Base::operator=; + // Conversion wm::Entity convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const; diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp index 28bcf696369fedfa9bd39ab9cce3f694033211d6..49bfe419d8a8cf1052fad7e47a0ecba9e355c529 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp @@ -13,36 +13,20 @@ namespace armarx::armem::d_ltm { - EntityInstance::EntityInstance() - { - } EntityInstance::EntityInstance(const EntityInstance& other) : - base::detail::MemoryItem(other.id()) + Base(other), + path(other.path) { } - 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 { return id() == other.id(); } + + void EntityInstance::update(const EntityUpdate& update, int index) { ARMARX_CHECK_FITS_SIZE(index, update.instancesData.size()); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h index 8e7a0fed18959090f05196ba32565f507e19faf4..9ee48c55b33dca02c88f57de1ac30426f8d5ae37 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.h @@ -3,26 +3,28 @@ #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); - EntityInstance& operator=(const EntityInstance& other); + using Base::EntityInstanceBase; + + EntityInstance(const EntityInstance& other); + EntityInstance(EntityInstance&& other) = default; + EntityInstance& operator=(const EntityInstance& other) = default; + EntityInstance& operator=(EntityInstance&& other) = default; + /** * @brief Fill `*this` with the update's values. diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp index 98654d7a854b4247d515887ba3e9e4d5996b46d8..199e4f2c9b9eed9d9b099e773d96ba0a03fd7d16 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp @@ -8,33 +8,6 @@ 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) - { - } - - EntitySnapshot& EntitySnapshot::operator=(const EntitySnapshot& other) - { - other._copySelf(*this); - return *this; - } - std::filesystem::path EntitySnapshot::_fullPath() const { if (path) diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.h index 5c3cf02ff6cb452797ac0c0433bbef294d92a29f..f73702857fc6700e5cfae5f6d08b369240d08f79 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,20 +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; + using Base::operator=; - /// Copy the instances from `other` to this. - EntitySnapshot& operator=(const EntitySnapshot& other); // Conversion void reload(const std::shared_ptr<std::filesystem::path>&); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp index 70ed79acc064f4c0fb3a222c75bd90321c39f0e2..874d189d6a22a79c9e015d800c292f9af075cfea 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp @@ -8,34 +8,6 @@ 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) - { - *this = other; - } - - Memory& Memory::operator=(const Memory& other) - { - other._copySelf(*this); - return *this; - } - std::filesystem::path Memory::_fullPath() const { if (path) diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h index 32bd30fa69c4dff87ef9d13e599cac8442936003..7f7872f7a638cc31122f09b00a95755ede4d9606 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,17 +15,15 @@ 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); - Memory(const Memory& other); - Memory& operator=(const Memory& other); + using Base::MemoryBase; + using Base::operator=; + // Conversion wm::Memory convert() const; diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp index ae84449bb7a55ccf5d7a525b5b27f50c34fb3815..2d5ed3d4a588827137b33e69ecaec3be1a4c31fc 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp @@ -2,47 +2,11 @@ #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) - { - } - - ProviderSegment& ProviderSegment::operator=(const ProviderSegment& other) - { - other._copySelf(*this); - return *this; - } - std::filesystem::path ProviderSegment::_fullPath() const { if (path) @@ -106,7 +70,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 +82,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..8ad96ea0630af0d5aba8b7270fe229c235c2a010 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,19 +15,15 @@ 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); - ProviderSegment(const ProviderSegment& other); - ProviderSegment& operator=(const ProviderSegment& other); + using Base::ProviderSegmentBase; + using Base::operator=; + // Conversion wm::ProviderSegment convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const; 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..78f275fe1a8b1285b852431acaa67dc13963874d 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp @@ -8,41 +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); - return *this; - } - wm::CoreSegment CoreSegment::convert() const { wm::CoreSegment m; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h index 59bb7830d66e1b5ec2e15c904ae967a93534b8a3..67f9da6f465820534a4214cbb423e14916819daf 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.h @@ -14,18 +14,15 @@ 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); - CoreSegment& operator=(const CoreSegment& other); + using Base::CoreSegmentBase; + using Base::operator=; + // Conversion wm::CoreSegment convert() const; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp index 30c578d82a61a556720cb7089d033dc9120a16c8..15e232c01fb0edb2ce6e0bffec0f2f0b2c0a3110 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp @@ -3,32 +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); - return *this; - } - wm::Entity Entity::convert() const { wm::Entity m; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h index 79d81340e35381228ffa8875c8723a349bdb4035..ecdf297c13fae4d24b070f2af13fd6c84ed93392 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h @@ -29,19 +29,15 @@ 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); - /// Copy the history from `other` to this. - Entity& operator=(const Entity& other); + + using Base::EntityBase; + using Base::operator=; + // Conversion wm::Entity convert() const; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp index 17535db36fda2e165df2e7a41489193699ac4754..6332be7ea52f3c547101ae3ee196a524a36aab17 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.cpp @@ -13,32 +13,6 @@ namespace armarx::armem::ltm && std::abs(confidence - other.confidence) < 1e-6f; } - EntityInstance::EntityInstance() - { - } - - EntityInstance::EntityInstance(const EntityInstance& other) : - MemoryItem(other.id()), - _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) - { - other._copySelf(*this); - return *this; - } - bool EntityInstance::equalsDeep(const EntityInstance& other) const { return id() == other.id() && _metadata == other.metadata(); @@ -65,7 +39,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..f78668e5e1a4e1506c2b63c8d2721126e293d6c9 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntityInstance.h @@ -34,17 +34,19 @@ 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); - EntityInstance& operator=(const EntityInstance& other); + using Base::EntityInstanceBase; + + EntityInstance(const EntityInstance& other) = default; + EntityInstance(EntityInstance&& other) = default; + EntityInstance& operator=(const EntityInstance& other) = default; + EntityInstance& operator=(EntityInstance&& other) = default; + EntityInstanceMetadata& metadata() { diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp index 9f3272eb9ba94c5751ea0b2d4f1c0893802eb0d6..73d4932155562ffe213504ce3b7bccfc93690b51 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp @@ -8,33 +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); - return *this; - } - wm::EntitySnapshot EntitySnapshot::convert() const { wm::EntitySnapshot m; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h index b8c3f491dc8b87979856786abe931ab1fc7eaeb7..79c0341643c4619270e6b264454ce50dffd0a202 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.h @@ -14,20 +14,15 @@ 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; + using Base::operator=; - /// Copy the instances from `other` to this. - EntitySnapshot& operator=(const EntitySnapshot& other); // Conversion wm::EntitySnapshot convert() const; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp index 9f216cb0338fc9ff8b7f47fa430acf99bf0cb92c..ac204816011ee0b760fa65a9fecea330edcadf97 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp @@ -9,33 +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); - return *this; - } - wm::Memory Memory::convert() const { wm::Memory m; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h index 1085de776eda6ac8e913d24c840b867a7fef969d..a381972a8c6670f10f286b5ecee82757c1be87d1 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h @@ -13,17 +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); - Memory& operator=(const Memory& other); + using Base::MemoryBase; + using Base::operator=; // Conversion diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp index dbdbdb1189fd2efdac397992b3cad480da77f863..38f2a142989324cab5aa9a47f2f80d7e91fa9b24 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp @@ -8,41 +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); - return *this; - } - wm::ProviderSegment ProviderSegment::convert() const { wm::ProviderSegment m; diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h index 5ac77dad663e34a3b3da6d39c53629d6a9415864..4e81db8a9270f58d44845d08f298b37d59424323 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.h @@ -14,18 +14,15 @@ 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); - ProviderSegment& operator=(const ProviderSegment& other); + using Base::ProviderSegmentBase; + using Base::operator=; + // Conversion wm::ProviderSegment convert() const; diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp index 4ef52fd749f9106d4ea1e9204fd0574392c18387..b4341c9da6b9bf6c1c9be6e1141ff712d9e00132 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp @@ -7,55 +7,13 @@ 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; - } - - 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..1eaf327338929b1290e476951aa69bdde0d3723d 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,27 @@ 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; + + CoreSegment(const CoreSegment& other) = default; + CoreSegment(CoreSegment&& other) = default; + CoreSegment& operator=(const CoreSegment& other) = default; + CoreSegment& operator=(CoreSegment&& other) = default; + + virtual ~CoreSegment() override = default; - 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..022864c19d9ea98583d9d3998bec46643921cdc8 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp @@ -2,46 +2,13 @@ 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; - } - - 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..6a31286722e0e78d53423f6aa6b517583f83ca09 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,27 @@ 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; + + Entity(const Entity& other) = default; + Entity(Entity&& other) = default; + Entity& operator=(const Entity& other) = default; + Entity& operator=(Entity&& other) = default; + + virtual ~Entity() override = default; - 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..95e508bde1412a87c865b2720bd227ec58595114 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp @@ -3,6 +3,17 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> +std::ostream& armarx::armem::wm::operator<<(std::ostream& os, const EntityInstanceMetadata& d) +{ + os << "EntityInstanceMetadata: " + << "\n- t_create = \t" << armem::toStringMicroSeconds(d.timeCreated) << " us" + << "\n- t_sent = \t" << armem::toStringMicroSeconds(d.timeSent) << " us" + << "\n- t_arrived = \t" << armem::toStringMicroSeconds(d.timeArrived) << " us" + << "\n- confidence = \t" << d.confidence << " us" + ; + return os; +} + namespace armarx::armem::wm { @@ -14,33 +25,6 @@ namespace armarx::armem::wm && std::abs(confidence - other.confidence) < 1e-6f; } - EntityInstance::EntityInstance() - { - } - - EntityInstance::EntityInstance(const EntityInstance& other) : - base::detail::MemoryItem(other.id()), - _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 +54,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..8e6eb1afe7e673baeab933397ebd16aa1781c18d 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 { @@ -28,21 +31,27 @@ namespace armarx::armem::wm } }; + std::ostream& operator<<(std::ostream& os, const EntityInstanceMetadata& rhs); + + /** * @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); - EntityInstance& operator=(const EntityInstance& other); + using Base::EntityInstanceBase; + + EntityInstance(const EntityInstance& other) = default; + EntityInstance(EntityInstance&& other) = default; + EntityInstance& operator=(const EntityInstance& other) = default; + EntityInstance& operator=(EntityInstance&& other) = default; + EntityInstanceMetadata& metadata() { @@ -74,18 +83,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..fb68d050a0ad19e1e2627e4cb5732a23a2ce4493 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp @@ -7,51 +7,12 @@ namespace armarx::armem::wm { - - - 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..ee0c78c5d201ed2e9fb1fe5c333efc728a9dccfc 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,20 @@ 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); - - /// Copy the instances from `other` to this. - EntitySnapshot& operator=(const EntitySnapshot& other); - - EntitySnapshot copyWithoutData() const override; + using Base::EntitySnapshotBase; + using Base::operator=; 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..b7af1a6456687b1741710d46fa157b9091295db7 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp @@ -1,54 +1,14 @@ #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; - } - - 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..e8b7cb35349837820c3dd47f2d584ef6b9760461 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,24 @@ 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; + + Memory(const Memory& other) = default; + Memory(Memory&& other) = default; + Memory& operator=(const Memory& other) = default; + Memory& operator=(Memory&& other) = 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..517b35bfad666cdac02041694e787523c4c1e894 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp @@ -8,54 +8,13 @@ namespace armarx::armem::wm { - ProviderSegment::ProviderSegment() + void ProviderSegment::_copySelfWithoutData(ProviderSegment& other) const { - } - - 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::copyWithoutData() const - { - ProviderSegment m; - _copySelfWithoutData(m); - return m; - } - - void ProviderSegment::_copySelfWithoutData(ProviderSegment& o) 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..0b703617d9b1b642153da505882e71aab8aa3723 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,28 @@ 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; + + ProviderSegment(const ProviderSegment& other) = default; + ProviderSegment(ProviderSegment&& other) = default; + ProviderSegment& operator=(const ProviderSegment& other) = default; + ProviderSegment& operator=(ProviderSegment&& other) = default; + + virtual ~ProviderSegment() override = default; - 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; - } - }; -} diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryIDTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryIDTest.cpp index 1f94d9adb9a2d023a3813c0e09edf8b41367ace1..aad3359b0d57cfed79d463cc27dcced44550ef00 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryIDTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryIDTest.cpp @@ -137,3 +137,30 @@ BOOST_AUTO_TEST_CASE(test_MemoryID_from_to_string) } + +BOOST_AUTO_TEST_CASE(test_MemoryID_copy_move_ctors_ops) +{ + const armem::MemoryID id("A/B/C/123/1"), moved("////1"); // int is not moved + { + const armem::MemoryID out(id); + BOOST_CHECK_EQUAL(out, id); + } + { + armem::MemoryID out; + out = id; + BOOST_CHECK_EQUAL(out, id); + } + { + armem::MemoryID in = id; + const armem::MemoryID out(std::move(in)); + BOOST_CHECK_EQUAL(in, moved); + BOOST_CHECK_EQUAL(out, id); + } + { + armem::MemoryID in = id; + armem::MemoryID out; + out = std::move(in); + BOOST_CHECK_EQUAL(in, moved); + BOOST_CHECK_EQUAL(out, id); + } +} diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index a30132549aacc14b80fd913dc83b302ba917a6c2..3c256468935e5be3a1da55e67359c8a6a079feec 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -32,13 +32,13 @@ #include <RobotAPI/libraries/armem/core/error.h> #include <iostream> +#include <SimoxUtility/meta/type_name.h> #include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> namespace armem = armarx::armem; namespace aron = armarx::aron; - BOOST_AUTO_TEST_CASE(test_time_to_string) { // 111111: seconds, 345: milliseconds, 789: microseconds @@ -78,6 +78,150 @@ BOOST_AUTO_TEST_CASE(test_time_to_string) } + + +namespace ArMemMemoryTest +{ + struct TestMemoryItem : public armem::base::detail::MemoryItem + { + using MemoryItem::MemoryItem; + using MemoryItem::operator=; + + std::string getKeyString() const override + { + return ""; + } + std::string getLevelName() const override + { + return ""; + } + }; + struct MemoryItemCtorOpTestFixture + { + const armem::MemoryID id {"A/B/C/123/1"}; + const armem::MemoryID moved {"////1"}; // int is not moved + TestMemoryItem item { id }; + + MemoryItemCtorOpTestFixture() + { + BOOST_CHECK_EQUAL(item.id(), id); + } + }; +} + + +BOOST_FIXTURE_TEST_SUITE(MemoryItemTest, ArMemMemoryTest::MemoryItemCtorOpTestFixture) + + +BOOST_AUTO_TEST_CASE(test_copy_ctor) +{ + const ArMemMemoryTest::TestMemoryItem out(item); + BOOST_CHECK_EQUAL(item.id(), id); + BOOST_CHECK_EQUAL(out.id(), id); +} +BOOST_AUTO_TEST_CASE(test_copy_op) +{ + ArMemMemoryTest::TestMemoryItem out; + out = item; + BOOST_CHECK_EQUAL(item.id(), id); + BOOST_CHECK_EQUAL(out.id(), id); +} +BOOST_AUTO_TEST_CASE(test_move_ctor) +{ + ArMemMemoryTest::TestMemoryItem in = item; + const ArMemMemoryTest::TestMemoryItem out(std::move(in)); + BOOST_CHECK_EQUAL(in.id(), moved); + BOOST_CHECK_EQUAL(out.id(), id); +} +BOOST_AUTO_TEST_CASE(test_move_op) +{ + ArMemMemoryTest::TestMemoryItem in = item; + ArMemMemoryTest::TestMemoryItem out; + out = std::move(in); + BOOST_CHECK_EQUAL(in.id(), moved); + BOOST_CHECK_EQUAL(out.id(), id); +} + + +BOOST_AUTO_TEST_SUITE_END() + + + +namespace ArMemMemoryTest +{ + struct TestMemoryContainer : public armem::base::detail::MemoryContainerBase<std::vector<int>, TestMemoryContainer> + { + using MemoryContainerBase::MemoryContainerBase; + using MemoryContainerBase::operator=; + + std::string getKeyString() const override + { + return ""; + } + std::string getLevelName() const override + { + return ""; + } + }; + struct MemoryContainerCtorOpTestFixture + { + const armem::MemoryID id {"A/B/C/123/1"}; + const armem::MemoryID moved {"////1"}; // int is not moved + TestMemoryContainer cont {id}; + + MemoryContainerCtorOpTestFixture() + { + cont.container() = std::vector<int>{ -1, 2, -3 }; + BOOST_CHECK_EQUAL(cont.id(), id); + BOOST_CHECK_EQUAL(cont.size(), 3); + } + }; + +} + +BOOST_FIXTURE_TEST_SUITE(MemoryContainerTest, ArMemMemoryTest::MemoryContainerCtorOpTestFixture) + +BOOST_AUTO_TEST_CASE(test_copy_ctor) +{ + const ArMemMemoryTest::TestMemoryContainer out(cont); + BOOST_CHECK_EQUAL(cont.id(), id); + BOOST_CHECK_EQUAL(cont.size(), 3); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 3); +} +BOOST_AUTO_TEST_CASE(test_copy_op) +{ + ArMemMemoryTest::TestMemoryContainer out; + out = cont; + BOOST_CHECK_EQUAL(cont.id(), id); + BOOST_CHECK_EQUAL(cont.size(), 3); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 3); +} +BOOST_AUTO_TEST_CASE(test_move_ctor) +{ + ArMemMemoryTest::TestMemoryContainer in = cont; + const ArMemMemoryTest::TestMemoryContainer out(std::move(in)); + BOOST_CHECK_EQUAL(in.id(), moved); + BOOST_CHECK_EQUAL(in.size(), 0); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 3); +} +BOOST_AUTO_TEST_CASE(test_move_op) +{ + ArMemMemoryTest::TestMemoryContainer in = cont; + ArMemMemoryTest::TestMemoryContainer out; + out = std::move(in); + BOOST_CHECK_EQUAL(in.id(), moved); + BOOST_CHECK_EQUAL(in.size(), 0); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 3); +} + +BOOST_AUTO_TEST_SUITE_END() + + + BOOST_AUTO_TEST_CASE(test_key_ctors) { armem::wm::EntityInstance instance(10); @@ -100,6 +244,338 @@ BOOST_AUTO_TEST_CASE(test_key_ctors) } +template <class ...Args> +auto add_element(std::vector<Args...>& vector) +{ + return vector.emplace_back(); +} +template <class ...Args> +auto add_element(std::map<Args...>& map) +{ + return map.emplace(); +} + + +template <class T> +struct CustomChecks +{ + static void checkEqual(const T& lhs, const T& rhs) + { + (void) lhs, (void) rhs; + } + static void checkMoved(const T& moved) + { + (void) moved; + } +}; + + +template <class T> +void checkEqual_d_ltm(const T& lhs, const T& rhs) +{ + BOOST_CHECK_EQUAL(lhs.path, rhs.path); +} +template <class T> +void checkMoved_d_ltm(const T& moved) +{ + BOOST_CHECK_EQUAL(moved.path, nullptr); +} + +template <> +struct CustomChecks<armem::wm::EntityInstance> +{ + static void checkEqual(const armem::wm::EntityInstance& lhs, const armem::wm::EntityInstance& rhs) + { + BOOST_CHECK_EQUAL(lhs.metadata(), rhs.metadata()); + BOOST_CHECK_EQUAL(lhs.data(), rhs.data()); + } + static void checkMoved(const armem::wm::EntityInstance& moved) + { + BOOST_CHECK_EQUAL(moved.data(), nullptr); + } +}; +template <> +struct CustomChecks<armem::d_ltm::EntityInstance> +{ + static void checkEqual(const armem::d_ltm::EntityInstance& lhs, const armem::d_ltm::EntityInstance& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::EntityInstance& moved) + { + checkMoved_d_ltm(moved); + } +}; +template <> +struct CustomChecks<armem::d_ltm::EntitySnapshot> +{ + static void checkEqual(const armem::d_ltm::EntitySnapshot& lhs, const armem::d_ltm::EntitySnapshot& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::EntitySnapshot& moved) + { + checkMoved_d_ltm(moved); + } +}; +template <> +struct CustomChecks<armem::d_ltm::Entity> +{ + static void checkEqual(const armem::d_ltm::Entity& lhs, const armem::d_ltm::Entity& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::Entity& moved) + { + checkMoved_d_ltm(moved); + } +}; +template <> +struct CustomChecks<armem::d_ltm::ProviderSegment> +{ + static void checkEqual(const armem::d_ltm::ProviderSegment& lhs, const armem::d_ltm::ProviderSegment& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::ProviderSegment& moved) + { + checkMoved_d_ltm(moved); + } +}; +template <> +struct CustomChecks<armem::d_ltm::CoreSegment> +{ + static void checkEqual(const armem::d_ltm::CoreSegment& lhs, const armem::d_ltm::CoreSegment& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::CoreSegment& moved) + { + checkMoved_d_ltm(moved); + } +}; +template <> +struct CustomChecks<armem::d_ltm::Memory> +{ + static void checkEqual(const armem::d_ltm::Memory& lhs, const armem::d_ltm::Memory& rhs) + { + checkEqual_d_ltm(lhs, rhs); + } + static void checkMoved(const armem::d_ltm::Memory& moved) + { + checkMoved_d_ltm(moved); + } +}; + + +struct CopyMoveCtorsOpsTestBase +{ + const armem::MemoryID id {"A/B/C/123000"}; // int index would not be moved + const armem::MemoryID idMoved; + + std::string typeName; + + CopyMoveCtorsOpsTestBase(const std::string& typeName) : + typeName(typeName) + { + } + virtual ~CopyMoveCtorsOpsTestBase() + { + } + + + void test() + { + BOOST_TEST_CONTEXT("Type " << typeName) + { + reset(); + BOOST_TEST_CONTEXT("copy ctor") + { + testCopyCtor(); + } + reset(); + BOOST_TEST_CONTEXT("copy op") + { + testCopyOp(); + } + reset(); + BOOST_TEST_CONTEXT("move ctor") + { + testMoveCtor(); + } + reset(); + BOOST_TEST_CONTEXT("move op") + { + testMoveOp(); + } + } + } + + virtual void reset() + { + } + + virtual void testCopyCtor() = 0; + virtual void testCopyOp() = 0; + virtual void testMoveCtor() = 0; + virtual void testMoveOp() = 0; +}; + + + +template <class T> +struct InstanceCopyMoveCtorsOpsTest : public CopyMoveCtorsOpsTestBase +{ + T in; + + InstanceCopyMoveCtorsOpsTest() : + CopyMoveCtorsOpsTestBase(simox::meta::get_type_name<T>()) + { + } + virtual ~InstanceCopyMoveCtorsOpsTest() override = default; + + void reset() override + { + in = T {id}; + BOOST_CHECK_EQUAL(in.id(), id); + } + + void testCopyCtor() override + { + T out { in }; + + BOOST_CHECK_EQUAL(out.id(), id); + + CustomChecks<T>::checkEqual(out, in); + } + void testCopyOp() override + { + T out; + out = in; + + BOOST_CHECK_EQUAL(out.id(), id); + + CustomChecks<T>::checkEqual(out, in); + } + void testMoveCtor() override + { + T out { std::move(in) }; + + BOOST_CHECK_EQUAL(in.id(), idMoved); + BOOST_CHECK_EQUAL(out.id(), id); + + CustomChecks<T>::checkMoved(in); + } + void testMoveOp() override + { + T out; + out = std::move(in); + + BOOST_CHECK_EQUAL(in.id(), idMoved); + BOOST_CHECK_EQUAL(out.id(), id); + + CustomChecks<T>::checkMoved(in); + } +}; + + +template <class T> +struct CopyMoveCtorsOpsTest : public CopyMoveCtorsOpsTestBase +{ + T in; + + CopyMoveCtorsOpsTest() : CopyMoveCtorsOpsTestBase(simox::meta::get_type_name<T>()) + { + } + virtual ~CopyMoveCtorsOpsTest() override = default; + + void reset() override + { + in = T {id}; + add_element(in.container()); + + BOOST_CHECK_EQUAL(in.id(), id); + BOOST_CHECK_EQUAL(in.size(), 1); + } + + void testCopyCtor() override + { + T out { in }; + BOOST_CHECK_EQUAL(in.id(), id); + BOOST_CHECK_EQUAL(in.size(), 1); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 1); + + CustomChecks<T>::checkEqual(out, in); + } + void testCopyOp() override + { + T out; + out = in; + BOOST_CHECK_EQUAL(in.id(), id); + BOOST_CHECK_EQUAL(in.size(), 1); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 1); + + CustomChecks<T>::checkEqual(out, in); + } + void testMoveCtor() override + { + T out { std::move(in) }; + + BOOST_CHECK_EQUAL(in.id(), idMoved); + BOOST_CHECK_EQUAL(in.size(), 0); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 1); + + CustomChecks<T>::checkMoved(in); + } + void testMoveOp() override + { + T out; + out = std::move(in); + + BOOST_CHECK_EQUAL(in.id(), idMoved); + BOOST_CHECK_EQUAL(in.size(), 0); + BOOST_CHECK_EQUAL(out.id(), id); + BOOST_CHECK_EQUAL(out.size(), 1); + + CustomChecks<T>::checkMoved(in); + } +}; + + + +BOOST_AUTO_TEST_CASE(test_copy_move_ctors_ops) +{ + { + InstanceCopyMoveCtorsOpsTest<armem::wm::EntityInstance>().test(); + CopyMoveCtorsOpsTest<armem::wm::EntitySnapshot>().test(); + CopyMoveCtorsOpsTest<armem::wm::Entity>().test(); + CopyMoveCtorsOpsTest<armem::wm::ProviderSegment>().test(); + CopyMoveCtorsOpsTest<armem::wm::CoreSegment>().test(); + CopyMoveCtorsOpsTest<armem::wm::Memory>().test(); + } + { + InstanceCopyMoveCtorsOpsTest<armem::ltm::EntityInstance>().test(); + CopyMoveCtorsOpsTest<armem::ltm::EntitySnapshot>().test(); + CopyMoveCtorsOpsTest<armem::ltm::Entity>().test(); + CopyMoveCtorsOpsTest<armem::ltm::ProviderSegment>().test(); + CopyMoveCtorsOpsTest<armem::ltm::CoreSegment>().test(); + CopyMoveCtorsOpsTest<armem::ltm::Memory>().test(); + } + { + InstanceCopyMoveCtorsOpsTest<armem::d_ltm::EntityInstance>().test(); + CopyMoveCtorsOpsTest<armem::d_ltm::EntitySnapshot>().test(); + CopyMoveCtorsOpsTest<armem::d_ltm::Entity>().test(); + CopyMoveCtorsOpsTest<armem::d_ltm::ProviderSegment>().test(); + CopyMoveCtorsOpsTest<armem::d_ltm::CoreSegment>().test(); + CopyMoveCtorsOpsTest<armem::d_ltm::Memory>().test(); + } +} + + + BOOST_AUTO_TEST_CASE(test_segment_setup) { armem::EntityUpdate update; @@ -291,43 +767,52 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) } + template <class T> -void test_the_copy_move_ctors_ops() +struct CopyTest { - T t1; + CopyTest() { - T t2 { t1 }; - t2 = t1; } + + void test() { - T t2 { std::move(t1) }; - t2 = std::move(t1); + // At least check whether they can be called. + T t; + T t2 = t.copy(); + + if constexpr (!std::is_base_of_v<armem::base::EntityInstanceBase<T>, T>) + { + t2 = t.copyEmpty(); + } } -} +}; -BOOST_AUTO_TEST_CASE(test_copy_move_ctors_ops) +BOOST_AUTO_TEST_CASE(test_copy) { - test_the_copy_move_ctors_ops<armem::wm::EntityInstance>(); - test_the_copy_move_ctors_ops<armem::wm::EntitySnapshot>(); - test_the_copy_move_ctors_ops<armem::wm::Entity>(); - test_the_copy_move_ctors_ops<armem::wm::ProviderSegment>(); - test_the_copy_move_ctors_ops<armem::wm::CoreSegment>(); - test_the_copy_move_ctors_ops<armem::wm::Memory>(); - - test_the_copy_move_ctors_ops<armem::ltm::EntityInstance>(); - test_the_copy_move_ctors_ops<armem::ltm::EntitySnapshot>(); - test_the_copy_move_ctors_ops<armem::ltm::Entity>(); - test_the_copy_move_ctors_ops<armem::ltm::ProviderSegment>(); - test_the_copy_move_ctors_ops<armem::ltm::CoreSegment>(); - test_the_copy_move_ctors_ops<armem::ltm::Memory>(); - - test_the_copy_move_ctors_ops<armem::d_ltm::EntityInstance>(); - test_the_copy_move_ctors_ops<armem::d_ltm::EntitySnapshot>(); - test_the_copy_move_ctors_ops<armem::d_ltm::Entity>(); - test_the_copy_move_ctors_ops<armem::d_ltm::ProviderSegment>(); - test_the_copy_move_ctors_ops<armem::d_ltm::CoreSegment>(); - test_the_copy_move_ctors_ops<armem::d_ltm::Memory>(); - - BOOST_CHECK(true); + { + CopyTest<armem::wm::EntityInstance>().test(); + CopyTest<armem::wm::EntitySnapshot>().test(); + CopyTest<armem::wm::Entity>().test(); + CopyTest<armem::wm::ProviderSegment>().test(); + CopyTest<armem::wm::CoreSegment>().test(); + CopyTest<armem::wm::Memory>().test(); + } + { + CopyTest<armem::ltm::EntityInstance>().test(); + CopyTest<armem::ltm::EntitySnapshot>().test(); + CopyTest<armem::ltm::Entity>().test(); + CopyTest<armem::ltm::ProviderSegment>().test(); + CopyTest<armem::ltm::CoreSegment>().test(); + CopyTest<armem::ltm::Memory>().test(); + } + { + CopyTest<armem::d_ltm::EntityInstance>().test(); + CopyTest<armem::d_ltm::EntitySnapshot>().test(); + CopyTest<armem::d_ltm::Entity>().test(); + CopyTest<armem::d_ltm::ProviderSegment>().test(); + CopyTest<armem::d_ltm::CoreSegment>().test(); + CopyTest<armem::d_ltm::Memory>().test(); + } } diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp index 3f40956a61149b1aca6af0b0fa2a9c3f129a18da..447b35332a60a3442b63e07a2c5e129b5b7b83d1 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp @@ -27,36 +27,43 @@ namespace armarx::armem::gui { MemoryViewer::MemoryViewer( - QBoxLayout* ltmControlWidgetLayout, QBoxLayout* updateWidgetLayout, - QGroupBox* _memoryGroupBox, QLayout* memoryGroupBoxParentLayout, - QGroupBox* _instanceGroupBox, QLayout* instanceGroupBoxParentLayout, - QLabel* statusLabel) + QBoxLayout* ltmControlWidgetLayout, + QGroupBox* memoryGroupBox, QLayout* memoryGroupBoxParentLayout, + QGroupBox* instanceGroupBox, QLayout* instanceGroupBoxParentLayout, + QLabel* statusLabel + ) { Logging::setTag("MemoryViewer"); this->statusLabel = statusLabel; this->statusLabel->clear(); - // LTM Control - this->ltmControlWidgetLayout = ltmControlWidgetLayout; - ltmControlWidget = new armem::gui::LTMControlWidget(); - ltmControlWidgetLayout->insertWidget(0, ltmControlWidget); - // Update timer this->updateWidgetLayout = updateWidgetLayout; updateWidget = new armem::gui::PeriodicUpdateWidget(2.0, 60); updateWidgetLayout->insertWidget(0, updateWidget); + // LTM Control + if (ltmControlWidgetLayout) + { + this->ltmControlWidgetLayout = ltmControlWidgetLayout; + ltmControlWidget = new armem::gui::LTMControlWidget(); + ltmControlWidgetLayout->addWidget(ltmControlWidget); + } + + // Memory View memoryGroup = new armem::gui::MemoryGroupBox(); - armarx::gui::replaceWidget(_memoryGroupBox, memoryGroup, memoryGroupBoxParentLayout); - ARMARX_CHECK_NULL(_memoryGroupBox); + armarx::gui::replaceWidget(memoryGroupBox, memoryGroup, memoryGroupBoxParentLayout); + ARMARX_CHECK_NULL(memoryGroupBox); + // Instance View this->instanceGroup = new armem::gui::InstanceGroupBox(); - armarx::gui::replaceWidget(_instanceGroupBox, instanceGroup, instanceGroupBoxParentLayout); + armarx::gui::replaceWidget(instanceGroupBox, instanceGroup, instanceGroupBoxParentLayout); this->instanceGroup->setStatusLabel(statusLabel); - ARMARX_CHECK_NULL(_instanceGroupBox); + ARMARX_CHECK_NULL(instanceGroupBox); + // Connections //connect(this, &This::connected, this, &This::updateMemory); connect(ltmControlWidget, &armem::gui::LTMControlWidget::store, this, &This::store); diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h index c2c2e6f4c7d251f23f19cb2f7275878940a603d5..19ab5000d9d662080b80e621144650fd887a0bcd 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h @@ -44,10 +44,10 @@ namespace armarx::armem::gui public: MemoryViewer( - QBoxLayout* ltmControlWidgetLayout, QBoxLayout* updateWidgetLayout, - QGroupBox* _memoryGroupBox, QLayout* memoryGroupBoxParentLayout, - QGroupBox* _instanceGroupBox, QLayout* instanceGroupBoxParentLayout, + QBoxLayout* ltmControlWidgetLayout, + QGroupBox* memoryGroupBox, QLayout* memoryGroupBoxParentLayout, + QGroupBox* instanceGroupBox, QLayout* instanceGroupBoxParentLayout, QLabel* statusLabel ); @@ -106,15 +106,15 @@ namespace armarx::armem::gui std::map<std::string, armem::client::Reader> memoryReaders; std::map<std::string, std::optional<armem::wm::Memory>> memoryData; - QLayout* ltmControlWidgetLayout; - armem::gui::LTMControlWidget* ltmControlWidget; + QLayout* updateWidgetLayout = nullptr; + armem::gui::PeriodicUpdateWidget* updateWidget = nullptr; - QLayout* updateWidgetLayout; - armem::gui::PeriodicUpdateWidget* updateWidget; + QLayout* ltmControlWidgetLayout = nullptr; + armem::gui::LTMControlWidget* ltmControlWidget = nullptr; - armem::gui::MemoryGroupBox* memoryGroup; + armem::gui::MemoryGroupBox* memoryGroup = nullptr; - armem::gui::InstanceGroupBox* instanceGroup; + armem::gui::InstanceGroupBox* instanceGroup = nullptr; QLabel* statusLabel = nullptr; diff --git a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp index 3d4c50f66c6263ec474acd552233b86f895a7862..a410033a4dcdda6b0e17f0de7ab35e4f9a044f12 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp @@ -74,7 +74,7 @@ namespace armarx::armem::gui::memory }); workingmemoryCoreSegmentBuilder.setUpdateItemFn([this](const std::string&, const wm::CoreSegment & coreSeg, QTreeWidgetItem * coreSegItem) { - updateTypedContainerItem(coreSeg, coreSegItem); + updateContainerItem(coreSeg, coreSegItem); updateChildren(coreSeg, coreSegItem); return true; }); @@ -86,7 +86,7 @@ namespace armarx::armem::gui::memory }); workingmemoryProvSegmentBuilder.setUpdateItemFn([this](const std::string&, const wm::ProviderSegment & provSeg, QTreeWidgetItem * provSegItem) { - updateTypedContainerItem(provSeg, provSegItem); + updateContainerItem(provSeg, provSegItem); updateChildren(provSeg, provSegItem); return true; }); @@ -279,28 +279,26 @@ namespace armarx::armem::gui::memory template <class... T> void TreeWidget::updateContainerItem( - const armem::wm::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item) + const base::detail::MemoryContainerBase<T...>& container, QTreeWidgetItem* item) { updateItemItem(container, item); item->setText(int(Columns::SIZE), QString::number(container.size())); - } - template <class... T> - void TreeWidget::updateTypedContainerItem( - const armem::wm::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item) - { - updateContainerItem(container, item); - std::string typeName; - if (container.aronType()) - { - typeName = container.aronType()->getName(); - typeName = instance::sanitizeTypeName(typeName); - } - else + if constexpr(std::is_base_of_v<base::detail::AronTyped, base::detail::MemoryContainerBase<T...>>) { - typeName = "(no Aron type)"; + const base::detail::AronTyped& cast = dynamic_cast<const base::detail::AronTyped&>(container); + std::string typeName; + if (cast.aronType()) + { + typeName = cast.aronType()->getName(); + typeName = instance::sanitizeTypeName(typeName); + } + else + { + typeName = "(no Aron type)"; + } + item->setText(int(Columns::TYPE), QString::fromStdString(typeName)); } - item->setText(int(Columns::TYPE), QString::fromStdString(typeName)); } } diff --git a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h index 1ce80192013f4d045ff84b4f461589bbd4a43297..2bcf0fa1b6135534407044a3ce341b86afeab442 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h @@ -71,9 +71,7 @@ namespace armarx::armem::gui::memory void updateItemItem(const armem::base::detail::MemoryItem& level, QTreeWidgetItem* item); template <class... T> - void updateContainerItem(const armem::wm::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item); - template <class... T> - void updateTypedContainerItem(const armem::wm::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item); + void updateContainerItem(const armem::base::detail::MemoryContainerBase<T...>& container, QTreeWidgetItem* item); private: diff --git a/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp b/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp index d1e0e4a011e05edc22c2ab8fb0835b95150c24da..4f259c7af5a50ff198b139084eb604bfd06fead5 100644 --- a/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp +++ b/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp @@ -30,12 +30,27 @@ #include <iostream> #include <RobotAPI/libraries/armem_gui/instance/sanitize_typename.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> using namespace armarx::armem::gui::instance; BOOST_AUTO_TEST_CASE(test_sanitizeTypeName) { - BOOST_CHECK_EQUAL(sanitizeTypeName("AronDictType<AronFloatType>"), "Dict<Float>"); - BOOST_CHECK_EQUAL(sanitizeTypeName("AronListType<AronFloatType>"), "List<Float>"); + using namespace armarx::aron::typenavigator; + { + DictNavigator dict; + dict.setAcceptedType(std::make_shared<FloatNavigator>()); + BOOST_CHECK_EQUAL(sanitizeTypeName(dict.getName()), "Dict<Float>"); + } + { + ListNavigator dict; + dict.setAcceptedType(std::make_shared<LongNavigator>()); + BOOST_CHECK_EQUAL(sanitizeTypeName(dict.getName()), "Dict<Long>"); + } + { + ObjectNavigator dict; + dict.setObjectName("namespace::MyObjectName"); + BOOST_CHECK_EQUAL(sanitizeTypeName(dict.getName()), "namespace::MyObjectName"); + } }