mc_rtc  2.16.0
Transform.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 TransformImpl : public CommonInputImpl<GetT, SetT>
31 {
32  static constexpr auto type = Elements::Transform;
33 
34  TransformImpl(const std::string & name, GetT get_fn, SetT set_fn = nullptr)
35  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn)
36  {
38  "TransformImpl getter should return an sva::PTransformd");
39  }
40 
41  constexpr static size_t write_size() { return CommonInputImpl<GetT, SetT>::write_size() + 1; }
42 
44  {
46  // True for read-only
47  builder.write(std::is_same_v<SetT, std::nullptr_t>);
48  }
49 
52 };
53 
54 } // namespace details
55 
57 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
58 auto Transform(const std::string & name, GetT get_fn)
59 { return details::TransformImpl(name, get_fn); }
60 
62 template<typename GetT, typename SetT>
63 auto Transform(const std::string & name, GetT get_fn, SetT set_fn)
64 { return details::TransformImpl(name, get_fn, set_fn); }
65 
67 template<typename T>
68 auto TransformRO(const std::string & name, T && value)
69 { return Transform(name, details::read(std::forward<T>(value))); }
70 
72 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
73 auto Transform(const std::string & name, T & value)
74 { return Transform(name, details::read(value), details::write(value)); }
75 
76 } // namespace mc_rtc::gui
std::optional< Eigen::VectorXd > value
auto read(const T &&value)
Definition: traits.h:184
auto write(T &value)
Definition: traits.h:226
Definition: Observer.h:16
auto Transform(const std::string &name, GetT get_fn)
Definition: Transform.h:58
auto TransformRO(const std::string &name, T &&value)
Definition: Transform.h:68
Definition: MessagePackBuilder.h:87
Definition: elements.h:167
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
static constexpr size_t write_size()
Definition: elements.h:106
Definition: Transform.h:31
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Transform.h:43
constexpr static size_t write_size()
Definition: Transform.h:41
TransformImpl(const std::string &name, GetT get_fn, SetT set_fn=nullptr)
Definition: Transform.h:34
TransformImpl()
Definition: Transform.h:51
static constexpr auto type
Definition: Transform.h:32