data_lookup_mixins.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 
8 
10 {
12 
13  template <class AronDtoT>
14  std::optional<AronDtoT>
16  {
17  if (data)
18  {
19  AronDtoT aron;
20  aron.fromAron(data);
21  return aron;
22  }
23  else
24  {
25  return std::nullopt;
26  }
27  }
28 
29  template <class DerivedT>
31  {
32 
34  findInstanceData(int instanceIndex = 0) const
35  {
36  const auto* instance = derived<DerivedT>(this).findInstance(instanceIndex);
37  return instance ? instance->data() : nullptr;
38  }
39 
40  template <class AronDtoT>
41  std::optional<AronDtoT>
42  findInstanceDataAs(int instanceIndex = 0) const
43  {
44  return getInstanceDataAs<AronDtoT>(
45  derived<DerivedT>(this).findInstanceData(instanceIndex));
46  }
47  };
48 
49  template <class DerivedT>
51  {
52 
54  findLatestInstanceData(int instanceIndex = 0) const
55  {
56  const auto* instance = derived<DerivedT>(this).findLatestInstance(instanceIndex);
57  return instance ? instance->data() : nullptr;
58  }
59 
60  template <class AronDtoT>
61  std::optional<AronDtoT>
62  findLatestInstanceDataAs(int instanceIndex = 0) const
63  {
64  return getInstanceDataAs<AronDtoT>(
65  derived<DerivedT>(this).findLatestInstanceData(instanceIndex));
66  }
67  };
68 
69  template <class DerivedT>
71  {
72 
74  findLatestInstanceData(const MemoryID& entityID, int instanceIndex = 0) const
75  {
76  const auto* instance =
77  derived<DerivedT>(this).findLatestInstance(entityID, instanceIndex);
78  return instance ? instance->data() : nullptr;
79  }
80 
81  template <class AronDtoT>
82  std::optional<AronDtoT>
83  findLatestInstanceDataAs(const MemoryID& entityID, int instanceIndex = 0) const
84  {
85  return getInstanceDataAs<AronDtoT>(
86  derived<DerivedT>(this).findLatestInstanceData(entityID, instanceIndex));
87  }
88  };
89 
90 } // namespace armarx::armem::wm::detail
armarx::armem::wm::detail::FindInstanceDataMixin::findLatestInstanceDataAs
std::optional< AronDtoT > findLatestInstanceDataAs(const MemoryID &entityID, int instanceIndex=0) const
Definition: data_lookup_mixins.h:83
armarx::armem::wm::detail::FindInstanceDataMixin::findLatestInstanceData
aron::data::DictPtr findLatestInstanceData(const MemoryID &entityID, int instanceIndex=0) const
Definition: data_lookup_mixins.h:74
forward_declarations.h
armarx::armem::wm::detail
Definition: data_lookup_mixins.h:9
armarx::armem::wm::detail::FindInstanceDataMixin
Definition: data_lookup_mixins.h:70
armarx::armem::wm::detail::FindInstanceDataMixinForEntity::findLatestInstanceData
aron::data::DictPtr findLatestInstanceData(int instanceIndex=0) const
Definition: data_lookup_mixins.h:54
armarx::armem::base::detail::derived
DerivedT & derived(ThisT *t)
Definition: derived.h:8
armarx::armem::wm::detail::getInstanceDataAs
std::optional< AronDtoT > getInstanceDataAs(aron::data::DictPtr data)
Definition: data_lookup_mixins.h:15
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
forward_declarations.h
armarx::armem::wm::detail::FindInstanceDataMixinForEntity::findLatestInstanceDataAs
std::optional< AronDtoT > findLatestInstanceDataAs(int instanceIndex=0) const
Definition: data_lookup_mixins.h:62
armarx::armem::wm::detail::FindInstanceDataMixinForSnapshot::findInstanceDataAs
std::optional< AronDtoT > findInstanceDataAs(int instanceIndex=0) const
Definition: data_lookup_mixins.h:42
armarx::armem::wm::detail::FindInstanceDataMixinForEntity
Definition: data_lookup_mixins.h:50
derived.h
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::wm::detail::FindInstanceDataMixinForSnapshot::findInstanceData
aron::data::DictPtr findInstanceData(int instanceIndex=0) const
Definition: data_lookup_mixins.h:34
armarx::armem::wm::detail::FindInstanceDataMixinForSnapshot
Definition: data_lookup_mixins.h:30