diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h index b6c47abb553cfa2c884fde1f2c13f3245432c387..ab535e4cc14d07f98898565e62d26b8d93396a1a 100644 --- a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h @@ -235,19 +235,20 @@ namespace armarx::armem::base { ARMARX_INFO << "CoreSegment: Merge name '" << m.name() << "' into '" << name() << "'"; - for (const auto& [k, s] : m.container()) + m.forEachProviderSegment([this](const ProviderSegmentT & provSeg) { - if (const auto& it = this->_container.find(k); it != this->_container.end()) + if (auto it = this->_container.find(provSeg.name()); it != this->_container.end()) { // segment already exists - it->second.append(s); + it->second.append(provSeg); } else { - auto wms = this->_container.emplace(k, this->id().withProviderSegmentName(k)); - wms.first->second.append(s); + auto wms = this->_container.emplace(provSeg.name(), this->id().withProviderSegmentName(provSeg.name())); + wms.first->second.append(provSeg); } - } + return true; + }); } /** diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index 6db264e1f6e9be64209307714b2b48ecfd3ac2f7..45499a57a46799ff7f17524d8b16241bc8623533 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -397,20 +397,20 @@ namespace armarx::armem::base { ARMARX_INFO << "Entity: Merge name '" << m.name() << "' into '" << name() << "'"; - for (const auto& [k, s] : m.container()) + m.forEachEntitySnapshot([this](const EntitySnapshotT & snapshot) { - if (const auto& it = this->_container.find(k); it != this->_container.end()) + if (auto it = this->_container.find(snapshot.time()); it != this->_container.end()) { // segment already exists // We assume that a snapshot does not change, so ignore } else { - EntitySnapshotT snapshot { s }; - snapshot.id() = this->id().withTimestamp(k); // update id (e.g. memory name) if necessary - this->_container.insert(std::make_pair(k, std::move(snapshot))); + EntitySnapshotT snapshot { snapshot }; + snapshot.id() = this->id().withTimestamp(snapshot.time()); // update id (e.g. memory name) if necessary + this->_container.insert(std::make_pair(snapshot.time(), std::move(snapshot))); } - } + }); } /** diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h index 72e5cf605c4b75c1b849b1463e3420573da11c3f..b4469c17880b91bf4251c07355e7e432429dbf6e 100644 --- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h @@ -327,9 +327,9 @@ namespace armarx::armem::base { ARMARX_INFO << "Memory: Merge name '" << m.name() << "' into '" << name() << "'"; - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = this->_container.find(k); it != this->_container.end()) + if (auto it = this->_container.find(k); it != this->_container.end()) { // segment already exists it->second.append(s); @@ -380,10 +380,10 @@ namespace armarx::armem::base for (const auto& [ckey, cseg] : this->container()) { ss << " |- Found core seg: " << ckey << "\n"; - for (const auto& [pkey, pseg] : cseg.container()) + for (const auto& [pkey, pseg] : cseg) { ss << " | |- Found prov seg: " << pkey << "\n"; - for (const auto& [ekey, eseg] : pseg.container()) + for (const auto& [ekey, eseg] : pseg) { ss << " | | |- Found entity: " << ekey << "\n"; } diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h index cd7aaa359b789e93b6c2fbd7bf9f714f5d6ae427..cd9e389cb5d13be5c29f57378e2a24701983fd6b 100644 --- a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h @@ -207,9 +207,9 @@ namespace armarx::armem::base { ARMARX_INFO << "ProviderSegment: Merge name '" << m.name() << "' into '" << name() << "'"; - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = this->_container.find(k); it != this->_container.end()) + if (auto it = this->_container.find(k); it != this->_container.end()) { // segment already exists it->second.append(s); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp index b166468d81929da12c8204a6e2df9ab90b994528..b3fb28a54ba7bc034019e65303cab3534ea199a0 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp @@ -80,7 +80,7 @@ namespace armarx::armem::d_ltm for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { it->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp index 5d784a097de4ef68ec2df0bdc1adce94fa737809..daa61bc4a43376b93be40cd7d203c63b80e7f1ef 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp @@ -63,9 +63,9 @@ namespace armarx::armem::d_ltm void Entity::append(const wm::Entity& m) { std::filesystem::create_directories(_fullPath()); - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { // timestamp already exists // We assume that a snapshot does not change, so ignore diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp index ab5b56d2274f78c350818693c269af18f0a4a979..b6f0ff1e0329b5d70ff5a17ac64b155b7de9c113 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp @@ -83,7 +83,7 @@ namespace armarx::armem::d_ltm _container.clear(); int i = 0; - for (const auto& s : m.instances()) + m.forEachEntityInstance([this, &i](wm::EntityInstance & s) { try { @@ -92,12 +92,14 @@ namespace armarx::armem::d_ltm catch (...) { ARMARX_WARNING << GetHandledExceptionString(); - continue;; + return true; } auto& wms = _container.emplace_back(id().withInstanceIndex(i++)); wms.path = path; wms.setTo(s); - } + + return true; + }); } } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp index 0fb6fba92b2ebc116787bffba2d7ed5bc743227b..97871505a80cf4d91bbe88f0eea0c3da27c5c8d5 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp @@ -65,9 +65,9 @@ namespace armarx::armem::d_ltm void Memory::append(const wm::Memory& m) { std::filesystem::create_directories(_fullPath()); - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { it->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp index 620e819f6b1fc05d4aeadc285edb087f5ea0e119..577417542795ec2edfdbccdf9f5e52d98e0cf976 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp @@ -95,9 +95,9 @@ namespace armarx::armem::d_ltm TypeIO::writeAronType(_aronType, _fullPath()); - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { it->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp index d47dc46cb63c5266edc8b9e8457c1fb4b75a4527..6adea4d681cb681d91017f6ac923f2ad215f1e47 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/CoreSegment.cpp @@ -41,7 +41,7 @@ namespace armarx::armem::ltm std::string k = i.providerSegmentName; - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { throw error::ArMemError("Somehow after clearing the (core) container a key k = " + k + " was found. Do you have double entries in mongodb?"); } @@ -62,24 +62,23 @@ namespace armarx::armem::ltm mongocxx::database db = client[dbsettings.database]; mongocxx::collection coll = db[id().str()]; - for (const auto& [k, s] : m.container()) + m.forEachProviderSegment([this, &coll](const wm::ProviderSegment & provSeg) { - if (const auto& it = _container.find(k); it != _container.end()) + auto it = _container.find(provSeg.name()); + if (it == _container.end()) { - it->second.append(s); - } - else - { - auto builder = bsoncxx::builder::stream::document{}; + bsoncxx::builder::stream::document builder; bsoncxx::document::value foreign_key = builder - << "foreign_key" << s.id().withProviderSegmentName(k).str() + << "foreign_key" << provSeg.id().str() << bsoncxx::builder::stream::finalize; coll.insert_one(foreign_key.view()); - auto wms = _container.emplace(k, id().withProviderSegmentName(k)); - wms.first->second.dbsettings = dbsettings; - wms.first->second.append(s); + it = _container.emplace(provSeg.name(), id().withProviderSegmentName(provSeg.name())).first; + it->second.dbsettings = dbsettings; } - } + it->second.append(provSeg); + + return true; + }); } } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp index bccb79c9d1d162a6c67a4f80c57b58b04425863e..99a8808c92787b5f976696a219fcc18c50341b34 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp @@ -36,7 +36,7 @@ namespace armarx::armem::ltm auto k = armem::Time::microSeconds(json.at("timestamp")); //ARMARX_INFO << "Entity: Found timestamp: " << std::to_string(k.toMicroSeconds()); - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { throw error::ArMemError("Somehow after clearing the (entity) container a key k = " + std::to_string(k.toMicroSeconds()) + " was found. Do you have double entries in mongodb?"); } @@ -58,9 +58,9 @@ namespace armarx::armem::ltm mongocxx::database db = client[dbsettings.database]; mongocxx::collection coll = db[id().str()]; - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { // timestamp already exists // We assume that a snapshot does not change, so ignore diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp index aae8a6d3258c94a27e9f931838a44c8d1b6426aa..f3dd8a59507d361eb22309c665e07c089255fa3c 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/EntitySnapshot.cpp @@ -85,7 +85,7 @@ namespace armarx::armem::ltm auto array_builder = bsoncxx::builder::basic::array{}; int i = 0; - for (const auto& s : m.container()) + for (const auto& s : m) { auto wms = _container.emplace_back(id().withInstanceIndex(i++)); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp index 2f424f9fbb5c54390f01684eb0632357246c1633..9b81f00a8679735d3ded28a1f2799027331a544e 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp @@ -1,11 +1,13 @@ #include "Memory.h" -#include <ArmarXCore/core/time/TimeUtil.h> -#include <ArmarXCore/core/logging/Logging.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - #include "error.h" +#include <ArmarXCore/core/application/properties/PluginAll.h> +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/time/TimeUtil.h> + namespace armarx::armem::ltm { @@ -37,6 +39,7 @@ namespace armarx::armem::ltm Memory& Memory::operator=(const Memory& other) { Base::operator=(other); + dbsettings = other.dbsettings; alwaysTransferSettings = other.alwaysTransferSettings; periodicTransferSettings = other.periodicTransferSettings; @@ -161,7 +164,7 @@ namespace armarx::armem::ltm std::string k = i.coreSegmentName; - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { throw error::ArMemError("Somehow after clearing the (memory) container a key k = " + k + " was found. Do you have double entries in mongodb?"); } @@ -199,9 +202,9 @@ namespace armarx::armem::ltm mongocxx::database db = client[dbsettings.database]; mongocxx::collection coll = db[id().str()]; - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { // TODO check if foreign key exists it->second.append(s); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h index fa68ebe47f5b219f0d7b5f2588bf0b6039766224..73a9f0fc3598d1e208c44a46c75028781beb9723 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h @@ -10,8 +10,8 @@ #include "../workingmemory/Memory.h" // Properties -#include <ArmarXCore/core/application/properties/PluginAll.h> -#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> +#include <ArmarXCore/core/application/properties/forward_declarations.h> + namespace armarx::armem::ltm { @@ -25,9 +25,6 @@ namespace armarx::armem::ltm public: - using Base::MemoryBase; - using Base::operator=; - struct TransferSettings { bool enabled = false; @@ -56,6 +53,10 @@ namespace armarx::armem::ltm }; + public: + + using Base::MemoryBase; + Memory(const Memory& other); Memory(Memory&& other); Memory& operator=(const Memory& other); diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp index 5fcf4a1351e34f257e773c2ac32e9d4eb64c5401..878adc8d76c0685753a4409b6ac0229e22b303a0 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/ProviderSegment.cpp @@ -39,7 +39,7 @@ namespace armarx::armem::ltm std::string k = i.entityName; - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { throw error::ArMemError("Somehow after clearing the (provvider) container a key k = " + k + " was found. Do you have double entries in mongodb?"); } @@ -60,9 +60,9 @@ namespace armarx::armem::ltm mongocxx::database db = client[dbsettings.database]; mongocxx::collection coll = db[id().str()]; - for (const auto& [k, s] : m.container()) + for (const auto& [k, s] : m) { - if (const auto& it = _container.find(k); it != _container.end()) + if (auto it = _container.find(k); it != _container.end()) { it->second.append(s); } diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/mongodb/MongoDBConnectionManager.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/mongodb/MongoDBConnectionManager.cpp index 6ad44836900e04765790a9a3c2a19881e1288656..fd2bbbb6ccb8aee93c4d343b818dc55872f7838a 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/mongodb/MongoDBConnectionManager.cpp +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/mongodb/MongoDBConnectionManager.cpp @@ -20,7 +20,7 @@ namespace armarx::armem::ltm initialize_if(); const auto uri_str = settings.uri(); - const auto& it = Connections.find(uri_str); + auto it = Connections.find(uri_str); if (it == Connections.end()) { mongocxx::uri uri(uri_str); @@ -43,7 +43,7 @@ namespace armarx::armem::ltm if (!force) { const auto uri_str = settings.uri(); - const auto& it = Connections.find(uri_str); + auto it = Connections.find(uri_str); if (it != Connections.end()) { auto admin = it->second["admin"]; @@ -70,7 +70,7 @@ namespace armarx::armem::ltm initialize_if(); const auto uri_str = settings.uri(); - const auto& it = Connections.find(uri_str); + auto it = Connections.find(uri_str); return it != Connections.end(); } } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp index bfc049995a6553e53a78be00294cb9c162e80a0d..71cdd52ea8bfdae9f08f02e595a9940bdf8bb514 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/ice_conversions.cpp @@ -1,5 +1,6 @@ #include "ice_conversions.h" + namespace armarx::armem { void toIce(armarx::armem::data::EntityInstanceMetadata& ice, const armarx::armem::wm::EntityInstanceMetadata& metadata) @@ -43,29 +44,46 @@ namespace armarx::armem { detail::toIceItem(ice, snapshot); - toIce(ice.instances, snapshot.instances()); + ice.instances.clear(); + snapshot.forEachEntityInstance([&ice](const wm::EntityInstance & instance) + { + toIce(ice.instances.emplace_back(), instance); + return true; + }); } void fromIce(const data::EntitySnapshot& ice, wm::EntitySnapshot& snapshot) { detail::fromIceItem(ice, snapshot); - fromIce(ice.instances, snapshot.instances()); + snapshot.clear(); + for (const data::EntityInstancePtr& instance : ice.instances) + { + snapshot.addInstance(fromIce<wm::EntityInstance>(instance)); + } } void toIce(data::Entity& ice, const wm::Entity& entity) { detail::toIceItem(ice, entity); - toIce(ice.history, entity.history()); + ice.history.clear(); + entity.forEachEntitySnapshot([&ice](const wm::EntitySnapshot & snapshot) + { + toIce(ice.history[toIce<long>(snapshot.time())], snapshot); + return true; + }); } void fromIce(const data::Entity& ice, wm::Entity& entity) { detail::fromIceItem(ice, entity); - fromIce(ice.history, entity.history()); + entity.clear(); + for (const auto& [key, snapshot] : ice.history) + { + entity.addSnapshot(fromIce<wm::EntitySnapshot>(snapshot)); + } } - void toIce(data::ProviderSegment& ice, const wm::ProviderSegment& providerSegment) { detail::toIceItem(ice, providerSegment); @@ -75,7 +93,14 @@ namespace armarx::armem ice.aronType = providerSegment.aronType()->toAronPtr(); } ARMARX_CHECK(!providerSegment.aronType() || ice.aronType); - toIce(ice.entities, providerSegment.entities()); + + // toIce(ice.entities, providerSegment.entities()); + ice.entities.clear(); + providerSegment.forEachEntity([&ice](const wm::Entity & entity) + { + toIce(ice.entities[entity.name()], entity); + return true; + }); } void fromIce(const data::ProviderSegment& ice, wm::ProviderSegment& providerSegment) { @@ -86,7 +111,13 @@ namespace armarx::armem providerSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); } ARMARX_CHECK(!providerSegment.aronType() || ice.aronType); - fromIce(ice.entities, providerSegment.entities()); + + // fromIce(ice.entities, providerSegment.entities()); + providerSegment.clear(); + for (const auto& [key, entity] : ice.entities) + { + providerSegment.addEntity(fromIce<wm::Entity>(entity)); + } } void toIce(data::CoreSegment& ice, const wm::CoreSegment& coreSegment) @@ -98,7 +129,14 @@ namespace armarx::armem ice.aronType = coreSegment.aronType()->toAronPtr(); } ARMARX_CHECK(!coreSegment.aronType() || ice.aronType); - toIce(ice.providerSegments, coreSegment.providerSegments()); + + // toIce(ice.providerSegments, coreSegment.providerSegments()); + ice.providerSegments.clear(); + coreSegment.forEachProviderSegment([&ice](const wm::ProviderSegment & providerSegment) + { + toIce(ice.providerSegments[providerSegment.name()], providerSegment); + return true; + }); } void fromIce(const data::CoreSegment& ice, wm::CoreSegment& coreSegment) { @@ -109,20 +147,37 @@ namespace armarx::armem coreSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(aron::typenavigator::Navigator::FromAronType(ice.aronType)); } ARMARX_CHECK(!coreSegment.aronType() || ice.aronType); - fromIce(ice.providerSegments, coreSegment.providerSegments()); + + // fromIce(ice.providerSegments, coreSegment.providerSegments()); + coreSegment.clear(); + for (const auto& [key, providerSegment] : ice.providerSegments) + { + coreSegment.addProviderSegment(fromIce<wm::ProviderSegment>(providerSegment)); + } } void toIce(data::Memory& ice, const wm::Memory& memory) { detail::toIceItem(ice, memory); - toIce(ice.coreSegments, memory.coreSegments()); + // toIce(ice.coreSegments, memory.coreSegments()); + ice.coreSegments.clear(); + memory.forEachCoreSegment([&ice](const wm::CoreSegment & coreSegment) + { + toIce(ice.coreSegments[coreSegment.name()], coreSegment); + return true; + }); } void fromIce(const data::Memory& ice, wm::Memory& memory) { detail::fromIceItem(ice, memory); - fromIce(ice.coreSegments, memory.coreSegments()); + // fromIce(ice.coreSegments, memory.coreSegments()); + memory.clear(); + for (const auto& [key, coreSegment] : ice.coreSegments) + { + memory.addCoreSegment(fromIce<wm::CoreSegment>(coreSegment)); + } } } diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index c0ff3cf64be957add85e5f4902da46a34e94e4fb..d30c49232cf84ec9d192d23c4fcaa041df8f2e57 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -162,6 +162,11 @@ namespace ArMemMemoryTest { return ""; } + + void fill() + { + _container = std::vector<int> { -1, 2, -3 }; + } }; struct MemoryContainerCtorOpTestFixture { @@ -171,7 +176,7 @@ namespace ArMemMemoryTest MemoryContainerCtorOpTestFixture() { - cont.container() = std::vector<int> { -1, 2, -3 }; + cont.fill(); BOOST_CHECK_EQUAL(cont.id(), id); BOOST_CHECK_EQUAL(cont.size(), 3); } @@ -244,17 +249,6 @@ 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 @@ -459,21 +453,25 @@ struct InstanceCopyMoveCtorsOpsTest : public CopyMoveCtorsOpsTestBase } void testMoveCtor() override { + T copy { in }; T out { std::move(in) }; BOOST_CHECK_EQUAL(in.id(), idMoved); BOOST_CHECK_EQUAL(out.id(), id); + CustomChecks<T>::checkEqual(out, copy); CustomChecks<T>::checkMoved(in); } void testMoveOp() override { + T copy { in }; T out; out = std::move(in); BOOST_CHECK_EQUAL(in.id(), idMoved); BOOST_CHECK_EQUAL(out.id(), id); + CustomChecks<T>::checkEqual(out, copy); CustomChecks<T>::checkMoved(in); } }; @@ -492,7 +490,12 @@ struct CopyMoveCtorsOpsTest : public CopyMoveCtorsOpsTestBase void reset() override { in = T {id}; - add_element(in.container()); + { + armem::EntityUpdate update; + update.entityID = armem::MemoryID("A", "B", "C", "D", armem::Time::seconds(1), 0); + update.timeCreated = update.entityID.timestamp; + in.update(update); + } BOOST_CHECK_EQUAL(in.id(), id); BOOST_CHECK_EQUAL(in.size(), 1); @@ -652,17 +655,17 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) update.timeCreated = armem::Time::milliSeconds(1000); BOOST_CHECK_NO_THROW(providerSegment.update(update)); - BOOST_CHECK_EQUAL(providerSegment.entities().size(), 1); + BOOST_CHECK_EQUAL(providerSegment.size(), 1); BOOST_CHECK(providerSegment.hasEntity("image")); BOOST_CHECK(!providerSegment.hasEntity("other_image")); armem::wm::Entity& entity = providerSegment.getEntity("image"); BOOST_CHECK_EQUAL(entity.name(), "image"); - BOOST_CHECK_EQUAL(entity.history().size(), 1); + BOOST_CHECK_EQUAL(entity.size(), 1); BOOST_CHECK_EQUAL(entity.history().count(update.timeCreated), 1); armem::wm::EntitySnapshot& entitySnapshot = entity.history().at(update.timeCreated); - BOOST_CHECK_EQUAL(entitySnapshot.instances().size(), update.instancesData.size()); + BOOST_CHECK_EQUAL(entitySnapshot.size(), update.instancesData.size()); // Another update (on memory). @@ -670,16 +673,16 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) update.instancesData = { std::make_shared<aron::datanavigator::DictNavigator>() }; update.timeCreated = armem::Time::milliSeconds(2000); memory.update(update); - BOOST_CHECK_EQUAL(entity.history().size(), 2); + BOOST_CHECK_EQUAL(entity.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).size(), update.instancesData.size()); // A third update (on entity). update.instancesData = { std::make_shared<aron::datanavigator::DictNavigator>() }; update.timeCreated = armem::Time::milliSeconds(3000); entity.update(update); - BOOST_CHECK_EQUAL(entity.history().size(), 3); + BOOST_CHECK_EQUAL(entity.size(), 3); } @@ -699,11 +702,11 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_entity) entity.update(update); update.timeCreated = armem::Time::milliSeconds(3000); entity.update(update); - BOOST_CHECK_EQUAL(entity.history().size(), 3); + BOOST_CHECK_EQUAL(entity.size(), 3); // Now with maximum history size. entity.setMaxHistorySize(2); - BOOST_CHECK_EQUAL(entity.history().size(), 2); + BOOST_CHECK_EQUAL(entity.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); @@ -711,7 +714,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_entity) update.timeCreated = armem::Time::milliSeconds(4000); entity.update(update); - BOOST_CHECK_EQUAL(entity.history().size(), 2); + BOOST_CHECK_EQUAL(entity.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); @@ -721,7 +724,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_entity) update.timeCreated = armem::Time::milliSeconds(5000); entity.update(update); - BOOST_CHECK_EQUAL(entity.history().size(), 3); + BOOST_CHECK_EQUAL(entity.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); @@ -753,22 +756,22 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) update.timeCreated = armem::Time::milliSeconds(4000); providerSegment.update(update); - BOOST_CHECK_EQUAL(providerSegment.getEntity("A").history().size(), 3); - BOOST_CHECK_EQUAL(providerSegment.getEntity("B").history().size(), 4); + BOOST_CHECK_EQUAL(providerSegment.getEntity("A").size(), 3); + BOOST_CHECK_EQUAL(providerSegment.getEntity("B").size(), 4); // Employ maximum history size. providerSegment.setMaxHistorySize(3); - BOOST_CHECK_EQUAL(providerSegment.getEntity("A").history().size(), 3); - BOOST_CHECK_EQUAL(providerSegment.getEntity("B").history().size(), 3); + BOOST_CHECK_EQUAL(providerSegment.getEntity("A").size(), 3); + BOOST_CHECK_EQUAL(providerSegment.getEntity("B").size(), 3); providerSegment.setMaxHistorySize(2); - BOOST_CHECK_EQUAL(providerSegment.getEntity("A").history().size(), 2); - BOOST_CHECK_EQUAL(providerSegment.getEntity("B").history().size(), 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("A").size(), 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("B").size(), 2); providerSegment.setMaxHistorySize(3); - BOOST_CHECK_EQUAL(providerSegment.getEntity("A").history().size(), 2); - BOOST_CHECK_EQUAL(providerSegment.getEntity("B").history().size(), 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("A").size(), 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("B").size(), 2); // Add new entity. providerSegment.setMaxHistorySize(2); @@ -784,7 +787,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) // Check correctly inherited history size. BOOST_CHECK_EQUAL(providerSegment.getEntity("C").getMaxHistorySize(), 2); // Check actual history size. - BOOST_CHECK_EQUAL(providerSegment.getEntity("C").history().size(), 2); + BOOST_CHECK_EQUAL(providerSegment.getEntity("C").size(), 2); // Remove maximum. providerSegment.setMaxHistorySize(-1); @@ -795,6 +798,6 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) update.entityID.entityName = name; update.timeCreated = armem::Time::milliSeconds(5000); providerSegment.update(update); - BOOST_CHECK_EQUAL(providerSegment.getEntity(name).history().size(), 3); + BOOST_CHECK_EQUAL(providerSegment.getEntity(name).size(), 3); } } diff --git a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MDBMotions/Segment.cpp b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MDBMotions/Segment.cpp index 8fab7c2c6e113e5ba5eb9b6ba8d250d8fb6fec4f..93bec90cad9283c055f8ebeaa0da98565b5cb3fd 100644 --- a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MDBMotions/Segment.cpp +++ b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MDBMotions/Segment.cpp @@ -8,7 +8,14 @@ // ArmarX #include "MotionConverter.h" + #include <RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h> +#include <RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h> +#include <RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h> + +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> +#include <ArmarXCore/core/application/properties/ProxyPropertyDefinition.h> + namespace armarx::armem::server::motions::mdb {