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