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

Add getLatestInstance() methods

parent 1be35e35
No related branches found
No related tags found
1 merge request!188ArMem Updates
......@@ -340,6 +340,31 @@ namespace armarx::armem::base
}
auto* findLatestInstance(int instanceIndex = 0)
{
auto* snapshot = this->findLatestSnapshot();
return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
}
const auto* findLatestInstance(int instanceIndex = 0) const
{
auto* snapshot = this->findLatestSnapshot();
return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
}
#if 0 // Do not offer this yet.
auto* findLatestInstanceData(int instanceIndex = 0)
{
auto* instance = this->findLatestInstance(instanceIndex);
return instance ? &instance->data() : nullptr;
}
const auto* findLatestInstanceData(int instanceIndex = 0) const
{
auto* instance = this->findLatestInstance(instanceIndex);
return instance ? &instance->data() : nullptr;
}
#endif
// ITERATION
/**
......
......@@ -150,12 +150,12 @@ namespace armarx::armem::base::detail
// More elaborate cases
auto* findLatestEntitySnapshot(const MemoryID& entityID)
auto* findLatestSnapshot(const MemoryID& entityID)
{
auto* entity = derived<DerivedT>(this).findEntity(entityID);
return entity ? entity->findLatestSnapshot() : nullptr;
}
const auto* findLatestEntitySnapshot(const MemoryID& entityID) const
const auto* findLatestSnapshot(const MemoryID& entityID) const
{
auto* entity = derived<DerivedT>(this).findEntity(entityID);
return entity ? entity->findLatestSnapshot() : nullptr;
......@@ -163,12 +163,12 @@ namespace armarx::armem::base::detail
auto* findLatestInstance(const MemoryID& entityID, int instanceIndex = 0)
{
auto* snapshot = derived<DerivedT>(this).findLatestEntitySnapshot(entityID);
auto* snapshot = derived<DerivedT>(this).findLatestSnapshot(entityID);
return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
}
const auto* findLatestInstance(const MemoryID& entityID, int instanceIndex = 0) const
{
auto* snapshot = derived<DerivedT>(this).findLatestEntitySnapshot(entityID);
auto* snapshot = derived<DerivedT>(this).findLatestSnapshot(entityID);
return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
}
......
......@@ -13,9 +13,74 @@ namespace armarx::armem::wm::detail
using base::detail::derived;
template <class AronDtoT>
std::optional<AronDtoT>
getInstanceDataAs(aron::datanavigator::DictNavigatorPtr data)
{
if (data)
{
AronDtoT aron;
aron.fromAron(data);
return aron;
}
else
{
return std::nullopt;
}
}
template <class DerivedT>
struct FindInstanceDataMixinForSnapshot
{
aron::datanavigator::DictNavigatorPtr
findInstanceData(int instanceIndex = 0) const
{
const auto* instance = derived<DerivedT>(this).findInstance(instanceIndex);
return instance ? instance->data() : nullptr;
}
template <class AronDtoT>
std::optional<AronDtoT>
findInstanceDataAs(int instanceIndex = 0) const
{
return getInstanceDataAs<AronDtoT>(derived<DerivedT>(this).findInstanceData(instanceIndex));
}
};
template <class DerivedT>
struct FindInstanceDataMixinForEntity
{
aron::datanavigator::DictNavigatorPtr
findLatestInstanceData(int instanceIndex = 0) const
{
const auto* instance = derived<DerivedT>(this).findLatestInstance(instanceIndex);
return instance ? instance->data() : nullptr;
}
template <class AronDtoT>
std::optional<AronDtoT>
findLatestInstanceDataAs(int instanceIndex = 0) const
{
return getInstanceDataAs<AronDtoT>(derived<DerivedT>(this).findLatestInstanceData(instanceIndex));
}
};
template <class DerivedT>
struct FindInstanceDataMixin
{
aron::datanavigator::DictNavigatorPtr
findLatestInstanceData(const MemoryID& entityID, int instanceIndex = 0) const
{
......@@ -23,21 +88,11 @@ namespace armarx::armem::wm::detail
return instance ? instance->data() : nullptr;
}
template <class AronDtoT>
std::optional<AronDtoT>
findLatestInstanceDataAs(const MemoryID& entityID, int instanceIndex = 0) const
{
if (aron::datanavigator::DictNavigatorPtr data = derived<DerivedT>(this).findLatestInstanceData(entityID, instanceIndex))
{
AronDtoT aron;
aron.fromAron(data);
return aron;
}
else
{
return std::nullopt;
}
return getInstanceDataAs<AronDtoT>(derived<DerivedT>(this).findLatestInstanceData(entityID, instanceIndex));
}
};
......
......@@ -47,6 +47,7 @@ namespace armarx::armem::wm
/// @see base::EntitySnapshotBase
class EntitySnapshot :
public base::EntitySnapshotBase<EntityInstance, EntitySnapshot>
, public detail::FindInstanceDataMixinForSnapshot<EntitySnapshot>
{
public:
......@@ -58,7 +59,7 @@ namespace armarx::armem::wm
/// @see base::EntityBase
class Entity :
public base::EntityBase<EntitySnapshot, Entity>
, public detail::FindInstanceDataMixin<Entity>
, public detail::FindInstanceDataMixinForEntity<Entity>
{
public:
......
......@@ -29,7 +29,7 @@ namespace armarx::armem::server::wm
class Entity :
public base::EntityBase<EntitySnapshot, Entity>
, public detail::MaxHistorySize
, public armem::wm::detail::FindInstanceDataMixin<Entity>
, public armem::wm::detail::FindInstanceDataMixinForEntity<Entity>
{
public:
......
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