operations.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "wm/memory_definitions.h"
4 
5 #include <string>
6 
7 
8 /*
9  * Functions performing some "advanced" operations on the memory
10  * data structure, which are using their public API but should not
11  * be part of it.
12  */
13 
14 namespace armarx::armem
15 {
16 
17  std::vector<aron::data::DictPtr>
18  getAronData(const wm::EntitySnapshot& snapshot);
19 
20 
21  EntityUpdate
22  toEntityUpdate(const wm::EntitySnapshot& snapshot);
23 
24 
25  template <class ContainerT>
26  Commit
27  toCommit(const ContainerT& container)
28  {
29  Commit commit;
30  container.forEachSnapshot([&commit](const wm::EntitySnapshot & snapshot)
31  {
32  commit.add(toEntityUpdate(snapshot));
33  return true;
34  });
35  return commit;
36  }
37 
38 
39  template <class ContainerT>
40  const typename ContainerT::EntityInstanceT*
41  findFirstInstance(const ContainerT& container)
42  {
43  const typename ContainerT::EntityInstanceT* instance = nullptr;
44  container.forEachInstance([&instance](const wm::EntityInstance & i)
45  {
46  instance = &i;
47  return false;
48  });
49  return instance;
50  }
51 
52 
53  template <class ContainerT>
54  std::vector<MemoryID> getEntityIDs(const ContainerT& container)
55  {
56  std::vector<armem::MemoryID> entityIDs;
57 
58  container.forEachEntity([&entityIDs](const auto& entity)
59  {
60  entityIDs.push_back(entity.id());
61  });
62 
63  return entityIDs;
64  }
65 
66 
67  std::string print(const wm::Memory& data, int maxDepth = -1, int depth = 0);
68  std::string print(const wm::CoreSegment& data, int maxDepth = -1, int depth = 0);
69  std::string print(const wm::ProviderSegment& data, int maxDepth = -1, int depth = 0);
70  std::string print(const wm::Entity& data, int maxDepth = -1, int depth = 0);
71  std::string print(const wm::EntitySnapshot& data, int maxDepth = -1, int depth = 0);
72  std::string print(const wm::EntityInstance& data, int maxDepth = -1, int depth = 0);
73 
74 }
75 
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::findFirstInstance
const ContainerT::EntityInstanceT * findFirstInstance(const ContainerT &container)
Definition: operations.h:41
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:136
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::toEntityUpdate
EntityUpdate toEntityUpdate(const wm::EntitySnapshot &snapshot)
Definition: operations.cpp:24
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
armarx::armem::server::wm::EntitySnapshot
armem::wm::EntitySnapshot EntitySnapshot
Definition: forward_declarations.h:65
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:81
armarx::armem::getEntityIDs
std::vector< MemoryID > getEntityIDs(const ContainerT &container)
Definition: operations.h:54
armarx::armem::print
std::string print(const wm::Memory &data, int maxDepth=-1, int depth=0)
Definition: operations.cpp:73
armarx::armem::getAronData
std::vector< aron::data::DictPtr > getAronData(const wm::EntitySnapshot &snapshot)
Definition: operations.cpp:12
armarx::armem::toCommit
Commit toCommit(const ContainerT &container)
Definition: operations.h:27