diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp index 69c11b153943e5b8b7eb7d89ce38ba819e312d4d..0feb71ccb9d6921f28f0d5c1e0b14f5fb428c75a 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp @@ -157,31 +157,31 @@ namespace armarx if (qResult.success) { - armem::MemoryPtr result = armem::fromIce<armem::MemoryPtr>(qResult.memory); + armem::Memory result = armem::fromIce<armem::Memory>(qResult.memory); - ARMARX_CHECK_EQUAL(result->coreSegments.size(), 1); - armem::CoreSegmentPtr& coreSeg = result->coreSegments.begin()->second; + ARMARX_CHECK_EQUAL(result.coreSegments.size(), 1); + armem::CoreSegment& coreSeg = result.coreSegments.begin()->second; - ARMARX_CHECK_EQUAL(coreSeg->providerSegments.size(), 1); - armem::ProviderSegmentPtr& provSeg = coreSeg->providerSegments.begin()->second; + ARMARX_CHECK_EQUAL(coreSeg.providerSegments.size(), 1); + armem::ProviderSegment& provSeg = coreSeg.providerSegments.begin()->second; - ARMARX_CHECK_EQUAL(provSeg->entities.size(), 1); - armem::EntityPtr& entity = provSeg->entities.begin()->second; + ARMARX_CHECK_EQUAL(provSeg.entities.size(), 1); + armem::Entity& entity = provSeg.entities.begin()->second; - ARMARX_CHECK_GREATER_EQUAL(entity->history.size(), 1); - armem::EntitySnapshotPtr& snapshot = entity->history.begin()->second; + ARMARX_CHECK_GREATER_EQUAL(entity.history.size(), 1); + armem::EntitySnapshot& snapshot = entity.history.begin()->second; ARMARX_INFO << "Result: " - << "\n- memory: \t" << result->name() - << "\n- core segment: \t" << coreSeg->name() - << "\n- prov segment: \t" << provSeg->name() - << "\n- entity: \t" << entity->name() - << "\n- snapshot: \t" << snapshot->time() - << "\n- #instances: \t" << snapshot->instances.size() + << "\n- memory: \t" << result.name() + << "\n- core segment: \t" << coreSeg.name() + << "\n- prov segment: \t" << provSeg.name() + << "\n- entity: \t" << entity.name() + << "\n- snapshot: \t" << snapshot.time() + << "\n- #instances: \t" << snapshot.instances.size() ; ARMARX_IMPORTANT << "Getting entity from snapshot ID"; - const armem::Entity& e = result->getEntity(entityID); + const armem::Entity& e = result.getEntity(entityID); ARMARX_INFO << "Result: " << "\n- entity: \t" << e.name() << "\n- snapshot: \t" << e.getLatestSnapshot().time() @@ -219,8 +219,8 @@ namespace armarx if (qResult.success) { - armem::MemoryPtr memory = std::move(qResult.memory); - armem::EntitySnapshot& entitySnapshot = memory->getEntity(snapshotID).getLatestSnapshot(); + armem::Memory memory = std::move(qResult.memory); + armem::EntitySnapshot& entitySnapshot = memory.getEntity(snapshotID).getLatestSnapshot(); ARMARX_INFO << "Result snapshot: " << "\n- time: \t" << entitySnapshot.time() diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h index 07401d4c435ff92b4fea0b0b51cc23027ef56bc6..ffdfc1154ad2131199f4c7d56dea46d154d40b71 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h @@ -136,7 +136,7 @@ namespace armarx { std::atomic_bool rebuild = false; - armem::MemoryPtr queryResult; + std::optional<armem::Memory> queryResult; RemoteGui::Client::GroupBox queryResultGroup; }; RemoteGuiTab tab; diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h index 08e3be5a0fce91ecbc60867f4ee7957d32353b46..64ff70a8f9a4f0922e7dac6ecf5e02b1c343cc8d 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h @@ -128,7 +128,7 @@ namespace armarx armem::MemoryInterfacePrx memory; armem::client::Reader memoryReader; - armem::MemoryPtr memoryData; + std::optional<armem::Memory> memoryData; armem::gui::MemoryTreeWidget* memoryTree; armem::gui::QueryWidget* queryTabs; diff --git a/source/RobotAPI/interface/armem/memory.ice b/source/RobotAPI/interface/armem/memory.ice index 960d15efae133392c4f18fc5e787b367ea2ff883..bbf0059faf5329210ee086cf12756c098be73f1a 100644 --- a/source/RobotAPI/interface/armem/memory.ice +++ b/source/RobotAPI/interface/armem/memory.ice @@ -7,8 +7,6 @@ module armarx { module armem { - // WIP - module data { struct MemoryID diff --git a/source/RobotAPI/libraries/armem/client/Query.h b/source/RobotAPI/libraries/armem/client/Query.h index 8519c7d3452830d1d54564b17342f8be0a900814..c87435fa3c67a38788e5d80d2812b2328831f917 100644 --- a/source/RobotAPI/libraries/armem/client/Query.h +++ b/source/RobotAPI/libraries/armem/client/Query.h @@ -31,7 +31,7 @@ namespace armarx::armem::client */ struct QueryResult : public detail::SuccessHeader { - MemoryPtr memory; + Memory memory; static QueryResult fromIce(const data::QueryResult& ice); diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/CoreSegment.cpp index a4250f86bb955e81c0a7f55cf94bbb865df08246..c1d81cc204ffa4f5df58cd493c9860e55447ab88 100644 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/CoreSegment.cpp @@ -69,7 +69,7 @@ namespace armarx::armem other.providerSegments.clear(); for (const auto& [name, providerSegment] : this->providerSegments) { - other.addProviderSegment(providerSegment->copy(withData)); + other.addProviderSegment(providerSegment.copy(withData)); } } @@ -89,8 +89,7 @@ namespace armarx::armem auto it = this->providerSegments.find(name); if (it != providerSegments.end()) { - ARMARX_CHECK_NOT_NULL(it->second); - return *it->second; + return it->second; } else { @@ -108,26 +107,24 @@ namespace armarx::armem ProviderSegment& CoreSegment::addProviderSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr providerSegmentType) { aron::typenavigator::AronObjectTypeNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType(); - return addProviderSegment(std::make_unique<ProviderSegment>(name, type)); + return addProviderSegment(ProviderSegment(name, type)); } ProviderSegment& CoreSegment::addProviderSegment(const ProviderSegment& providerSegment) { - return addProviderSegment(std::make_unique<ProviderSegment>(providerSegment)); + return addProviderSegment(ProviderSegment(providerSegment)); } - ProviderSegment& CoreSegment::addProviderSegment(ProviderSegmentPtr&& providerSegment) + ProviderSegment& CoreSegment::addProviderSegment(ProviderSegment&& providerSegment) { - ARMARX_CHECK_NOT_NULL(providerSegment); - if (hasProviderSegment(providerSegment->name())) + if (hasProviderSegment(providerSegment.name())) { throw armem::error::ContainerEntryAlreadyExists( - providerSegment->getLevelName(), providerSegment->name(), getLevelName(), this->name()); + providerSegment.getLevelName(), providerSegment.name(), getLevelName(), this->name()); } - auto it = providerSegments.emplace(providerSegment->name(), std::move(providerSegment)).first; - ARMARX_CHECK_NOT_NULL(it->second); - it->second->id().setCoreSegmentID(id()); - return *it->second; + auto it = providerSegments.emplace(providerSegment.name(), std::move(providerSegment)).first; + it->second.id().setCoreSegmentID(id()); + return it->second; } std::string CoreSegment::getLevelName() const @@ -148,7 +145,7 @@ namespace armarx::armem auto it = this->providerSegments.find(update.entityID.providerSegmentName); if (it != providerSegments.end()) { - return it->second->update(update); + return it->second.update(update); } else { diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.h b/source/RobotAPI/libraries/armem/core/CoreSegment.h index 18c40941f05d3987f8a1ef07493c587596c46b14..eb20e6abc9243ac9a6f18d4db9f14e65c7376f84 100644 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/CoreSegment.h @@ -1,7 +1,6 @@ #pragma once #include <map> -#include <memory> #include <string> #include "ProviderSegment.h" @@ -11,15 +10,12 @@ namespace armarx::armem { - class CoreSegment; - using CoreSegmentPtr = std::unique_ptr<CoreSegment>; - /** * @brief Data of a core segment containing multiple provider segments. */ - class CoreSegment : public detail::TypedEntityContainer<ProviderSegmentPtr, CoreSegment> + class CoreSegment : public detail::TypedEntityContainer<ProviderSegment, CoreSegment> { - using Base = detail::TypedEntityContainer<ProviderSegmentPtr, CoreSegment>; + using Base = detail::TypedEntityContainer<ProviderSegment, CoreSegment>; public: @@ -61,7 +57,7 @@ namespace armarx::armem /// Copy and insert a provider segment. ProviderSegment& addProviderSegment(const ProviderSegment& providerSegment); /// Move and insert a provider segment. - ProviderSegment& addProviderSegment(ProviderSegmentPtr&& providerSegment); + ProviderSegment& addProviderSegment(ProviderSegment&& providerSegment); // MemoryItem interface @@ -77,7 +73,7 @@ namespace armarx::armem public: /// The provider segments. - std::map<std::string, ProviderSegmentPtr> providerSegments; + std::map<std::string, ProviderSegment> providerSegments; }; diff --git a/source/RobotAPI/libraries/armem/core/Entity.cpp b/source/RobotAPI/libraries/armem/core/Entity.cpp index b1607a1316b61b33a1ff2f41c461a4161e71003f..1bccf59cb9700d171b26feb31844d1863cc40a6c 100644 --- a/source/RobotAPI/libraries/armem/core/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/Entity.cpp @@ -63,15 +63,7 @@ namespace armarx::armem other.history.clear(); for (const auto& [time, snapshot] : this->history) { - if (snapshot) - { - other.addSnapshot(snapshot->copy(withData)); - } - else - { - throw error::MissingData("entity snapshot", toDateTimeMilliSeconds(time), - getLevelName(), this->name()); - } + other.addSnapshot(snapshot.copy(withData)); } } @@ -83,8 +75,7 @@ namespace armarx::armem bool Entity::hasSnapshotData(Time time) const { - auto it = history.find(time); - return it != history.end() && (it->second != nullptr); + return history.count(time) > 0; } EntitySnapshot& Entity::getSnapshot(Time time) @@ -97,15 +88,7 @@ namespace armarx::armem auto it = history.find(time); if (it != history.end()) { - if (it->second) - { - return *it->second; - } - else - { - throw error::MissingData("entity snapshot", toDateTimeMilliSeconds(time), - getLevelName(), this->name()); - } + return it->second; } else { @@ -132,16 +115,7 @@ namespace armarx::armem const EntitySnapshot& Entity::getLatestSnapshot() const { - auto& latest = getLatestItem(); - if (latest.second) - { - return *latest.second; - } - else - { - throw error::MissingData("entity snapshot", toDateTimeMilliSeconds(latest.first), - getLevelName(), this->name()); - } + return getLatestItem().second; } Time Entity::getLatestTimestamp() const @@ -157,25 +131,20 @@ namespace armarx::armem EntitySnapshot& Entity::addSnapshot(const EntitySnapshot& snapshot) { - return addSnapshot(std::make_unique<EntitySnapshot>(snapshot)); + return addSnapshot(EntitySnapshot(snapshot)); } - EntitySnapshot& Entity::addSnapshot(EntitySnapshotPtr&& snapshot) + EntitySnapshot& Entity::addSnapshot(EntitySnapshot&& snapshot) { - if (!snapshot) - { - throw error::InvalidArgument("snapshot", __FUNCTION__, "Passed snapshot pointer is null."); - } - auto it = history.emplace(snapshot->time(), std::move(snapshot)).first; - ARMARX_CHECK_NOT_NULL(it->second); - it->second->id().setEntityID(id()); - return *it->second; + auto it = history.emplace(snapshot.time(), std::move(snapshot)).first; + it->second.id().setEntityID(id()); + return it->second; } EntitySnapshot& Entity::addSnapshot(const Time& timestamp) { - return addSnapshot(std::make_unique<EntitySnapshot>(timestamp)); + return addSnapshot(EntitySnapshot(timestamp)); } MemoryID Entity::update(const EntityUpdate& update) @@ -194,7 +163,7 @@ namespace armarx::armem } else { - snapshot = it->second.get(); + snapshot = &it->second; } // Update entry. snapshot->update(update); @@ -230,7 +199,7 @@ namespace armarx::armem } } - const std::map<Time, EntitySnapshotPtr>::value_type& Entity::getLatestItem() const + const std::map<Time, EntitySnapshot>::value_type& Entity::getLatestItem() const { if (history.empty()) { diff --git a/source/RobotAPI/libraries/armem/core/Entity.h b/source/RobotAPI/libraries/armem/core/Entity.h index 38241963f15cc53af1b93dd280647409d765622f..b4618a9c05d47e63f5f5412c5989ef335a497440 100644 --- a/source/RobotAPI/libraries/armem/core/Entity.h +++ b/source/RobotAPI/libraries/armem/core/Entity.h @@ -1,7 +1,6 @@ #pragma once #include <map> -#include <memory> #include <string> #include "../core/Time.h" @@ -14,9 +13,6 @@ namespace armarx::armem { - class Entity; - using EntityPtr = std::unique_ptr<Entity>; - /** * @brief An entity over a period of time. * @@ -37,9 +33,9 @@ namespace armarx::armem * each containing a single `AronData` object of a specific `AronType`. */ class Entity : - public detail::MemoryContainer<std::map<Time, EntitySnapshotPtr>, Entity> + public detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity> { - using Base = detail::MemoryContainer<std::map<Time, EntitySnapshotPtr>, Entity>; + using Base = detail::MemoryContainer<std::map<Time, EntitySnapshot>, Entity>; public: @@ -124,7 +120,7 @@ namespace armarx::armem * @return The stored snapshot. */ EntitySnapshot& addSnapshot(const EntitySnapshot& snapshot); - EntitySnapshot& addSnapshot(EntitySnapshotPtr&& snapshot); + EntitySnapshot& addSnapshot(EntitySnapshot&& snapshot); EntitySnapshot& addSnapshot(const Time& timestamp); @@ -155,12 +151,12 @@ namespace armarx::armem * @return The latest snapshot. * @throw `armem::error::EntityHistoryEmpty` If the history is empty. */ - const std::map<Time, EntitySnapshotPtr>::value_type& getLatestItem() const; + const std::map<Time, EntitySnapshot>::value_type& getLatestItem() const; public: - std::map<Time, EntitySnapshotPtr> history; + std::map<Time, EntitySnapshot> history; /** * @brief Maximum size of `history` diff --git a/source/RobotAPI/libraries/armem/core/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/EntityInstance.cpp index e43f3c58711cbfeef2ab26c3c004b2f0d3728285..1d1dbd21631b53b8072e2173d88928be1ee563d6 100644 --- a/source/RobotAPI/libraries/armem/core/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/EntityInstance.cpp @@ -50,14 +50,13 @@ namespace armarx::armem this->_metadata.timeArrived = update.timeArrived; } - EntityInstancePtr EntityInstance::copy(bool withData) const + EntityInstance EntityInstance::copy(bool withData) const { - EntityInstancePtr other = std::make_unique<EntityInstance>(); - other->id() = id(); - other->_metadata = _metadata; + EntityInstance other(id()); + other._metadata = _metadata; if (withData) { - other->setData(_data); + other.setData(_data); } return other; } diff --git a/source/RobotAPI/libraries/armem/core/EntityInstance.h b/source/RobotAPI/libraries/armem/core/EntityInstance.h index 3db4171c41d4557371f3f83be7a31508c247554c..5d5c1ae095b391a9639fc0694efa1f454d409560 100644 --- a/source/RobotAPI/libraries/armem/core/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/EntityInstance.h @@ -1,7 +1,5 @@ #pragma once -#include <memory> - #include <RobotAPI/interface/aron.h> #include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> @@ -33,9 +31,6 @@ namespace armarx::armem }; - class EntityInstance; - using EntityInstancePtr = std::unique_ptr<EntityInstance>; - /** * @brief Data of a single entity instance. */ @@ -79,7 +74,6 @@ namespace armarx::armem } - /** * @brief Fill `*this` with the update's values. * @param update The update. @@ -88,7 +82,7 @@ namespace armarx::armem void update(const EntityUpdate& update, int index); - EntityInstancePtr copy(bool withData = true) const; + EntityInstance copy(bool withData = true) const; // MemoryItem interface @@ -99,6 +93,7 @@ namespace armarx::armem private: + /// The metadata. EntityInstanceMetadata _metadata; /// The data. May be nullptr. diff --git a/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp index 834355e513c17186c0fe64a9afbb78e38e0f29a1..7980b3fa40d490d913adcf0d72682dde997904ef 100644 --- a/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/EntitySnapshot.cpp @@ -59,7 +59,7 @@ namespace armarx::armem other.instances.reserve(this->instances.size()); for (const auto& data : this->instances) { - other.instances.emplace_back(data->copy(withData)); + other.instances.emplace_back(data.copy(withData)); } } @@ -76,8 +76,8 @@ namespace armarx::armem instances.clear(); for (int i = 0; i < int(update.instancesData.size()); ++i) { - EntityInstancePtr& data = instances.emplace_back(std::make_unique<EntityInstance>(i, id())); - data->update(update, i); + EntityInstance& data = instances.emplace_back(i, id()); + data.update(update, i); } } @@ -98,7 +98,7 @@ namespace armarx::armem if (hasInstance(index)) { size_t si = size_t(index); - return *instances[si]; + return instances[si]; } else { diff --git a/source/RobotAPI/libraries/armem/core/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/EntitySnapshot.h index 23a2c23a4df97e38264bb602390ee51cd518b0f9..14d6c458497c5af10ed21e506fe38039f7d84114 100644 --- a/source/RobotAPI/libraries/armem/core/EntitySnapshot.h +++ b/source/RobotAPI/libraries/armem/core/EntitySnapshot.h @@ -14,17 +14,13 @@ namespace armarx::armem { - class EntitySnapshot; - using EntitySnapshotPtr = std::unique_ptr<EntitySnapshot>; - - /** * @brief Data of an entity at one point in time. */ class EntitySnapshot : - public detail::MemoryContainer<std::vector<EntityInstancePtr>, EntitySnapshot> + public detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot> { - using Base = detail::MemoryContainer<std::vector<EntityInstancePtr>, EntitySnapshot>; + using Base = detail::MemoryContainer<std::vector<EntityInstance>, EntitySnapshot>; public: @@ -88,7 +84,7 @@ namespace armarx::armem public: - std::vector<EntityInstancePtr> instances; + std::vector<EntityInstance> instances; }; diff --git a/source/RobotAPI/libraries/armem/core/Memory.cpp b/source/RobotAPI/libraries/armem/core/Memory.cpp index 56594cfcc3c9862096f46add46779d650d7b2027..6979ebdeb4bb22438169b8e25eb7fb8cb2b254ce 100644 --- a/source/RobotAPI/libraries/armem/core/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/Memory.cpp @@ -48,7 +48,7 @@ namespace armarx::armem other.coreSegments.clear(); for (const auto& [name, coreSegment] : this->coreSegments) { - other.coreSegments.emplace(name, coreSegment->copy(withData)); + other.coreSegments.emplace(name, coreSegment.copy(withData)); } } @@ -67,8 +67,7 @@ namespace armarx::armem auto it = this->coreSegments.find(name); if (it != coreSegments.end()) { - ARMARX_CHECK_NOT_NULL(it->second); - return *it->second; + return it->second; } else { @@ -86,29 +85,24 @@ namespace armarx::armem CoreSegment& Memory::addCoreSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr coreSegmentType) { - return addCoreSegment(std::make_unique<CoreSegment>(name, coreSegmentType)); + return addCoreSegment(CoreSegment(name, coreSegmentType)); } CoreSegment& Memory::addCoreSegment(const CoreSegment& coreSegment) { - return addCoreSegment(std::make_unique<CoreSegment>(coreSegment)); + return addCoreSegment(CoreSegment(coreSegment)); } - CoreSegment& Memory::addCoreSegment(CoreSegmentPtr&& coreSegment) + CoreSegment& Memory::addCoreSegment(CoreSegment&& coreSegment) { - if (!coreSegment) + if (coreSegments.count(coreSegment.name()) > 0) { - throw armem::error::InvalidArgument("coreSegment", __FUNCTION__, "Must not be null."); - } - if (coreSegments.count(coreSegment->name()) > 0) - { - throw armem::error::ContainerEntryAlreadyExists(coreSegment->getLevelName(), coreSegment->name(), + throw armem::error::ContainerEntryAlreadyExists(coreSegment.getLevelName(), coreSegment.name(), this->getLevelName(), this->name()); } - auto it = coreSegments.emplace(coreSegment->name(), std::move(coreSegment)).first; - ARMARX_CHECK_NOT_NULL(it->second); - it->second->id().setMemoryID(id()); - return *it->second; + auto it = coreSegments.emplace(coreSegment.name(), std::move(coreSegment)).first; + it->second.id().setMemoryID(id()); + return it->second; } std::vector<CoreSegment*> Memory::addCoreSegments(const std::vector<std::string>& names) @@ -136,7 +130,7 @@ namespace armarx::armem auto it = this->coreSegments.find(update.entityID.coreSegmentName); if (it != coreSegments.end()) { - return it->second->update(update); + return it->second.update(update); } else { @@ -165,7 +159,7 @@ namespace armarx::armem return false; } - if (not(core->equalsDeep(other.getCoreSegment(key)))) + if (not(core.equalsDeep(other.getCoreSegment(key)))) { return false; } diff --git a/source/RobotAPI/libraries/armem/core/Memory.h b/source/RobotAPI/libraries/armem/core/Memory.h index e5349ea366754f2b62e7c7eeb814cd7fd7065dfd..1f38f7eab44be7f08020c1e78c41a3460b9ebe76 100644 --- a/source/RobotAPI/libraries/armem/core/Memory.h +++ b/source/RobotAPI/libraries/armem/core/Memory.h @@ -1,7 +1,6 @@ #pragma once #include <map> -#include <memory> #include <string> #include "CoreSegment.h" @@ -10,15 +9,12 @@ namespace armarx::armem { - class Memory; - using MemoryPtr = std::unique_ptr<Memory>; - /** * @brief Data of a memory consisting of multiple core segments. */ - class Memory : public detail::EntityContainer<CoreSegmentPtr, Memory> + class Memory : public detail::EntityContainer<CoreSegment, Memory> { - using Base = detail::EntityContainer<CoreSegmentPtr, Memory>; + using Base = detail::EntityContainer<CoreSegment, Memory>; public: @@ -55,7 +51,7 @@ namespace armarx::armem /// Copy and insert a core segment. CoreSegment& addCoreSegment(const CoreSegment& coreSegment); /// Move and insert a core segment. - CoreSegment& addCoreSegment(CoreSegmentPtr&& coreSegment); + CoreSegment& addCoreSegment(CoreSegment&& coreSegment); /** * @brief Add multiple core segments. @@ -67,8 +63,10 @@ namespace armarx::armem virtual MemoryID update(const EntityUpdate& update) override; using Base::update; + bool equalsDeep(const Memory& other) const; + // MemoryItem interface public: std::string getLevelName() const override; @@ -80,6 +78,6 @@ namespace armarx::armem public: - std::map<std::string, CoreSegmentPtr> coreSegments; + std::map<std::string, CoreSegment> coreSegments; }; } diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp index 2b5c4a2572ae86f26c74de482d31a4e959608bfa..28010d765fd024f0b83442082d9daf636e7274e0 100644 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp @@ -41,14 +41,18 @@ namespace armarx::armem bool ProviderSegment::equalsDeep(const ProviderSegment& other) const { + if (size() != other.size()) + { + return false; + } for (const auto& [key, value] : entities) { - if (not(other.hasEntity(key))) + if (not other.hasEntity(key)) { return false; } - if (not(value->equalsDeep(other.getEntity(key)))) + if (not value.equalsDeep(other.getEntity(key))) { return false; } @@ -77,7 +81,7 @@ namespace armarx::armem other.entities.clear(); for (const auto& [name, entity] : this->entities) { - other.addEntity(entity->copy(withData)); + other.addEntity(entity.copy(withData)); } } @@ -97,8 +101,7 @@ namespace armarx::armem auto it = this->entities.find(name); if (it != entities.end()) { - ARMARX_CHECK_NOT_NULL(it->second); - return *it->second; + return it->second; } else { @@ -126,7 +129,7 @@ namespace armarx::armem } else { - entity = it->second.get(); + entity = &it->second; } // Update entity. return entity->update(update); @@ -134,20 +137,19 @@ namespace armarx::armem Entity& ProviderSegment::addEntity(const std::string& name) { - return addEntity(std::make_unique<Entity>(name)); + return addEntity(Entity(name)); } Entity& ProviderSegment::addEntity(const Entity& entity) { - return addEntity(std::make_unique<Entity>(entity)); + return addEntity(Entity(entity)); } - Entity& ProviderSegment::addEntity(EntityPtr&& entity) + Entity& ProviderSegment::addEntity(Entity&& entity) { - auto it = entities.emplace(entity->name(), std::move(entity)).first; - ARMARX_CHECK_NOT_NULL(it->second); - it->second->id().setProviderSegmentID(id()); - return *it->second; + auto it = entities.emplace(entity.name(), std::move(entity)).first; + it->second.id().setProviderSegmentID(id()); + return it->second; } void ProviderSegment::setMaxHistorySize(long maxSize) @@ -155,7 +157,7 @@ namespace armarx::armem this->maxHistorySize = maxSize; for (auto& [name, entity] : entities) { - entity->setMaxHistorySize(maxSize); + entity.setMaxHistorySize(maxSize); } } diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/ProviderSegment.h index 86162b657b75dcbd754532d531b92b1941a9d783..ecfa53be218d27cb9978009196aec93f68f475c7 100644 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/ProviderSegment.h @@ -1,7 +1,6 @@ #pragma once #include <map> -#include <memory> #include <string> #include "Entity.h" @@ -11,15 +10,12 @@ namespace armarx::armem { - class ProviderSegment; - using ProviderSegmentPtr = std::unique_ptr<ProviderSegment>; - /** * @brief Data of a provider segment containing multiple entities. */ - class ProviderSegment : public detail::TypedEntityContainer<EntityPtr, ProviderSegment> + class ProviderSegment : public detail::TypedEntityContainer<Entity, ProviderSegment> { - using Base = detail::TypedEntityContainer<EntityPtr, ProviderSegment>; + using Base = detail::TypedEntityContainer<Entity, ProviderSegment>; public: @@ -31,7 +27,6 @@ namespace armarx::armem ProviderSegment(const ProviderSegment& other); ProviderSegment& operator=(const ProviderSegment& other); - bool equalsDeep(const ProviderSegment& other) const; ~ProviderSegment() override; @@ -63,7 +58,7 @@ namespace armarx::armem /// Copy and insert an entity. Entity& addEntity(const Entity& entity); /// Move and insert an entity. - Entity& addEntity(EntityPtr&& entity); + Entity& addEntity(Entity&& entity); /** @@ -74,6 +69,8 @@ namespace armarx::armem void setMaxHistorySize(long maxSize); + bool equalsDeep(const ProviderSegment& other) const; + // MemoryItem interface public: @@ -89,7 +86,7 @@ namespace armarx::armem public: /// The entities. - std::map<std::string, EntityPtr> entities; + std::map<std::string, Entity> entities; /** * @brief Maximum size of entity histories. diff --git a/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h b/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h index 7112aa7e9df5eab19042a9434d4b2d58fac7abe0..6b64db1dd03b00c856d62a6bc0d12139010c0ecf 100644 --- a/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h +++ b/source/RobotAPI/libraries/armem/core/detail/MemoryContainer.h @@ -1,7 +1,5 @@ #pragma once -#include <memory> - #include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include "../../error.h" @@ -22,7 +20,6 @@ namespace armarx::armem::detail public: using ContainerT = _ContainerT; using Derived = _Derived; - using DerivedPtr = std::unique_ptr<Derived>; public: @@ -70,25 +67,25 @@ namespace armarx::armem::detail // Copying - virtual DerivedPtr copy(bool withData = true) const + virtual Derived copy(bool withData = true) const { auto cast = dynamic_cast<const Derived*>(this); ARMARX_CHECK_NOT_NULL(cast); - DerivedPtr other = std::make_unique<Derived>(); - this->_copySelf(*other); - this->_copyElements(*other, withData); + Derived other; + this->_copySelf(other); + this->_copyElements(other, withData); return other; } /// Make a copy not containing any elements. - virtual DerivedPtr copyEmpty() const + virtual Derived copyEmpty() const { auto cast = dynamic_cast<const Derived*>(this); ARMARX_CHECK_NOT_NULL(cast); - DerivedPtr other = std::make_unique<Derived>(); - this->_copySelf(*other); + Derived other; + this->_copySelf(other); return other; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp index 5ddfd4be948e71e364bc349195589a29a60a85a4..66d9fa03be22c6b0305244a2d6943242373ada09 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp @@ -133,7 +133,7 @@ namespace armarx::armem::io return ret; } - EntityInstancePtr DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const + EntityInstance DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const { if (!std::filesystem::is_regular_file(p)) { @@ -147,13 +147,13 @@ namespace armarx::armem::io return unwrapData(dictdata); } - EntityInstancePtr DiskReader::unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr& dataWrapped) const + EntityInstance DiskReader::unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr& dataWrapped) const { - EntityInstancePtr e = EntityInstancePtr(new EntityInstance()); - EntityInstanceMetadata& metadata = e->metadata(); + EntityInstance e; + EntityInstanceMetadata& metadata = e.metadata(); aron::datanavigator::AronDictDataNavigatorPtr data = aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_DATA_FIELD)); - e->setData(data); + e.setData(data); // not used right now //aron::datanavigator::AronLongDataNavigatorPtr timeWrapped = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD)); diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h index 3f3b29594ebf86c67e7a897e3346cfbec4e92765..bdd7d1451f2a2747fe9d33baccea0f31607a9f75 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h @@ -49,10 +49,10 @@ namespace armarx::armem::io FileSystemLookupMemoryManager readMemoryStructureFromDisk(); FileSystemLookupMemoryManager readMemoryStructureFromDisk(const std::string&); - EntityInstancePtr readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; + EntityInstance readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; protected: - EntityInstancePtr unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr&) const; + EntityInstance unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr&) const; virtual aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::AronTypeNavigatorPtr&) const = 0; virtual aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp index d9c1fab74202809d14c5be790d67f173a5414aab..1d1822c6b611ec324d6fa259913f1c22f70ce67e 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp @@ -71,7 +71,7 @@ namespace armarx::armem::io { MemoryID storeCore(id); storeCore.coreSegmentName = coreKey; - DiskWriterReturnInformation other = writeOnDisk(storeCore, *coreSegment); + DiskWriterReturnInformation other = writeOnDisk(storeCore, coreSegment); ret.append(other); } return ret; @@ -105,7 +105,7 @@ namespace armarx::armem::io { MemoryID storeProvider(id); storeProvider.providerSegmentName = providerKey; - DiskWriterReturnInformation other = writeOnDisk(storeProvider, *providerSegment); + DiskWriterReturnInformation other = writeOnDisk(storeProvider, providerSegment); ret.append(other); } return ret; @@ -139,7 +139,7 @@ namespace armarx::armem::io { MemoryID storeEntity(id); storeEntity.entityName = entityKey; - DiskWriterReturnInformation other = writeOnDisk(storeEntity, *entity); + DiskWriterReturnInformation other = writeOnDisk(storeEntity, entity); ret.append(other); } return ret; @@ -162,7 +162,7 @@ namespace armarx::armem::io { MemoryID storeSnapshot(id); storeSnapshot.timestamp = ts; - DiskWriterReturnInformation other = writeOnDisk(storeSnapshot, *snapshot); + DiskWriterReturnInformation other = writeOnDisk(storeSnapshot, snapshot); ret.append(other); } return ret; @@ -182,13 +182,13 @@ namespace armarx::armem::io } int i = 0; - for (const auto& instance : s.instances) + for (const EntityInstance& instance : s.instances) { MemoryID storeInstance(id); storeInstance.instanceIndex = i; std::filesystem::path entityElementPath = rootPath / (storeInstance.str() + getEntityInstanceSuffix()); - std::string val = getDataAsString(wrapData(*instance)); + std::string val = getDataAsString(wrapData(instance)); if (filePathExists(entityElementPath)) { diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp index 2cde6249d434bbe3e72bb13dc827c0519119f57e..608ed1ad0d9326697a1ade4f956177cbf71a8a35 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp @@ -51,19 +51,19 @@ namespace armarx::armem::io updateInternalMemory(loaded); } - std::map<std::string, MemoryPtr> MemoryFileSystemStorage::getInternalMemoryAsRealMemory() const + std::map<std::string, Memory> MemoryFileSystemStorage::getInternalMemoryAsRealMemory() const { - std::map<std::string, MemoryPtr> ret; + std::map<std::string, Memory> ret; for (const auto& [memoryName, memory] : internalMemory.memoryLookupTable) { - MemoryPtr m = MemoryPtr(new Memory(memoryName)); + Memory m = Memory(memoryName); MemoryID id; id.memoryName = memoryName; for (const auto& [coreKey, coreSegment] : memory) { - CoreSegment& c = m->addCoreSegment(coreKey); + CoreSegment& c = m.addCoreSegment(coreKey); id.coreSegmentName = coreKey; for (const auto& [providerKey, providerSegment] : coreSegment) { @@ -80,8 +80,7 @@ namespace armarx::armem::io for (unsigned int i = 0; i < entitySnapshot.size(); ++i) { id.instanceIndex = static_cast<int>(i); - EntityInstancePtr instance = reader->readSingleInstanceFromDisk(entitySnapshot[i]); - es.instances.push_back(std::move(instance)); + es.instances.push_back(reader->readSingleInstanceFromDisk(entitySnapshot[i])); } } } diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h index e5ececd24baa108e493ec902f402c214458dee9d..4c9a4f1b8b0977bd40680eb42a132b1866526c3c 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h @@ -63,9 +63,9 @@ namespace armarx::armem::io void updateInternalMemoryFromFileSystem(); - EntityPtr getEntityFromFileSystem(const MemoryID&); + Entity getEntityFromFileSystem(const MemoryID&); - std::map<std::string, MemoryPtr> getInternalMemoryAsRealMemory() const; + std::map<std::string, Memory> getInternalMemoryAsRealMemory() const; std::string getInternalMemoryAsString(); private: diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp index 6cb5a5d0fde4d1a3a5de7cc821fd1b425120d906..e6c51d554b185570c0de0b3e658a363bc0abac1b 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp @@ -24,7 +24,7 @@ namespace armarx::armem::server } for (const auto& [name, coreSegment] : memory.coreSegments) { - group.addChild(makeGroupBox(*coreSegment)); + group.addChild(makeGroupBox(coreSegment)); } return group; @@ -43,7 +43,7 @@ namespace armarx::armem::server } for (const auto& [name, providerSegment] : coreSegment.providerSegments) { - group.addChild(makeGroupBox(*providerSegment)); + group.addChild(makeGroupBox(providerSegment)); } return group; @@ -62,7 +62,7 @@ namespace armarx::armem::server } for (const auto& [name, entity] : providerSegment.entities) { - group.addChild(makeGroupBox(*entity)); + group.addChild(makeGroupBox(entity)); } return group; @@ -83,7 +83,7 @@ namespace armarx::armem::server { for (const auto& [time, snapshot] : entity.history) { - group.addChild(makeGroupBox(*snapshot)); + group.addChild(makeGroupBox(snapshot)); } } else @@ -94,13 +94,13 @@ namespace armarx::armem::server --rit; for (int i = 0; i < margin; ++i, ++it) { - group.addChild(makeGroupBox(*it->second)); + group.addChild(makeGroupBox(it->second)); --rit; } group.addChild(Label("...")); for (; rit != entity.history.end(); ++rit) { - group.addChild(makeGroupBox(*rit->second)); + group.addChild(makeGroupBox(rit->second)); } } group.setCollapsed(true); @@ -120,9 +120,9 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("instances"))); } - for (const auto& instance : snapshot.instances) + for (const EntityInstance& instance : snapshot.instances) { - group.addChild(makeGroupBox(*instance)); + group.addChild(makeGroupBox(instance)); } group.setCollapsed(true); diff --git a/source/RobotAPI/libraries/armem/server/query_proc/BaseQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/BaseQueryProcessor.h index ef5d60e1c920cd8e98674129bc4dbb6edc239771..7858b2b7120fb5239c375d0c398334d8381c538b 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/BaseQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/BaseQueryProcessor.h @@ -3,7 +3,6 @@ #include <RobotAPI/interface/armem/query.h> #include <RobotAPI/libraries/armem/core/DataMode.h> -#include <RobotAPI/libraries/armem/core/Memory.h> namespace armarx::armem::query_proc @@ -17,7 +16,6 @@ namespace armarx::armem::query_proc { public: - using DataPtrT = std::unique_ptr<DataT>; using QueryPtrT = ::IceInternal::Handle<QueryT>; using QuerySeqT = std::vector<QueryPtrT>; @@ -32,21 +30,21 @@ namespace armarx::armem::query_proc {} - DataPtrT process(const QueryT& query, const DataT& data) const + DataT process(const QueryT& query, const DataT& data) const { - DataPtrT result = data.copyEmpty(); - this->process(*result, query, data); + DataT result = data.copyEmpty(); + this->process(result, query, data); return result; } - DataPtrT process(const QueryPtrT& query, const DataPtrT& data) const + DataT process(const QueryPtrT& query, const DataT& data) const { return this->process(*query, *data); } - DataPtrT process(const QuerySeqT& queries, const DataT& data) const + DataT process(const QuerySeqT& queries, const DataT& data) const { - DataPtrT result = data.copyEmpty(); - this->process(*result, queries, data); + DataT result = data.copyEmpty(); + this->process(result, queries, data); return result; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp index 42dceaa7e71b4e0bf20e8dee5dd0c653c7f130a0..e4a960086cfd5df277cc7784050953b1eaafacd3 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.cpp @@ -38,7 +38,7 @@ namespace armarx::armem::query_proc { for (const auto& [name, providerSegment] : coreSegment.providerSegments) { - result.addProviderSegment(providerSegmentProcessor.process(query.providerSegmentQueries, *providerSegment)); + result.addProviderSegment(providerSegmentProcessor.process(query.providerSegmentQueries, providerSegment)); } } @@ -62,18 +62,18 @@ namespace armarx::armem::query_proc std::regex regex(query.providerSegmentNameRegex); for (const auto& [name, providerSegment] : coreSegment.providerSegments) { - if (std::regex_search(providerSegment->name(), regex)) + if (std::regex_search(providerSegment.name(), regex)) { - result.addProviderSegment(providerSegmentProcessor.process(query.providerSegmentQueries, *providerSegment)); + result.addProviderSegment(providerSegmentProcessor.process(query.providerSegmentQueries, providerSegment)); } } } - data::CoreSegmentPtr CoreSegmentQueryProcessor::processToIce( + data::CoreSegment CoreSegmentQueryProcessor::processToIce( const data::query::CoreSegmentQuery& query, const CoreSegment& coreSegment) const { - return toIce<data::CoreSegmentPtr>(process(query, coreSegment)); + return toIce<data::CoreSegment>(process(query, coreSegment)); } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h index f9babf13c56ccde05d5d76c3378fedfeb1c82b7e..0bc3756be0a3bc4900027783e917b1906da0b438 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/CoreSegmentQueryProcessor.h @@ -33,7 +33,7 @@ namespace armarx::armem::query_proc void process(CoreSegment& result, const data::query::core::Regex& query, const CoreSegment& coreSegment) const; - data::CoreSegmentPtr processToIce(const data::query::CoreSegmentQuery& query, const CoreSegment& coreSegment) const; + data::CoreSegment processToIce(const data::query::CoreSegmentQuery& query, const CoreSegment& coreSegment) const; private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp index 897b1411a579a4f641784ae7bc2b290a47b5088f..f23ab7265f7c18fad7927ae8d24f6f18f4c06ec1 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.cpp @@ -41,7 +41,7 @@ namespace armarx::armem::query_proc for (const auto& [time, snapshot] : entity) { - addResultSnapshot(result, *snapshot, query); + addResultSnapshot(result, snapshot); } } @@ -51,7 +51,7 @@ namespace armarx::armem::query_proc { try { - addResultSnapshot(result, entity.getLatestSnapshot(), query); + addResultSnapshot(result, entity.getLatestSnapshot()); } catch (const armem::error::EntityHistoryEmpty&) { @@ -63,7 +63,7 @@ namespace armarx::armem::query_proc Time time = fromIce<Time>(query.timestamp); try { - addResultSnapshot(result, entity.getSnapshot(time), query); + addResultSnapshot(result, entity.getSnapshot(time)); } catch (const armem::error::MissingEntry&) { @@ -85,7 +85,7 @@ namespace armarx::armem::query_proc size_t num = last - first + 1; // +1 to make last inclusive for (size_t i = 0; i < num; ++i, ++it) { - addResultSnapshot(result, it, query); + addResultSnapshot(result, it); } } } @@ -110,13 +110,13 @@ namespace armarx::armem::query_proc for (auto it = begin; it != end && it != entity.history.end(); ++it) { - addResultSnapshot(result, it, query); + addResultSnapshot(result, it); } } - data::EntityPtr EntityQueryProcessor::processToIce(const data::query::EntityQuery& query, const Entity& entity) const + data::Entity EntityQueryProcessor::processToIce(const data::query::EntityQuery& query, const Entity& entity) const { - return toIce<data::EntityPtr>(process(query, entity)); + return toIce<data::Entity>(process(query, entity)); } size_t EntityQueryProcessor::negativeIndexSemantics(long index, size_t size) @@ -132,13 +132,12 @@ namespace armarx::armem::query_proc } } - void EntityQueryProcessor::addResultSnapshot( - Entity& result, Entity::ContainerT::const_iterator it, const data::query::EntityQuery& query) const + void EntityQueryProcessor::addResultSnapshot(Entity& result, Entity::ContainerT::const_iterator it) const { - addResultSnapshot(result, *it->second, query); + addResultSnapshot(result, it->second); } - void EntityQueryProcessor::addResultSnapshot(Entity& result, const EntitySnapshot& snapshot, const data::query::EntityQuery& query) const + void EntityQueryProcessor::addResultSnapshot(Entity& result, const EntitySnapshot& snapshot) const { bool withData = (dataMode == DataMode::WithData); result.addSnapshot(snapshot.copy(withData)); diff --git a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h index ae919425b342158f0e7a24f99e1326f4166c8d23..44f26354b40c9020f73265573e977bbd1af0442e 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/EntityQueryProcessor.h @@ -35,15 +35,15 @@ namespace armarx::armem::query_proc const data::query::EntityQuery& query) const; - data::EntityPtr processToIce(const data::query::EntityQuery& query, const Entity& entity) const; + data::Entity processToIce(const data::query::EntityQuery& query, const Entity& entity) const; static size_t negativeIndexSemantics(long index, size_t size); private: - void addResultSnapshot(Entity& result, Entity::ContainerT::const_iterator it, const data::query::EntityQuery& query) const; - void addResultSnapshot(Entity& result, const EntitySnapshot& snapshot, const data::query::EntityQuery& query) const; + void addResultSnapshot(Entity& result, Entity::ContainerT::const_iterator it) const; + void addResultSnapshot(Entity& result, const EntitySnapshot& snapshot) const; }; diff --git a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp index 0ba5b5ae72cb088f7032df12858c428d259b7c77..be2353ec92c37480925faddee4cd688d2ad4cdef 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/MemoryQueryProcessor.cpp @@ -52,17 +52,15 @@ namespace armarx::armem::query_proc } - void MemoryQueryProcessor::process(Memory& result, - const data::query::memory::All& query, const Memory& memory) const + void MemoryQueryProcessor::process(Memory& result, const data::query::memory::All& query, const Memory& memory) const { for (const auto& [name, coreSegment] : memory.coreSegments) { - result.addCoreSegment(coreSegmentProcessor.process(query.coreSegmentQueries, *coreSegment)); + result.addCoreSegment(coreSegmentProcessor.process(query.coreSegmentQueries, coreSegment)); } } - void MemoryQueryProcessor::process(Memory& result, - const data::query::memory::Single& query, const Memory& memory) const + void MemoryQueryProcessor::process(Memory& result, const data::query::memory::Single& query, const Memory& memory) const { try { @@ -75,15 +73,14 @@ namespace armarx::armem::query_proc } } - void MemoryQueryProcessor::process(Memory& result, - const data::query::memory::Regex& query, const Memory& memory) const + void MemoryQueryProcessor::process(Memory& result, const data::query::memory::Regex& query, const Memory& memory) const { std::regex regex(query.coreSegmentNameRegex); for (const auto& [name, coreSegment] : memory.coreSegments) { - if (std::regex_search(coreSegment->name(), regex)) + if (std::regex_search(coreSegment.name(), regex)) { - result.addCoreSegment(coreSegmentProcessor.process(query.coreSegmentQueries, *coreSegment)); + result.addCoreSegment(coreSegmentProcessor.process(query.coreSegmentQueries, coreSegment)); } } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp index 425ddfa06214d6adbcb12a89cc9e62a6fe0f8318..9b7069fe84ca7a8acb0459c7d320068d9903a178 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.cpp @@ -38,7 +38,7 @@ namespace armarx::armem::query_proc { for (const auto& [name, entity] : providerSegment.entities) { - result.addEntity(std::move(*entityProcessor.process(query.entityQueries, *entity))); + result.addEntity(entityProcessor.process(query.entityQueries, entity)); } } @@ -48,7 +48,7 @@ namespace armarx::armem::query_proc try { const Entity& entity = providerSegment.getEntity(query.entityName); - result.addEntity(std::move(*entityProcessor.process(query.entityQueries, entity))); + result.addEntity(entityProcessor.process(query.entityQueries, entity)); } catch (const error::MissingEntry&) { @@ -62,18 +62,18 @@ namespace armarx::armem::query_proc std::regex regex(query.entityNameRegex); for (const auto& [name, entity] : providerSegment.entities) { - if (std::regex_search(entity->name(), regex)) + if (std::regex_search(entity.name(), regex)) { - result.addEntity(std::move(*entityProcessor.process(query.entityQueries, *entity))); + result.addEntity(entityProcessor.process(query.entityQueries, entity)); } } } - data::ProviderSegmentPtr ProviderSegmentQueryProcessor::processToIce( + data::ProviderSegment ProviderSegmentQueryProcessor::processToIce( const data::query::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const { - return toIce<data::ProviderSegmentPtr>(process(query, providerSegment)); + return toIce<data::ProviderSegment>(process(query, providerSegment)); } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h index a9f17ddde09e119ee798bb1aecd97fdeb15f0a72..6d65a54e975adefa2421bacca1575e64f51ab5a4 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/ProviderSegmentQueryProcessor.h @@ -33,7 +33,7 @@ namespace armarx::armem::query_proc void process(ProviderSegment& result, const data::query::provider::Regex& query, const ProviderSegment& providerSegment) const; - data::ProviderSegmentPtr processToIce(const data::query::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const; + data::ProviderSegment processToIce(const data::query::ProviderSegmentQuery& query, const ProviderSegment& providerSegment) const; private: diff --git a/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp index 6b5b22d46fb68fbb950ff4d95c5e15dc158731cb..e139931d828f69494299b69fb4bd87677fd40465 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemIceConversionsTest.cpp @@ -35,66 +35,31 @@ namespace armem = armarx::armem; namespace aron = armarx::aron; -BOOST_AUTO_TEST_CASE(test_entity_no_nullptr) +BOOST_AUTO_TEST_CASE(test_entity) { - armem::EntityPtr entity = std::make_unique<armem::Entity>("entity"); + armem::Entity entity("entity"); std::vector<armem::Time> expectedTimestamps; armem::EntitySnapshot snapshot; snapshot.time() = armem::Time::milliSeconds(100); expectedTimestamps.push_back(snapshot.time()); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); snapshot.time() = armem::Time::milliSeconds(300); expectedTimestamps.push_back(snapshot.time()); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); - armem::data::Entity ice; + armem::data::EntityPtr ice; armem::toIce(ice, entity); - armem::EntityPtr entityOut; + armem::Entity entityOut; armem::fromIce(ice, entityOut); - BOOST_CHECK_NE(entityOut.get(), nullptr); - BOOST_CHECK_EQUAL(entityOut->history.size(), entity->history.size()); + BOOST_CHECK_EQUAL(entityOut.history.size(), entity.history.size()); - std::vector<armem::Time> timestamps = entityOut->getTimestamps(); + std::vector<armem::Time> timestamps = entityOut.getTimestamps(); BOOST_CHECK_EQUAL_COLLECTIONS(timestamps.begin(), timestamps.end(), expectedTimestamps.begin(), expectedTimestamps.end()); - - for (const auto& [time, snapshot] : entity->history) - { - BOOST_CHECK_NE(snapshot.get(), nullptr); - } } - -BOOST_AUTO_TEST_CASE(test_entity_with_nullptr) -{ - armem::EntityPtr entity = std::make_unique<armem::Entity>("entity"); - - std::vector<armem::Time> expectedTimestamps; - entity->history.emplace(expectedTimestamps.emplace_back(armem::Time::milliSeconds(100)), - nullptr); - entity->history.emplace(expectedTimestamps.emplace_back(armem::Time::milliSeconds(300)), - nullptr); - - armem::data::Entity ice; - armem::toIce(ice, entity); - - armem::EntityPtr entityOut; - armem::fromIce(ice, entityOut); - - BOOST_CHECK_NE(entityOut.get(), nullptr); - BOOST_CHECK_EQUAL(entityOut->history.size(), entity->history.size()); - - std::vector<armem::Time> timestamps = entityOut->getTimestamps(); - BOOST_CHECK_EQUAL_COLLECTIONS(timestamps.begin(), timestamps.end(), - expectedTimestamps.begin(), expectedTimestamps.end()); - - for (const auto& [time, snapshot] : entity->history) - { - BOOST_CHECK_EQUAL(snapshot.get(), nullptr); - } -} diff --git a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp index 576891400bfca1ab565238eda003f6f2c6e78aed..b1ee718d3cb48ed9c06f1cd12543ff434b3a8cbd 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp @@ -44,12 +44,12 @@ BOOST_AUTO_TEST_CASE(test_memory_heavy_setup_and_export) aron::AronRandomizer r; std::string memoryName = "TestMemory"; - armem::MemoryPtr memory = std::make_unique<armem::Memory>(memoryName); - BOOST_CHECK_EQUAL(memory->name(), memoryName); + armem::Memory memory(memoryName); + BOOST_CHECK_EQUAL(memory.name(), memoryName); - armem::CoreSegment& coreSegment = memory->addCoreSegment("TestCoreSegment"); + armem::CoreSegment& coreSegment = memory.addCoreSegment("TestCoreSegment"); BOOST_CHECK_EQUAL(coreSegment.name(), "TestCoreSegment"); - BOOST_CHECK(memory->hasCoreSegment(coreSegment.name())); + BOOST_CHECK(memory.hasCoreSegment(coreSegment.name())); armem::ProviderSegment& providerSegment = coreSegment.addProviderSegment("TestProvider"); BOOST_CHECK_EQUAL(providerSegment.name(), "TestProvider"); @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(test_memory_heavy_setup_and_export) // export memory std::string storagePath = "/tmp/MemoryExport"; // important! without tailing / armem::io::MemoryFileSystemStorage mfs(storagePath, true); - mfs.writeOnDisk(*memory); + mfs.writeOnDisk(memory); std::string mfs_str = mfs.getInternalMemoryAsString(); @@ -102,8 +102,8 @@ BOOST_AUTO_TEST_CASE(test_memory_heavy_setup_and_export) std::cout << mfs2_str << std::endl; BOOST_CHECK_EQUAL(mfs_str == mfs_str, true); - //std::map<std::string, armem::MemoryPtr> loaded_memories = mfs.getInternalMemoryAsRealMemory(); - //armem::MemoryPtr& memory2 = loaded_memories["Memory"]; + //std::map<std::string, armem::Memory> loaded_memories = mfs.getInternalMemoryAsRealMemory(); + //armem::Memory& memory2 = loaded_memories["Memory"]; //BOOST_CHECK_EQUAL(memory->equalsDeep(*memory2), true); } diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index 1c6492665b0cb6cb3ded023f902d71cc4286e22f..6983c42dceef954ad5857c8a26626332666bf86b 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -81,18 +81,18 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) { armem::EntityUpdate update; - armem::MemoryPtr memory = std::make_unique<armem::Memory>("Memory"); - BOOST_CHECK_EQUAL(memory->name(), "Memory"); + armem::Memory memory("Memory"); + BOOST_CHECK_EQUAL(memory.name(), "Memory"); { update.entityID = armem::MemoryID::fromString("OtherMemory/SomeSegment"); - BOOST_CHECK_THROW(memory->update(update), armem::error::ContainerNameMismatch); + BOOST_CHECK_THROW(memory.update(update), armem::error::ContainerNameMismatch); update.entityID = armem::MemoryID::fromString("Memory/MissingSegment"); - BOOST_CHECK_THROW(memory->update(update), armem::error::MissingEntry); + BOOST_CHECK_THROW(memory.update(update), armem::error::MissingEntry); } - armem::CoreSegment& coreSegment = memory->addCoreSegment("ImageRGB"); + armem::CoreSegment& coreSegment = memory.addCoreSegment("ImageRGB"); BOOST_CHECK_EQUAL(coreSegment.name(), "ImageRGB"); - BOOST_CHECK(memory->hasCoreSegment(coreSegment.name())); + BOOST_CHECK(memory.hasCoreSegment(coreSegment.name())); { update.entityID = armem::MemoryID::fromString("Memory/OtherCoreSegment"); BOOST_CHECK_THROW(coreSegment.update(update), armem::error::ContainerNameMismatch); @@ -129,18 +129,18 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_CHECK_EQUAL(entity.history.size(), 1); BOOST_CHECK_EQUAL(entity.history.count(update.timeCreated), 1); - armem::EntitySnapshot* entitySnapshot = entity.history.at(update.timeCreated).get(); - BOOST_CHECK_EQUAL(entitySnapshot->instances.size(), update.instancesData.size()); + armem::EntitySnapshot& entitySnapshot = entity.history.at(update.timeCreated); + BOOST_CHECK_EQUAL(entitySnapshot.instances.size(), update.instancesData.size()); // Another update (on memory). update.instancesData = { std::make_shared<aron::datanavigator::AronDictDataNavigator>() }; update.timeCreated = armem::Time::milliSeconds(2000); - memory->update(update); + memory.update(update); BOOST_CHECK_EQUAL(entity.history.size(), 2); BOOST_CHECK_EQUAL(entity.history.count(update.timeCreated), 1); - BOOST_CHECK_EQUAL(entity.history.at(update.timeCreated)->instances.size(), update.instancesData.size()); + BOOST_CHECK_EQUAL(entity.history.at(update.timeCreated).instances.size(), update.instancesData.size()); // A third update (on entity). @@ -155,44 +155,44 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) BOOST_AUTO_TEST_CASE(test_history_size_in_entity) { - armem::EntityPtr entity = std::make_unique<armem::Entity>("entity"); + armem::Entity entity("entity"); armem::EntityUpdate update; - update.entityID.entityName = entity->name(); + update.entityID.entityName = entity.name(); // With unlimited history. update.timeCreated = armem::Time::milliSeconds(1000); - entity->update(update); + entity.update(update); update.timeCreated = armem::Time::milliSeconds(2000); - entity->update(update); + entity.update(update); update.timeCreated = armem::Time::milliSeconds(3000); - entity->update(update); - BOOST_CHECK_EQUAL(entity->history.size(), 3); + entity.update(update); + BOOST_CHECK_EQUAL(entity.history.size(), 3); // Now with maximum history size. - entity->setMaxHistorySize(2); - BOOST_CHECK_EQUAL(entity->history.size(), 2); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(1000)), 0); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(2000)), 1); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(3000)), 1); + entity.setMaxHistorySize(2); + BOOST_CHECK_EQUAL(entity.history.size(), 2); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(1000)), 0); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(2000)), 1); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(3000)), 1); update.timeCreated = armem::Time::milliSeconds(4000); - entity->update(update); - BOOST_CHECK_EQUAL(entity->history.size(), 2); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(2000)), 0); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(3000)), 1); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(4000)), 1); + entity.update(update); + BOOST_CHECK_EQUAL(entity.history.size(), 2); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(2000)), 0); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(3000)), 1); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(4000)), 1); // Disable maximum history size. - entity->setMaxHistorySize(-1); + entity.setMaxHistorySize(-1); update.timeCreated = armem::Time::milliSeconds(5000); - entity->update(update); - BOOST_CHECK_EQUAL(entity->history.size(), 3); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(3000)), 1); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(4000)), 1); - BOOST_CHECK_EQUAL(entity->history.count(armem::Time::milliSeconds(5000)), 1); + entity.update(update); + BOOST_CHECK_EQUAL(entity.history.size(), 3); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(3000)), 1); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(4000)), 1); + BOOST_CHECK_EQUAL(entity.history.count(armem::Time::milliSeconds(5000)), 1); } diff --git a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp index e8bfa3601922d998d392bcdc9cdf8cb080d41976..05615f8beb56a7948861f5934010e78553b5aff2 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp @@ -50,29 +50,29 @@ namespace ArMemQueryTest struct Fixture { - armem::EntityPtr entity; + armem::Entity entity; armem::query_proc::EntityQueryProcessor processor; query::EntityQueryPtr entityQuery; - std::vector<armem::EntityPtr> results; + std::vector<armem::Entity> results; Fixture() { - entity = std::make_unique<armem::Entity>("entity"); + entity = armem::Entity("entity"); armem::EntitySnapshot snapshot; snapshot.time() = armem::Time::microSeconds(1000); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); snapshot.time() = armem::Time::microSeconds(2000); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); snapshot.time() = armem::Time::microSeconds(3000); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); snapshot.time() = armem::Time::microSeconds(4000); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); snapshot.time() = armem::Time::microSeconds(5000); - entity->addSnapshot(snapshot); + entity.addSnapshot(snapshot); } ~Fixture() { @@ -84,8 +84,8 @@ namespace ArMemQueryTest { entityQuery = new QueryT(query); - results.emplace_back(processor.process(query, *entity)); - results.emplace_back(processor.process(*entityQuery, *entity)); + results.emplace_back(processor.process(query, entity)); + results.emplace_back(processor.process(*entityQuery, entity)); } }; @@ -98,11 +98,11 @@ BOOST_FIXTURE_TEST_SUITE(ArMemQueryTest, ArMemQueryTest::Fixture) BOOST_AUTO_TEST_CASE(test_entity_UnknownQueryType) { - BOOST_CHECK_THROW(processor.process(UnknownEntityQuery(), *entity), armem::error::UnknownQueryType); + BOOST_CHECK_THROW(processor.process(UnknownEntityQuery(), entity), armem::error::UnknownQueryType); std::string msg; try { - processor.process(UnknownEntityQuery(), *entity); + processor.process(UnknownEntityQuery(), entity); } catch (const armem::error::UnknownQueryType& e) { @@ -121,10 +121,10 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_latest) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); - BOOST_CHECK_EQUAL(result->history.size(), 1); - BOOST_CHECK_EQUAL(result->history.begin()->second->time(), entity->getLatestSnapshot().time()); - BOOST_CHECK_NE(result->history.begin()->second.get(), entity->history.rbegin()->second.get()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); + BOOST_CHECK_EQUAL(result.history.size(), 1); + BOOST_CHECK_EQUAL(result.history.begin()->second.time(), entity.getLatestSnapshot().time()); + BOOST_CHECK_NE(&result.history.begin()->second, &entity.history.rbegin()->second); } } @@ -136,9 +136,9 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_existing) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); - BOOST_CHECK_EQUAL(result->history.size(), 1); - BOOST_CHECK_EQUAL(result->history.begin()->second->time(), armem::Time::microSeconds(3000)); + BOOST_CHECK_EQUAL(result.name(), entity.name()); + BOOST_CHECK_EQUAL(result.history.size(), 1); + BOOST_CHECK_EQUAL(result.history.begin()->second.time(), armem::Time::microSeconds(3000)); } } @@ -150,8 +150,8 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_non_existing) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); - BOOST_CHECK_EQUAL(result->history.size(), 0); + BOOST_CHECK_EQUAL(result.name(), entity.name()); + BOOST_CHECK_EQUAL(result.history.size(), 0); } } @@ -163,14 +163,14 @@ BOOST_AUTO_TEST_CASE(test_entity_All) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); - BOOST_CHECK_EQUAL(result->history.size(), entity->history.size()); - for (auto it = result->history.begin(), jt = entity->history.begin(); - it != result->history.end(); ++it, ++jt) + BOOST_CHECK_EQUAL(result.name(), entity.name()); + BOOST_CHECK_EQUAL(result.history.size(), entity.history.size()); + auto jt = entity.history.begin(); + for (auto it = result.history.begin(); it != result.history.end(); ++it, ++jt) { BOOST_CHECK_EQUAL(it->first, jt->first); - BOOST_CHECK_EQUAL(it->second->time(), jt->second->time()); - BOOST_CHECK_NE(it->second.get(), jt->second.get()); + BOOST_CHECK_EQUAL(it->second.time(), jt->second.time()); + BOOST_CHECK_NE(&it->second, &jt->second); } } } @@ -184,11 +184,11 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_slice) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 2); + BOOST_CHECK_EQUAL(result.history.size(), 2); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); std::vector<armem::Time> expected { armem::Time::microSeconds(2000), armem::Time::microSeconds(3000) @@ -205,11 +205,11 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_exact) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 3); + BOOST_CHECK_EQUAL(result.history.size(), 3); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); std::vector<armem::Time> expected { armem::Time::microSeconds(2000), armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) @@ -226,12 +226,12 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_all) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), entity->history.size()); + BOOST_CHECK_EQUAL(result.history.size(), entity.history.size()); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); - std::vector<armem::Time> expected = simox::alg::get_keys(entity->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); + std::vector<armem::Time> expected = simox::alg::get_keys(entity.history); BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } } @@ -245,9 +245,9 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_empty) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 0); + BOOST_CHECK_EQUAL(result.history.size(), 0); } } @@ -259,11 +259,11 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_from_start) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 2); + BOOST_CHECK_EQUAL(result.history.size(), 2); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); std::vector<armem::Time> expected { armem::Time::microSeconds(1000), armem::Time::microSeconds(2000) @@ -280,11 +280,11 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_to_end) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 3); + BOOST_CHECK_EQUAL(result.history.size(), 3); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); std::vector<armem::Time> expected { armem::Time::microSeconds(3000), armem::Time::microSeconds(4000), armem::Time::microSeconds(5000) @@ -329,12 +329,12 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_all_default) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), entity->history.size()); + BOOST_CHECK_EQUAL(result.history.size(), entity.history.size()); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); - std::vector<armem::Time> expected = simox::alg::get_keys(entity->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); + std::vector<armem::Time> expected = simox::alg::get_keys(entity.history); BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } @@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_all_default) BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) { - BOOST_REQUIRE_EQUAL(entity->size(), 5); + BOOST_REQUIRE_EQUAL(entity.size(), 5); addResults(query::entity::IndexRange{ 1, 3 }); // => [1, 2, 3] addResults(query::entity::IndexRange{ 1, -2 }); // 5 - 2 = 3 addResults(query::entity::IndexRange{ -4, 3 }); // 5 - 4 = 1 @@ -352,11 +352,11 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 3); + BOOST_CHECK_EQUAL(result.history.size(), 3); - std::vector<armem::Time> times = simox::alg::get_keys(result->history); + std::vector<armem::Time> times = simox::alg::get_keys(result.history); std::vector<armem::Time> expected { armem::Time::microSeconds(2000), armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) @@ -368,21 +368,21 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) BOOST_AUTO_TEST_CASE(test_entity_IndexRange_empty) { - BOOST_REQUIRE_EQUAL(entity->size(), 5); + BOOST_REQUIRE_EQUAL(entity.size(), 5); addResults(query::entity::IndexRange{ 1, 0 }); addResults(query::entity::IndexRange{ 2, 1 }); addResults(query::entity::IndexRange{ 5, 3 }); - addResults(query::entity::IndexRange{ 4, -3 }); // 5-3 = 2 - addResults(query::entity::IndexRange{ 3, -3 }); - addResults(query::entity::IndexRange{ 1, -5 }); + addResults(query::entity::IndexRange{ 4, -3 }); // 5-3 = 2 + addResults(query::entity::IndexRange{ 3, -3 }); + addResults(query::entity::IndexRange{ 1, -5 }); BOOST_REQUIRE_GT(results.size(), 0); for (const auto& result : results) { - BOOST_CHECK_EQUAL(result->name(), entity->name()); + BOOST_CHECK_EQUAL(result.name(), entity.name()); - BOOST_CHECK_EQUAL(result->history.size(), 0); + BOOST_CHECK_EQUAL(result.history.size(), 0); } } diff --git a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp b/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp index ad6bfc10f5e4c2a3e2e4041c0abda50f74b9055e..cbea351b288a5f766326dbe6857752d5d6aa093d 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp @@ -45,11 +45,11 @@ namespace armarx::armem::gui memoryBuilder.setExpand(true); memoryBuilder.setMakeItemFn([this](const std::string & name, const Memory * memory) { - return makeItem(name, memory); + return makeItem(name, *memory); }); memoryBuilder.setUpdateItemFn([this](const std::string&, const Memory * memory, QTreeWidgetItem * memoryItem) { - updateContainerItem(memory, memoryItem); + updateContainerItem(*memory, memoryItem); if (memoryItem) { updateChildren(*memory, memoryItem); @@ -59,96 +59,74 @@ namespace armarx::armem::gui coreSegmentBuilder.setExpand(true); - coreSegmentBuilder.setMakeItemFn([this](const std::string & name, const CoreSegmentPtr & coreSeg) + coreSegmentBuilder.setMakeItemFn([this](const std::string & name, const CoreSegment & coreSeg) { - return makeItem(name, coreSeg.get()); + return makeItem(name, coreSeg); }); - coreSegmentBuilder.setUpdateItemFn([this](const std::string&, const CoreSegmentPtr & coreSeg, QTreeWidgetItem * coreSegItem) + coreSegmentBuilder.setUpdateItemFn([this](const std::string&, const CoreSegment & coreSeg, QTreeWidgetItem * coreSegItem) { - updateTypedContainerItem(coreSeg.get(), coreSegItem); - if (coreSeg) - { - updateChildren(*coreSeg, coreSegItem); - } + updateTypedContainerItem(coreSeg, coreSegItem); + updateChildren(coreSeg, coreSegItem); return true; }); provSegmentBuilder.setExpand(true); - provSegmentBuilder.setMakeItemFn([this](const std::string & name, const ProviderSegmentPtr & provSeg) + provSegmentBuilder.setMakeItemFn([this](const std::string & name, const ProviderSegment & provSeg) { - return makeItem(name, provSeg.get()); + return makeItem(name, provSeg); }); - provSegmentBuilder.setUpdateItemFn([this](const std::string&, const ProviderSegmentPtr & provSeg, QTreeWidgetItem * provSegItem) + provSegmentBuilder.setUpdateItemFn([this](const std::string&, const ProviderSegment & provSeg, QTreeWidgetItem * provSegItem) { - updateTypedContainerItem(provSeg.get(), provSegItem); - if (provSeg) - { - updateChildren(*provSeg, provSegItem); - } + updateTypedContainerItem(provSeg, provSegItem); + updateChildren(provSeg, provSegItem); return true; }); // entityBuilder.setExpand(true); - entityBuilder.setMakeItemFn([this](const std::string & name, const EntityPtr & entity) + entityBuilder.setMakeItemFn([this](const std::string & name, const Entity & entity) { - return makeItem(name, entity.get()); + return makeItem(name, entity); }); - entityBuilder.setUpdateItemFn([this](const std::string&, const EntityPtr & entity, QTreeWidgetItem * entityItem) + entityBuilder.setUpdateItemFn([this](const std::string&, const Entity & entity, QTreeWidgetItem * entityItem) { - updateContainerItem(entity.get(), entityItem); - if (entity) - { - updateChildren(*entity, entityItem); - } + updateContainerItem(entity, entityItem); + updateChildren(entity, entityItem); return true; }); - snapshotBuilder.setMakeItemFn([this](const armem::Time & time, const EntitySnapshotPtr & snapshot) + snapshotBuilder.setMakeItemFn([this](const armem::Time & time, const EntitySnapshot & snapshot) { - QTreeWidgetItem* item = makeItem(toDateTimeMilliSeconds(time), snapshot.get()); - item->setData(int(Columns::KEY), Qt::ItemDataRole::UserRole, QVariant(static_cast<qlonglong>(snapshot->time().toMicroSeconds()))); + QTreeWidgetItem* item = makeItem(toDateTimeMilliSeconds(time), snapshot); + item->setData(int(Columns::KEY), Qt::ItemDataRole::UserRole, QVariant(static_cast<qlonglong>(snapshot.time().toMicroSeconds()))); return item; }); snapshotBuilder.setCompareFn([](const auto & pair, QTreeWidgetItem * item) { - const EntitySnapshotPtr& snapshot = pair.second; - return armarx::detail::compare(static_cast<qlonglong>(snapshot->time().toMicroSeconds()), + const EntitySnapshot& snapshot = pair.second; + return armarx::detail::compare(static_cast<qlonglong>(snapshot.time().toMicroSeconds()), item->data(int(Columns::KEY), Qt::ItemDataRole::UserRole).toLongLong()); }); - snapshotBuilder.setUpdateItemFn([this](const armem::Time&, const EntitySnapshotPtr & snapshot, QTreeWidgetItem * snapshotItem) + snapshotBuilder.setUpdateItemFn([this](const armem::Time&, const EntitySnapshot & snapshot, QTreeWidgetItem * snapshotItem) { - updateContainerItem(snapshot.get(), snapshotItem); - if (snapshot) - { - updateChildren(*snapshot, snapshotItem); - } - else - { - while (snapshotItem->childCount() > 0) - { - delete snapshotItem->takeChild(snapshotItem->childCount() - 1); - } - } + updateContainerItem(snapshot, snapshotItem); + updateChildren(snapshot, snapshotItem); return true; }); - instanceBuilder.setMakeItemFn([this](const EntityInstancePtr & instance) + instanceBuilder.setMakeItemFn([this](const EntityInstance & instance) { - QTreeWidgetItem* item = makeItem("", instance.get()); - item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(instance->id().str())); + QTreeWidgetItem* item = makeItem("", instance); + item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(instance.id().str())); return item; }); - instanceBuilder.setCompareFn([](const EntityInstancePtr & lhs, QTreeWidgetItem * rhsItem) + instanceBuilder.setCompareFn([](const EntityInstance & lhs, QTreeWidgetItem * rhsItem) { - return armarx::detail::compare(lhs->index(), rhsItem->text(0).toInt()); + return armarx::detail::compare(lhs.index(), rhsItem->text(0).toInt()); }); - instanceBuilder.setUpdateItemFn([this](const EntityInstancePtr & instance, QTreeWidgetItem * instanceItem) + instanceBuilder.setUpdateItemFn([this](const EntityInstance & instance, QTreeWidgetItem * instanceItem) { - updateItemItem(instance.get(), instanceItem); - if (instance) - { - updateChildren(*instance, instanceItem); - } + updateItemItem(instance, instanceItem); + updateChildren(instance, instanceItem); return true; }); @@ -235,70 +213,50 @@ namespace armarx::armem::gui } } - QTreeWidgetItem* MemoryTreeWidget::makeItem(const std::string& key, const armem::detail::MemoryItem* memoryItem) + QTreeWidgetItem* MemoryTreeWidget::makeItem(const std::string& key, const armem::detail::MemoryItem& memoryItem) { + (void) key; QStringList columns; - if (memoryItem) - { - columns.insert(int(Columns::KEY), QString::fromStdString(memoryItem->getKeyString())); - columns.insert(int(Columns::SIZE), ""); - columns.insert(int(Columns::TYPE), ""); - columns.insert(int(Columns::LEVEL), QString::fromStdString(simox::alg::capitalize_words(memoryItem->getLevelName()))); - columns.insert(int(Columns::ID), QString::fromStdString(memoryItem->id().str())); - } - else - { - columns.insert(int(Columns::KEY), QString::fromStdString(key)); - columns.insert(int(Columns::ID), QString::fromStdString("(null)")); - } + columns.insert(int(Columns::KEY), QString::fromStdString(memoryItem.getKeyString())); + columns.insert(int(Columns::SIZE), ""); + columns.insert(int(Columns::TYPE), ""); + columns.insert(int(Columns::LEVEL), QString::fromStdString(simox::alg::capitalize_words(memoryItem.getLevelName()))); + columns.insert(int(Columns::ID), QString::fromStdString(memoryItem.id().str())); QTreeWidgetItem* item = new QTreeWidgetItem(columns); - if (memoryItem) - { - item->setData(int(Columns::LEVEL), Qt::UserRole, QString::fromStdString(memoryItem->getLevelName())); - } + item->setData(int(Columns::LEVEL), Qt::UserRole, QString::fromStdString(memoryItem.getLevelName())); item->setTextAlignment(int(Columns::SIZE), Qt::AlignRight); return item; } - void MemoryTreeWidget::updateItemItem(const armem::detail::MemoryItem* level, QTreeWidgetItem* item) + void MemoryTreeWidget::updateItemItem(const armem::detail::MemoryItem& level, QTreeWidgetItem* item) { (void) level, (void) item; } template <class... T> void MemoryTreeWidget::updateContainerItem( - const armem::detail::MemoryContainer<T...>* container, QTreeWidgetItem* item) + const armem::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item) { updateItemItem(container, item); - if (container) - { - item->setText(int(Columns::SIZE), QString::number(container->size())); - } + item->setText(int(Columns::SIZE), QString::number(container.size())); } template <class... T> void MemoryTreeWidget::updateTypedContainerItem( - const armem::detail::TypedEntityContainer<T...>* container, QTreeWidgetItem* item) + const armem::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item) { updateContainerItem(container, item); - if (container) + std::string typeName; + if (container.aronType()) { - std::string typeName; - if (container->aronType()) - { - auto objectType = aron::typenavigator::AronObjectTypeNavigator::DynamicCast(container->aronType()); - if (objectType != nullptr) - { - typeName = objectType->getName(); - } - } - else - { - typeName = "(no Aron type)"; - } - item->setText(int(Columns::TYPE), QString::fromStdString(typeName)); + typeName = container.aronType()->getName(); + } + else + { + typeName = "(no Aron type)"; } + item->setText(int(Columns::TYPE), QString::fromStdString(typeName)); } } diff --git a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h b/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h index 4bb67207ff5921b3bc02cdc3faff1516b43e9066..0aff62014b444997d67d1ce67517f95952cda734 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h +++ b/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h @@ -52,13 +52,13 @@ namespace armarx::armem::gui void updateChildren(const armem::EntityInstance& data, QTreeWidgetItem* parent); - QTreeWidgetItem* makeItem(const std::string& key, const armem::detail::MemoryItem* container); + QTreeWidgetItem* makeItem(const std::string& key, const armem::detail::MemoryItem& container); - void updateItemItem(const armem::detail::MemoryItem* level, QTreeWidgetItem* item); + void updateItemItem(const armem::detail::MemoryItem& level, QTreeWidgetItem* item); template <class... T> - void updateContainerItem(const armem::detail::MemoryContainer<T...>* container, QTreeWidgetItem* item); + void updateContainerItem(const armem::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item); template <class... T> - void updateTypedContainerItem(const armem::detail::TypedEntityContainer<T...>* container, QTreeWidgetItem* item); + void updateTypedContainerItem(const armem::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item); private: @@ -66,11 +66,11 @@ namespace armarx::armem::gui bool instanceIntrospection = false; MapTreeWidgetBuilder<std::string, const Memory*> memoryBuilder; - MapTreeWidgetBuilder<std::string, CoreSegmentPtr> coreSegmentBuilder; - MapTreeWidgetBuilder<std::string, ProviderSegmentPtr> provSegmentBuilder; - MapTreeWidgetBuilder<std::string, EntityPtr> entityBuilder; - MapTreeWidgetBuilder<armem::Time, EntitySnapshotPtr> snapshotBuilder; - TreeWidgetBuilder<std::vector<EntityInstancePtr>> instanceBuilder; + MapTreeWidgetBuilder<std::string, CoreSegment> coreSegmentBuilder; + MapTreeWidgetBuilder<std::string, ProviderSegment> provSegmentBuilder; + MapTreeWidgetBuilder<std::string, Entity> entityBuilder; + MapTreeWidgetBuilder<armem::Time, EntitySnapshot> snapshotBuilder; + TreeWidgetBuilder<std::vector<EntityInstance>> instanceBuilder; enum class Columns