Point3D.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 #include <mc_rtc/gui/elements.h>
9 #include <mc_rtc/gui/types.h>
10 
11 namespace mc_rtc::gui
12 {
13 
14 namespace details
15 {
16 
29 template<typename GetT, typename SetT = std::nullptr_t>
30 struct Point3DImpl : public CommonInputImpl<GetT, SetT>
31 {
32  static constexpr auto type = Elements::Point3D;
33 
34  Point3DImpl(const std::string & name, const PointConfig & config, GetT get_fn, SetT set_fn = nullptr)
35  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn), config_(config)
36  {
38  "Point3D element position callback must return an Eigen::Vector3d");
39  }
40 
43 
44  static constexpr size_t write_size()
45  {
47  }
48 
50  {
52  // True for read-only
53  builder.write(std::is_same_v<SetT, std::nullptr_t>);
54  config_.write(builder);
55  }
56 
57 private:
58  PointConfig config_;
59 };
60 
61 } // namespace details
62 
64 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
65 auto Point3D(const std::string & name, GetT get_fn)
66 {
67  return details::Point3DImpl(name, {}, get_fn);
68 }
69 
71 template<typename GetT, typename SetT>
72 auto Point3D(const std::string & name, GetT get_fn, SetT set_fn)
73 {
74  return details::Point3DImpl(name, {}, get_fn, set_fn);
75 }
76 
78 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
79 auto Point3D(const std::string & name, const PointConfig & config, GetT get_fn)
80 {
81  return details::Point3DImpl(name, config, get_fn);
82 }
83 
85 template<typename GetT, typename SetT>
86 auto Point3D(const std::string & name, const PointConfig & config, GetT get_fn, SetT set_fn)
87 {
88  return details::Point3DImpl(name, config, get_fn, set_fn);
89 }
90 
92 template<typename T>
93 auto Point3DRO(const std::string & name, T && value)
94 {
95  return Point3D(name, details::read(std::forward<T>(value)));
96 }
97 
99 template<typename T>
100 auto Point3DRO(const std::string & name, const PointConfig & config, T && value)
101 {
102  return Point3D(name, config, details::read(std::forward<T>(value)));
103 }
104 
106 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
107 auto Point3D(const std::string & name, T & value)
108 {
109  return Point3D(name, details::read(value), details::write(value));
110 }
111 
113 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
114 auto Point3D(const std::string & name, const PointConfig & config, T & value)
115 {
116  return Point3D(name, config, details::read(value), details::write(value));
117 }
118 
119 } // namespace mc_rtc::gui
mc_rtc::gui::DataElement::write_size
static constexpr size_t write_size()
Definition: elements.h:106
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::details::Point3DImpl::type
static constexpr auto type
Definition: Point3D.h:32
types.h
mc_rtc::gui::Elements::Point3D
@ Point3D
mc_rtc::gui::details::Point3DImpl
Definition: Point3D.h:30
mc_rtc::gui::PointConfig::write
void write(mc_rtc::MessagePackBuilder &out) const
Definition: types.h:369
mc_rtc::gui::details::Point3DImpl::Point3DImpl
Point3DImpl(const std::string &name, const PointConfig &config, GetT get_fn, SetT set_fn=nullptr)
Definition: Point3D.h:34
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
mc_rtc::gui::details::Point3DImpl::write_size
static constexpr size_t write_size()
Definition: Point3D.h:44
elements.h
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::Point3DImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Point3D.h:49
mc_rtc::gui::PointConfig
Definition: types.h:341
mc_rtc::gui::Point3DRO
auto Point3DRO(const std::string &name, T &&value)
Definition: Point3D.h:93
mc_rtc::gui::Point3D
auto Point3D(const std::string &name, GetT get_fn)
Definition: Point3D.h:65
mc_rtc::gui::PointConfig::write_size
static constexpr size_t write_size()
Definition: types.h:367
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
mc_rtc::gui::details::Point3DImpl::Point3DImpl
Point3DImpl()
Definition: Point3D.h:42
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui::CommonInputImpl
Definition: elements.h:166
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61