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 {
60  return details::TransformImpl(name, get_fn);
61 }
62 
64 template<typename GetT, typename SetT>
65 auto Transform(const std::string & name, GetT get_fn, SetT set_fn)
66 {
67  return details::TransformImpl(name, get_fn, set_fn);
68 }
69 
71 template<typename T>
72 auto TransformRO(const std::string & name, T && value)
73 {
74  return Transform(name, details::read(std::forward<T>(value)));
75 }
76 
78 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
79 auto Transform(const std::string & name, T & value)
80 {
81  return Transform(name, details::read(value), details::write(value));
82 }
83 
84 } // namespace mc_rtc::gui
mc_rtc::gui::details::TransformImpl
Definition: Transform.h:30
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::Elements::Transform
@ Transform
mc_rtc::gui::Transform
auto Transform(const std::string &name, GetT get_fn)
Definition: Transform.h:58
types.h
mc_rtc::gui::details::TransformImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Transform.h:43
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
elements.h
mc_rtc::gui::details::TransformImpl::TransformImpl
TransformImpl(const std::string &name, GetT get_fn, SetT set_fn=nullptr)
Definition: Transform.h:34
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::TransformRO
auto TransformRO(const std::string &name, T &&value)
Definition: Transform.h:72
mc_rtc::gui::details::TransformImpl::type
static constexpr auto type
Definition: Transform.h:32
mc_rtc::gui::details::TransformImpl::write_size
constexpr static size_t write_size()
Definition: Transform.h:41
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui::details::TransformImpl::TransformImpl
TransformImpl()
Definition: Transform.h:51
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