Skip to content
Snippets Groups Projects
Commit 11d0e8fe authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Update usage of forEach in reader

parent 4269f509
No related branches found
No related tags found
2 merge requests!188ArMem Updates,!185Clean up interfaces and unneeded code in memory core classes
...@@ -242,32 +242,19 @@ namespace armarx::armem::articulated_object ...@@ -242,32 +242,19 @@ namespace armarx::armem::articulated_object
.getCoreSegment(properties.coreInstanceSegmentName); .getCoreSegment(properties.coreInstanceSegmentName);
// clang-format on // clang-format on
for (const auto& [_, providerSegment] : coreSegment.providerSegments()) std::optional<wm::EntityInstance> instance;
coreSegment.forEachInstance([&instance](const wm::EntityInstance & i)
{ {
instance = i;
const auto entities = simox::alg::get_values(providerSegment.entities()); });
if (instance.has_value())
if (entities.empty()) {
{ return robot::convertRobotState(instance.value());
ARMARX_WARNING << "No entity found"; }
continue; else
} {
return std::nullopt;
const auto entitySnapshots = simox::alg::get_values(entities.front().history());
if (entitySnapshots.empty())
{
ARMARX_WARNING << "No entity snapshots found";
continue;
}
// TODO(fabian.reister): check if 0 available
const armem::wm::EntityInstance& instance = entitySnapshots.front().getInstance(0);
return robot::convertRobotState(instance);
} }
return std::nullopt;
} }
...@@ -275,67 +262,43 @@ namespace armarx::armem::articulated_object ...@@ -275,67 +262,43 @@ namespace armarx::armem::articulated_object
Reader::getRobotDescription(const armarx::armem::wm::Memory& memory) const Reader::getRobotDescription(const armarx::armem::wm::Memory& memory) const
{ {
// clang-format off // clang-format off
const armem::wm::CoreSegment& coreSegment = memory const armem::wm::CoreSegment& coreSegment = memory.getCoreSegment(properties.coreClassSegmentName);
.getCoreSegment(properties.coreClassSegmentName);
// clang-format on // clang-format on
for (const auto& [_, providerSegment] : coreSegment.providerSegments()) std::optional<wm::EntityInstance> instance;
coreSegment.forEachInstance([&instance](const wm::EntityInstance & i)
{ {
const auto entities = simox::alg::get_values(providerSegment.entities()); instance = i;
});
if (entities.empty()) if (instance.has_value())
{ {
ARMARX_WARNING << "No entity found"; return convertRobotDescription(instance.value());
continue; }
} else
{
const auto entitySnapshots = simox::alg::get_values(entities.front().history()); return std::nullopt;
if (entitySnapshots.empty())
{
ARMARX_WARNING << "No entity snapshots found";
continue;
}
if (entitySnapshots.front().hasInstance(0))
{
const armem::wm::EntityInstance& instance = entitySnapshots.front().getInstance(0);
return convertRobotDescription(instance);
}
} }
return std::nullopt;
} }
std::vector<robot::RobotDescription> std::vector<robot::RobotDescription>
Reader::getRobotDescriptions(const armarx::armem::wm::Memory& memory) const Reader::getRobotDescriptions(const armarx::armem::wm::Memory& memory) const
{ {
std::vector<robot::RobotDescription> descriptions;
const armem::wm::CoreSegment& coreSegment = const armem::wm::CoreSegment& coreSegment =
memory.getCoreSegment(properties.coreClassSegmentName); memory.getCoreSegment(properties.coreClassSegmentName);
for (const auto& [providerName, providerSegment] : coreSegment.providerSegments()) std::vector<robot::RobotDescription> descriptions;
coreSegment.forEachEntity([&descriptions](const wm::Entity & entity)
{ {
for (const auto& [name, entity] : providerSegment.entities()) if (not entity.empty())
{ {
if (entity.empty()) const auto robotDescription = convertRobotDescription(entity.getFirstSnapshot().getInstance(0));
{
ARMARX_WARNING << "No entity found";
continue;
}
const auto entitySnapshots = simox::alg::get_values(entity.history());
const armem::wm::EntityInstance& instance = entitySnapshots.front().getInstance(0);
const auto robotDescription = convertRobotDescription(instance);
if (robotDescription) if (robotDescription)
{ {
descriptions.push_back(*robotDescription); descriptions.push_back(*robotDescription);
} }
} }
} });
return descriptions; return descriptions;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment