ice_conversions.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <RobotAPI/interface/armem/memory.h>
10 
11 #include "CoreSegmentBase.h"
12 #include "EntityBase.h"
13 #include "EntityInstanceBase.h"
14 #include "EntitySnapshotBase.h"
15 #include "MemoryBase.h"
16 #include "ProviderSegmentBase.h"
17 
19 {
20  void toIceItem(data::detail::MemoryItem& ice, const MemoryItem& item);
21  void fromIceItem(const data::detail::MemoryItem& ice, MemoryItem& item);
22 
25 
26  void toIce(aron::type::dto::GenericTypePtr& ice, const aron::type::ObjectPtr& bo);
27  void fromIce(const aron::type::dto::GenericTypePtr& ice, aron::type::ObjectPtr& bo);
28 } // namespace armarx::armem::base::detail
29 
30 namespace armarx::armem::base
31 {
32  void toIce(data::EntityInstanceMetadata& ice, const EntityInstanceMetadata& metadata);
34 
35  void toIce(data::EntityInstanceMetadataPtr& ice, const EntityInstanceMetadata& metadata);
36  void fromIce(const data::EntityInstanceMetadataPtr& ice, EntityInstanceMetadata& metadata);
37 
38  template <class... Args>
39  void
41  {
42  detail::toIceItem(ice, data);
43 
44  // detail::toIce(std::ref(ice.data).get(), data.data());
45  detail::toIce(ice.data, data.data());
46  toIce(ice.metadata, data.metadata());
47  }
48 
49  template <class... Args>
50  void
52  {
54 
55  detail::fromIce(ice.data, data.data());
56  fromIce(ice.metadata, data.metadata());
57  }
58 
59  template <class... Args>
60  void
62  {
63  detail::toIceItem(ice, snapshot);
64 
65  ice.instances.clear();
66  snapshot.forEachInstance([&ice](const auto& instance)
67  { armarx::toIce(ice.instances.emplace_back(), instance); });
68  }
69 
70  template <class... Args>
71  void
73  {
74  detail::fromIceItem(ice, snapshot);
75 
76  snapshot.clear();
77  for (const data::EntityInstancePtr& iceInstance : ice.instances)
78  {
79  snapshot.addInstance(
81  iceInstance));
82  }
83  }
84 
85  template <class... Args>
86  void
87  toIce(data::Entity& ice, const EntityBase<Args...>& entity)
88  {
89  detail::toIceItem(ice, entity);
90 
91  ice.history.clear();
92  entity.forEachSnapshot(
93  [&ice](const auto& snapshot)
94  { armarx::toIce(ice.history[armarx::toIce<dto::Time>(snapshot.time())], snapshot); });
95  }
96 
97  template <class... Args>
98  void
99  fromIce(const data::Entity& ice, EntityBase<Args...>& entity)
100  {
101  detail::fromIceItem(ice, entity);
102 
103  entity.clear();
104  for (const auto& [key, snapshot] : ice.history)
105  {
106  entity.addSnapshot(
108  }
109  }
110 
111  template <class... Args>
112  void
113  toIce(data::ProviderSegment& ice, const ProviderSegmentBase<Args...>& providerSegment)
114  {
115  detail::toIceItem(ice, providerSegment);
116 
117  detail::toIce(ice.aronType, providerSegment.aronType());
118  ARMARX_CHECK(!providerSegment.aronType() || ice.aronType);
119 
120  ice.entities.clear();
121  providerSegment.forEachEntity([&ice](const auto& entity)
122  { armarx::toIce(ice.entities[entity.name()], entity); });
123  }
124 
125  template <class... Args>
126  void
127  fromIce(const data::ProviderSegment& ice, ProviderSegmentBase<Args...>& providerSegment)
128  {
129  detail::fromIceItem(ice, providerSegment);
130 
131  detail::fromIce(ice.aronType, providerSegment.aronType());
132  ARMARX_CHECK(!providerSegment.aronType() || ice.aronType);
133 
134  providerSegment.clear();
135  for (const auto& [key, entity] : ice.entities)
136  {
137  providerSegment.addEntity(
139  }
140  }
141 
142  template <class... Args>
143  void
144  toIce(data::CoreSegment& ice, const CoreSegmentBase<Args...>& coreSegment)
145  {
146  detail::toIceItem(ice, coreSegment);
147 
148  detail::toIce(ice.aronType, coreSegment.aronType());
149  ARMARX_CHECK(!coreSegment.aronType() || ice.aronType);
150 
151  ice.providerSegments.clear();
152  coreSegment.forEachProviderSegment(
153  [&ice](const auto& providerSegment)
154  { armarx::toIce(ice.providerSegments[providerSegment.name()], providerSegment); });
155  }
156 
157  template <class... Args>
158  void
159  fromIce(const data::CoreSegment& ice, CoreSegmentBase<Args...>& coreSegment)
160  {
161  detail::fromIceItem(ice, coreSegment);
162 
163  detail::fromIce(ice.aronType, coreSegment.aronType());
164  ARMARX_CHECK(!coreSegment.aronType() || ice.aronType);
165 
166  // fromIce(ice.providerSegments, coreSegment.providerSegments());
167  coreSegment.clear();
168  for (const auto& [key, providerSegment] : ice.providerSegments)
169  {
170  coreSegment.addProviderSegment(
172  providerSegment));
173  }
174  }
175 
176  template <class... Args>
177  void
178  toIce(data::Memory& ice, const MemoryBase<Args...>& memory)
179  {
181 
182  ice.coreSegments.clear();
183  memory.forEachCoreSegment(
184  [&ice](const auto& coreSegment)
185  { armarx::toIce(ice.coreSegments[coreSegment.name()], coreSegment); });
186  }
187 
188  template <class... Args>
189  void
190  fromIce(const data::Memory& ice, MemoryBase<Args...>& memory)
191  {
193 
194  memory.clear();
195  for (const auto& [key, coreSegment] : ice.coreSegments)
196  {
197  // We can avoid using CoreSegment's copy constructor this way:
198  armarx::fromIce(coreSegment, memory.addCoreSegment(coreSegment->id.coreSegmentName));
199  }
200  }
201 
202 } // namespace armarx::armem::base
armarx::armem::base::ProviderSegmentBase
Data of a provider segment containing multiple entities.
Definition: ProviderSegmentBase.h:22
armarx::armem::base::detail::fromIceItem
void fromIceItem(const data::detail::MemoryItem &ice, MemoryItem &item)
Definition: ice_conversions.cpp:19
armarx::armem::base
Definition: CoreSegmentBase.h:15
EntitySnapshotBase.h
armarx::armem::server::wm::EntityInstance
armem::wm::EntityInstance EntityInstance
Definition: forward_declarations.h:64
MemoryBase.h
armarx::armem::base::EntitySnapshotBase::addInstance
EntityInstanceT & addInstance(const EntityInstanceT &instance)
Add a single instance with data.
Definition: EntitySnapshotBase.h:264
armarx::armem::base::EntitySnapshotBase::forEachInstance
bool forEachInstance(InstanceFunctionT &&func)
Definition: EntitySnapshotBase.h:178
armarx::armem::base::EntitySnapshotBase
Data of an entity at one point in time.
Definition: EntitySnapshotBase.h:24
EntityInstanceBase.h
armarx::armem::base::detail::AronTyped::aronType
aron::type::ObjectPtr & aronType()
Definition: AronTyped.cpp:18
armarx::armem::base::detail
Definition: AronTyped.cpp:6
armarx::armem::wm::EntityInstanceMetadata
base::EntityInstanceMetadata EntityInstanceMetadata
Client-side working memory entity instance metadata.
Definition: memory_definitions.h:18
armarx::armem::base::detail::toIceItem
void toIceItem(data::detail::MemoryItem &ice, const MemoryItem &item)
Definition: ice_conversions.cpp:15
ice_conversions.h
armarx::armem::base::EntityBase
An entity over a period of time.
Definition: EntityBase.h:43
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(const Time &timestamp)
Add a snapshot at the given time.
Definition: EntityBase.h:629
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::armem::base::CoreSegmentBase
Data of a core segment containing multiple provider segments.
Definition: CoreSegmentBase.h:22
armarx::armem::base::EntityBase::EntitySnapshotT
_EntitySnapshotT EntitySnapshotT
Definition: EntityBase.h:56
armarx::armem::base::toIce
void toIce(data::EntityInstanceMetadata &ice, const EntityInstanceMetadata &metadata)
Definition: ice_conversions.cpp:56
armarx::armem::base::fromIce
void fromIce(const data::EntityInstanceMetadata &ice, EntityInstanceMetadata &metadata)
Definition: ice_conversions.cpp:65
armarx::armem::base::CoreSegmentBase::ProviderSegmentT
_ProviderSegmentT ProviderSegmentT
Definition: CoreSegmentBase.h:40
ProviderSegmentBase.h
armarx::armem::base::detail::fromIce
void fromIce(const aron::data::dto::DictPtr &ice, aron::data::DictPtr &bo)
Definition: ice_conversions.cpp:29
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::base::CoreSegmentBase::forEachProviderSegment
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
Definition: CoreSegmentBase.h:217
EntityBase.h
armarx::armem::base::CoreSegmentBase::addProviderSegment
ProviderSegmentT & addProviderSegment(const std::string &name, aron::type::ObjectPtr providerSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty provider segment with the given name, optional provider segment type and prediction engi...
Definition: CoreSegmentBase.h:344
ice_conversions.h
armarx::armem::base::MemoryBase
Data of a memory consisting of multiple core segments.
Definition: MemoryBase.h:19
armarx::armem::base::detail::toIce
void toIce(aron::data::dto::DictPtr &ice, const aron::data::DictPtr &bo)
Definition: ice_conversions.cpp:25
armarx::armem::base::EntityInstanceBase
Data of a single entity instance.
Definition: EntityInstanceBase.h:80
forward_declarations.h
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
ExpressionException.h
armarx::armem::base::detail::MemoryContainerBase< std::vector< _EntityInstanceT >, _Derived >::clear
void clear()
Definition: MemoryContainerBase.h:52
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::server::wm::EntitySnapshot
armem::wm::EntitySnapshot EntitySnapshot
Definition: forward_declarations.h:65
armarx::armem::base::ProviderSegmentBase::forEachEntity
bool forEachEntity(EntityFunctionT &&func)
Definition: ProviderSegmentBase.h:189
CoreSegmentBase.h
armarx::armem::base::EntitySnapshotBase::EntityInstanceT
_EntityInstanceT EntityInstanceT
Definition: EntitySnapshotBase.h:33
ice_conversions_templates.h
armarx::armem::base::EntityBase::forEachSnapshot
bool forEachSnapshot(SnapshotFunctionT &&func)
Definition: EntityBase.h:390
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::armem::base::ProviderSegmentBase::addEntity
EntityT & addEntity(const std::string &name)
Add an empty entity with the given name.
Definition: ProviderSegmentBase.h:298
armarx::armem::base::ProviderSegmentBase::EntityT
_EntityT EntityT
Definition: ProviderSegmentBase.h:37
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168