operations.cpp
Go to the documentation of this file.
1 #include "operations.h"
2 
4 
5 #include <SimoxUtility/algorithm/string/string_tools.h>
6 
7 
8 namespace armarx
9 {
10 
11  std::vector<aron::data::DictPtr>
13  {
14  std::vector<aron::data::DictPtr> result;
15  snapshot.forEachChild([&result](const wm::EntityInstance & instance)
16  {
17  result.push_back(instance.data());
18  return true;
19  });
20  return result;
21  }
22 
23 
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 
34  template <class DataT>
35  static std::string 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 
58  template <class DataT>
59  static std::string _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  {
67  ss << armem::print(instance, maxDepth - 1, depth + 1);
68  });
69  }
70  return ss.str();
71  }
72 
73  std::string armem::print(const wm::Memory& data, int maxDepth, int depth)
74  {
75  return _print(data, maxDepth, depth);
76  }
77  std::string armem::print(const wm::CoreSegment& data, int maxDepth, int depth)
78  {
79  return _print(data, maxDepth, depth);
80  }
81  std::string armem::print(const wm::ProviderSegment& data, int maxDepth, int depth)
82  {
83  return _print(data, maxDepth, depth);
84  }
85  std::string armem::print(const wm::Entity& data, int maxDepth, int depth)
86  {
87  return _print(data, maxDepth, depth);
88  }
89  std::string armem::print(const wm::EntitySnapshot& data, int maxDepth, int depth)
90  {
91  return _print(data, maxDepth, depth);
92  }
93 
94  std::string armem::print(const wm::EntityInstance& data, int maxDepth, int depth)
95  {
96  (void) maxDepth;
97  std::stringstream ss;
98  ss << makeLine(depth, data);
99  return ss.str();
100  }
101 }
armarx::armem::EntityUpdate::instancesData
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition: Commit.h:33
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::base::detail::MemoryContainerBase::forEachChild
bool forEachChild(ChildFunctionT &&func)
Definition: MemoryContainerBase.h:64
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:136
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::toEntityUpdate
EntityUpdate toEntityUpdate(const wm::EntitySnapshot &snapshot)
Definition: operations.cpp:24
operations.h
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
armarx::armem::MemoryID::getEntityID
MemoryID getEntityID() const
Definition: MemoryID.cpp:305
armarx::armem::EntityUpdate::referencedTime
Time referencedTime
Time when this entity update was created (e.g.
Definition: Commit.h:39
armarx::armem::base::EntitySnapshotBase::time
Time & time()
Definition: EntitySnapshotBase.h:59
Time.h
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::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129
armarx::armem::EntityUpdate::entityID
MemoryID entityID
The entity's ID.
Definition: Commit.h:30
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28