ArrayLabel.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 
7 #include <mc_rtc/gui/Label.h>
8 
9 namespace mc_rtc::gui
10 {
11 
12 namespace details
13 {
14 
23 template<typename GetT>
24 struct ArrayLabelImpl : public LabelImpl<GetT>
25 {
26  static constexpr auto type = Elements::ArrayLabel;
27 
28  ArrayLabelImpl(const std::string & name, GetT get_fn) : LabelImpl<GetT>(name, get_fn) {}
29 
30  ArrayLabelImpl(const std::string & name, const std::vector<std::string> & labels, GetT get_fn)
31  : LabelImpl<GetT>(name, get_fn), labels_(labels)
32  {
33  }
34 
37 
38  static constexpr size_t write_size() { return LabelImpl<GetT>::write_size() + 1; }
39 
41  {
42  LabelImpl<GetT>::write(writer);
43  writer.write(labels_);
44  }
45 
46 private:
47  std::vector<std::string> labels_;
48 };
49 
50 } // namespace details
51 
53 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
54 auto ArrayLabel(const std::string & name, GetT get_fn)
55 {
56  return details::ArrayLabelImpl(name, get_fn);
57 }
58 
60 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
61 auto ArrayLabel(const std::string & name, const std::vector<std::string> & labels, GetT get_fn)
62 {
63  return details::ArrayLabelImpl(name, labels, get_fn);
64 }
65 
70 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
71 auto ArrayLabel(const std::string & name, const std::vector<std::string> & labels, T && value)
72 {
73  return ArrayLabel(name, labels, details::read(std::forward<T>(value)));
74 }
75 
80 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
81 auto ArrayLabel(const std::string & name, T && value)
82 {
83  using Labels = details::Labels<std::decay_t<T>>;
84  auto callback = details::read(std::forward<T>(value));
85  if constexpr(Labels::has_labels) { return ArrayLabel(name, Labels::labels, callback); }
86  else { return details::ArrayLabelImpl(name, callback); }
87 }
88 
93 template<bool Degrees = true, typename T>
94 auto RPYLabel(const std::string & name, T && value)
95 {
96  return ArrayLabel(name, details::RPYLabels<Degrees>::labels, details::read_rpy<Degrees>(std::forward<T>(value)));
97 }
98 
99 } // namespace mc_rtc::gui
mc_rtc::gui::details::ArrayLabelImpl::type
static constexpr auto type
Definition: ArrayLabel.h:26
mc_rtc::gui::Elements::ArrayLabel
@ ArrayLabel
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::ArrayLabelImpl::write
void write(mc_rtc::MessagePackBuilder &writer)
Definition: ArrayLabel.h:40
mc_rtc::gui::details::ArrayLabelImpl::ArrayLabelImpl
ArrayLabelImpl()
Definition: ArrayLabel.h:36
mc_rtc::gui::RPYLabel
auto RPYLabel(const std::string &name, T &&value)
Definition: ArrayLabel.h:94
mc_rtc::gui::details::LabelImpl
Definition: Label.h:22
mc_rtc::gui::details::ArrayLabelImpl::write_size
static constexpr size_t write_size()
Definition: ArrayLabel.h:38
mc_rtc::gui::details::ArrayLabelImpl::ArrayLabelImpl
ArrayLabelImpl(const std::string &name, const std::vector< std::string > &labels, GetT get_fn)
Definition: ArrayLabel.h:30
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
mc_rtc::gui::details::ArrayLabelImpl
Definition: ArrayLabel.h:24
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::RPYLabels
Definition: traits.h:175
Label.h
mc_rtc::gui::details::ArrayLabelImpl::ArrayLabelImpl
ArrayLabelImpl(const std::string &name, GetT get_fn)
Definition: ArrayLabel.h:28
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
mc_rtc::gui::ArrayLabel
auto ArrayLabel(const std::string &name, GetT get_fn)
Definition: ArrayLabel.h:54
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::details::Labels
Definition: traits.h:119
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61