DataComboInput.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/elements.h>
8 
9 namespace mc_rtc::gui
10 {
11 
12 namespace details
13 {
14 
22 template<typename GetT, typename SetT>
23 struct DataComboInputImpl : public CommonInputImpl<GetT, SetT>
24 {
25  static constexpr auto type = Elements::DataComboInput;
26 
27  DataComboInputImpl(const std::string & name, const std::vector<std::string> & data_ref, GetT get_fn, SetT set_fn)
28  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn), data_ref_(data_ref)
29  {
30  }
31 
32  static constexpr size_t write_size() { return CommonInputImpl<GetT, SetT>::write_size() + 1; }
33 
35  {
37  builder.write(data_ref_);
38  }
39 
42 
43 private:
44  std::vector<std::string> data_ref_;
45 };
46 
47 } // namespace details
48 
50 template<typename GetT, typename SetT>
51 auto DataComboInput(const std::string & name, const std::vector<std::string> & values, GetT get_fn, SetT set_fn)
52 {
53  return details::DataComboInputImpl(name, values, get_fn, set_fn);
54 }
55 
57 inline auto DataComboInput(const std::string & name, const std::vector<std::string> & values, std::string & value)
58 {
59  return DataComboInput(name, values, details::read(value), details::write(value));
60 }
61 
62 } // 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::DataComboInput
auto DataComboInput(const std::string &name, const std::vector< std::string > &values, GetT get_fn, SetT set_fn)
Definition: DataComboInput.h:51
mc_rtc::gui::details::DataComboInputImpl::DataComboInputImpl
DataComboInputImpl()
Definition: DataComboInput.h:41
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
mc_rtc::gui::details::DataComboInputImpl::type
static constexpr auto type
Definition: DataComboInput.h:25
elements.h
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::gui::details::DataComboInputImpl::DataComboInputImpl
DataComboInputImpl(const std::string &name, const std::vector< std::string > &data_ref, GetT get_fn, SetT set_fn)
Definition: DataComboInput.h:27
mc_rtc::gui::details::DataComboInputImpl::write_size
static constexpr size_t write_size()
Definition: DataComboInput.h:32
mc_rtc::gui::details::DataComboInputImpl
Definition: DataComboInput.h:23
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::DataComboInputImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: DataComboInput.h:34
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
mc_rtc::gui::Elements::DataComboInput
@ DataComboInput
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