operations.cpp
Go to the documentation of this file.
1#include "operations.h"
2
3#include <SimoxUtility/algorithm/string/string_tools.h>
4
6
7namespace armarx
8{
9
10 std::vector<aron::data::DictPtr>
12 {
13 std::vector<aron::data::DictPtr> result;
14 snapshot.forEachChild(
15 [&result](const wm::EntityInstance& instance)
16 {
17 result.push_back(instance.data());
18 return true;
19 });
20 return result;
21 }
22
25 {
26 EntityUpdate up;
27 up.entityID = snapshot.id().getEntityID();
28 up.referencedTime = snapshot.time();
29 up.instancesData = getAronData(snapshot);
30 return up;
31 }
32
33 template <class DataT>
34 static std::string
35 makeLine(int depth, const DataT& data, std::optional<size_t> size = std::nullopt)
36 {
37 std::stringstream ss;
38 while (depth > 1)
39 {
40 ss << "| ";
41 depth--;
42 }
43 if (depth > 0)
44 {
45 ss << "+- ";
46 }
47 ss << simox::alg::capitalize_words(DataT::getLevelName());
48 ss << " '" << simox::alg::capitalize_words(data.getKeyString()) << "'";
49 if (size.has_value())
50 {
51 ss << " (size " << size.value() << ")";
52 }
53 ss << "\n";
54 return ss.str();
55 }
56
57 template <class DataT>
58 static std::string
59 _print(const DataT& data, int maxDepth, int depth)
60 {
61 std::stringstream ss;
62 ss << makeLine(depth, data, data.size());
63 if (maxDepth < 0 || maxDepth > 0)
64 {
65 data.forEachChild([&ss, maxDepth, depth](const auto& instance)
66 { ss << armem::print(instance, maxDepth - 1, depth + 1); });
67 }
68 return ss.str();
69 }
70
71 std::string
72 armem::print(const wm::Memory& data, int maxDepth, int depth)
73 {
74 return _print(data, maxDepth, depth);
75 }
76
77 std::string
78 armem::print(const wm::CoreSegment& data, int maxDepth, int depth)
79 {
80 return _print(data, maxDepth, depth);
81 }
82
83 std::string
84 armem::print(const wm::ProviderSegment& data, int maxDepth, int depth)
85 {
86 return _print(data, maxDepth, depth);
87 }
88
89 std::string
90 armem::print(const wm::Entity& data, int maxDepth, int depth)
91 {
92 return _print(data, maxDepth, depth);
93 }
94
95 std::string
96 armem::print(const wm::EntitySnapshot& data, int maxDepth, int depth)
97 {
98 return _print(data, maxDepth, depth);
99 }
100
101 std::string
102 armem::print(const wm::EntityInstance& data, int maxDepth, int depth)
103 {
104 (void)maxDepth;
105 std::stringstream ss;
106 ss << makeLine(depth, data);
107 return ss.str();
108 }
109} // namespace armarx
MemoryID getEntityID() const
Definition MemoryID.cpp:310
armem::wm::EntitySnapshot EntitySnapshot
armem::wm::EntityInstance EntityInstance
std::string print(const wm::Memory &data, int maxDepth=-1, int depth=0)
EntityUpdate toEntityUpdate(const wm::EntitySnapshot &snapshot)
std::vector< aron::data::DictPtr > getAronData(const wm::EntitySnapshot &snapshot)
This file offers overloads of toIce() and fromIce() functions for STL container types.
An update of an entity for a specific point in time.
Definition Commit.h:26