WidgetRegister.cpp
Go to the documentation of this file.
1 #include "WidgetRegister.h"
2 
3 #include "Widgets.h"
4 
7 
8 #include <memory>
9 #include <map>
10 #include <typeindex>
11 
12 namespace armarx::RemoteGui
13 {
14 
15  typedef std::map<std::type_index, WidgetHandler*> WidgetRegister;
16 
17  template <typename HandlerT>
19  {
21  static WidgetHandler handler;
22  register_.emplace(typeid(typename WidgetHandler::RemoteWidgetT), &handler);
23  }
24 
26  {
27  WidgetRegister result;
28 
29  registerHandler<CheckBoxHandler>(result);
30  registerHandler<ToggleButtonHandler>(result);
31  registerHandler<ButtonHandler>(result);
32 
33  registerHandler<IntSpinBoxHandler>(result);
34  registerHandler<IntSliderHandler>(result);
35  registerHandler<FloatSpinBoxHandler>(result);
36  registerHandler<FloatSliderHandler>(result);
37 
38  registerHandler<LabelHandler>(result);
39  registerHandler<LineEditHandler>(result);
40  registerHandler<ComboBoxHandler>(result);
41 
42  registerHandler<GroupBoxHandler>(result);
43  registerHandler<VBoxLayoutHandler>(result);
44  registerHandler<HBoxLayoutHandler>(result);
45  registerHandler<SimpleGridLayoutSpanningChildHandler>(result);
46  registerHandler<SimpleGridLayoutHandler>(result);
47  registerHandler<GridLayoutHandler>(result);
48 
49  registerHandler<HSpacerHandler>(result);
50  registerHandler<VSpacerHandler>(result);
51  registerHandler<HLineHandler>(result);
52  registerHandler<VLineHandler>(result);
53  registerHandler<EmptyWidgetHandler>(result);
54 
55  registerHandler<Vector3fSpinBoxesHandler>(result);
56  registerHandler<PosRPYSpinBoxesHandler>(result);
57  return result;
58  }
59 
61  {
63  static const WidgetRegister widgetRegister = createWidgetRegister();
64 
65  auto descPtr = desc.get();
66  ARMARX_CHECK_EXPRESSION(descPtr != nullptr);
67 
68  std::type_info const& typeInfo = typeid(*descPtr);
69 
70  auto iter = widgetRegister.find(typeInfo);
71  if (iter == widgetRegister.end())
72  {
73  throw armarx::LocalException()
74  << "Unexpected widget type: "
75  << GetTypeString(typeInfo)
76  << "\n only these types are supported:"
78  {
79  for (const auto& [tid, _] : widgetRegister)
80  {
81  out << "\n " << GetTypeString(tid);
82  }
83  };
84  }
85 
86  auto& widgetHandler = iter->second;
87  ARMARX_CHECK_EXPRESSION(widgetHandler);
88 
89  return *widgetHandler;
90  }
91 
92 }
armarx::RemoteGui::TypedWidgetHandler
Definition: TypedWidget.h:18
armarx::RemoteGui::WidgetRegister
std::map< std::type_index, WidgetHandler * > WidgetRegister
Definition: WidgetRegister.cpp:15
GetTypeString.h
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
Widgets.h
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
WidgetRegister.h
armarx::RemoteGui::WidgetHandler
Definition: WidgetHandler.h:22
armarx::RemoteGui::registerHandler
void registerHandler(WidgetRegister &register_)
Definition: WidgetRegister.cpp:18
armarx::GetTypeString
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
Definition: GetTypeString.h:36
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::RemoteGui::getWidgetHandler
const WidgetHandler & getWidgetHandler(WidgetPtr const &desc)
Definition: WidgetRegister.cpp:60
armarx::RemoteGui::createWidgetRegister
WidgetRegister createWidgetRegister()
Definition: WidgetRegister.cpp:25
ARMARX_STREAM_PRINTER
#define ARMARX_STREAM_PRINTER
use this macro to write output code that is executed when printed and thus not executed if the debug ...
Definition: Logging.h:304