RemoteGuiAronDataVisitor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <stack>
5 
7 
9 
12 
13 
14 namespace armarx::armem::server
15 {
16 
19  {
23 
24 
25  struct Group
26  {
27  Group(const std::string& label = {});
28 
31  int nextRow = 0;
32  };
33 
34  std::stack<Group> groups;
36 
37 
38  virtual ~RemoteGuiAronDataVisitor() = default;
39 
40  void visitDictOnEnter(const aron::data::VariantPtr& n) override
41  {
43  const std::string key = n->getPath().size() > 0 ? n->getPath().getLastElement() : ""; // check if root of object
44  visitEnter(key, "dict", n->childrenSize());
45  }
47  {
48  visitExit();
49  }
50 
51  void visitListOnEnter(const aron::data::VariantPtr& n) override
52  {
54  const std::string key = n->getPath().getLastElement();
55  visitEnter(key, "list", n->childrenSize());
56  }
58  {
59  visitExit();
60  }
61 
62  // Same for Dict and List
63  bool visitEnter(const std::string& key, const std::string& type, size_t size);
64  bool visitExit();
65 
66  void visitBool(const aron::data::VariantPtr& b) override
67  {
69  const std::string key = b->getPath().getLastElement();
70  this->addValueLabel(key, *aron::data::Bool::DynamicCastAndCheck(b), "bool");
71  }
72  void visitDouble(const aron::data::VariantPtr& d) override
73  {
75  const std::string key = d->getPath().getLastElement();
76  this->addValueLabel(key, *aron::data::Double::DynamicCastAndCheck(d), "double");
77  }
78  void visitFloat(const aron::data::VariantPtr& f) override
79  {
81  const std::string key = f->getPath().getLastElement();
82  this->addValueLabel(key, *aron::data::Float::DynamicCastAndCheck(f), "float");
83  }
84  void visitInt(const aron::data::VariantPtr& i) override
85  {
87  const std::string key = i->getPath().getLastElement();
88  this->addValueLabel(key, *aron::data::Int::DynamicCastAndCheck(i), "int");
89  }
90  void visitLong(const aron::data::VariantPtr& l) override
91  {
93  const std::string key = l->getPath().getLastElement();
94  this->addValueLabel(key, *aron::data::Long::DynamicCastAndCheck(l), "long");
95  }
96  void visitString(const aron::data::VariantPtr& string) override
97  {
98  ARMARX_CHECK_NOT_NULL(string);
100  const std::string key = string->getPath().getLastElement();
101  this->addValueLabel(key, *s, "string");
102  }
103 
104  void visitNDArray(const aron::data::VariantPtr& array) override
105  {
106  ARMARX_CHECK_NOT_NULL(array);
107  const std::string key = array->getPath().getLastElement();
108  this->addValueLabel(key, *aron::data::NDArray::DynamicCastAndCheck(array), "ND Array");
109  }
110 
111  void visitUnknown(const aron::data::VariantPtr& unknown) override
112  {
113  ARMARX_IMPORTANT << "Unknown data encountered: "
114  << (unknown ? unknown->getFullName() : "nullptr");
115  }
116 
117 
118  private:
119  template <class DataT>
120  void addValueLabel(const std::string& key, DataT& n, const std::string& typeName)
121  {
122  checkGroupsNotEmpty();
123  Group& g = groups.top();
124  g.layout
125  .add(Label(key), {g.nextRow, 0})
126  .add(Label("(" + typeName + ")"), {g.nextRow, 1})
127  .add(Label("= " + getValueText(n)), {g.nextRow, 2})
128  ;
129  ++g.nextRow;
130  }
131 
132  template <class DataT>
133  std::string getValueText(DataT& n)
134  {
135  std::stringstream ss;
136  streamValueText(n, ss);
137  return ss.str();
138  }
139 
140  template <class DataT>
141  void streamValueText(DataT& n, std::stringstream& ss)
142  {
143  ss << n.getValue();
144  }
145  void streamValueText(aron::data::String& n, std::stringstream& ss);
146  void streamValueText(aron::data::NDArray& n, std::stringstream& ss);
147 
148  void checkGroupsNotEmpty() const;
149 
150  };
151 
152 
153 }
armarx::armem::server::RemoteGuiAronDataVisitor::Group::Group
Group(const std::string &label={})
Definition: RemoteGuiAronDataVisitor.cpp:11
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::armem::server::RemoteGuiAronDataVisitor::groups
std::stack< Group > groups
Definition: RemoteGuiAronDataVisitor.h:34
armarx::RemoteGui::Client::Label
Definition: Widgets.h:31
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::armem::server::RemoteGuiAronDataVisitor
Definition: RemoteGuiAronDataVisitor.h:17
armarx::armem::server::RemoteGuiAronDataVisitor::visitInt
void visitInt(const aron::data::VariantPtr &i) override
Definition: RemoteGuiAronDataVisitor.h:84
armarx::armem::server::RemoteGuiAronDataVisitor::result
GroupBox result
Definition: RemoteGuiAronDataVisitor.h:35
armarx::aron::data::detail::SpecializedVariantBase< data::dto::AronBool, Bool >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::armem::server::RemoteGuiAronDataVisitor::visitNDArray
void visitNDArray(const aron::data::VariantPtr &array) override
Definition: RemoteGuiAronDataVisitor.h:104
armarx::armem::server::RemoteGuiAronDataVisitor::visitListOnEnter
void visitListOnEnter(const aron::data::VariantPtr &n) override
Definition: RemoteGuiAronDataVisitor.h:51
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::armem::server::RemoteGuiAronDataVisitor::visitListOnExit
void visitListOnExit(const aron::data::VariantPtr &) override
Definition: RemoteGuiAronDataVisitor.h:57
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::armem::server::RemoteGuiAronDataVisitor::visitFloat
void visitFloat(const aron::data::VariantPtr &f) override
Definition: RemoteGuiAronDataVisitor.h:78
armarx::armem::server::RemoteGuiAronDataVisitor::Group::layout
GridLayout layout
Definition: RemoteGuiAronDataVisitor.h:30
armarx::armem::server::RemoteGuiAronDataVisitor::visitExit
bool visitExit()
Definition: RemoteGuiAronDataVisitor.cpp:26
armarx::armem::server::RemoteGuiAronDataVisitor::~RemoteGuiAronDataVisitor
virtual ~RemoteGuiAronDataVisitor()=default
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
All.h
armarx::armem::server::RemoteGuiAronDataVisitor::visitDictOnExit
void visitDictOnExit(const aron::data::VariantPtr &) override
Definition: RemoteGuiAronDataVisitor.h:46
armarx::armem::server::RemoteGuiAronDataVisitor::visitDouble
void visitDouble(const aron::data::VariantPtr &d) override
Definition: RemoteGuiAronDataVisitor.h:72
armarx::armem::server::RemoteGuiAronDataVisitor::Group::nextRow
int nextRow
Definition: RemoteGuiAronDataVisitor.h:31
armarx::armem::server
Definition: GraspMemory.cpp:19
armarx::armem::server::RemoteGuiAronDataVisitor::visitBool
void visitBool(const aron::data::VariantPtr &b) override
Definition: RemoteGuiAronDataVisitor.h:66
armarx::armem::server::RemoteGuiAronDataVisitor::visitString
void visitString(const aron::data::VariantPtr &string) override
Definition: RemoteGuiAronDataVisitor.h:96
armarx::armem::server::RemoteGuiAronDataVisitor::visitEnter
bool visitEnter(const std::string &key, const std::string &type, size_t size)
Definition: RemoteGuiAronDataVisitor.cpp:17
armarx::armem::server::RemoteGuiAronDataVisitor::Label
armarx::RemoteGui::Client::Label Label
Definition: RemoteGuiAronDataVisitor.h:22
VariantVisitor.h
armarx::aron::data::RecursiveConstVariantVisitor
Definition: VariantVisitor.h:120
armarx::armem::server::RemoteGuiAronDataVisitor::visitUnknown
void visitUnknown(const aron::data::VariantPtr &unknown) override
Definition: RemoteGuiAronDataVisitor.h:111
armarx::armem::server::RemoteGuiAronDataVisitor::visitLong
void visitLong(const aron::data::VariantPtr &l) override
Definition: RemoteGuiAronDataVisitor.h:90
Widgets.h
armarx::armem::server::RemoteGuiAronDataVisitor::Group::groupBox
GroupBox groupBox
Definition: RemoteGuiAronDataVisitor.h:29
cxxopts::String
std::string String
Definition: cxxopts.hpp:209
armarx::armem::server::RemoteGuiAronDataVisitor::visitDictOnEnter
void visitDictOnEnter(const aron::data::VariantPtr &n) override
Definition: RemoteGuiAronDataVisitor.h:40
Logging.h
armarx::armem::server::RemoteGuiAronDataVisitor::Group
Definition: RemoteGuiAronDataVisitor.h:25
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33