ComboInput.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 
21 template<typename GetT, typename SetT>
22 struct ComboInputImpl : public CommonInputImpl<GetT, SetT>
23 {
24  static constexpr auto type = Elements::ComboInput;
25 
26  ComboInputImpl(const std::string & name, const std::vector<std::string> & values, GetT get_fn, SetT set_fn)
27  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn), values_(values)
28  {
30  "ComboInput element getter callback should return an std::string");
31  }
32 
33  static constexpr size_t write_size() { return CommonInputImpl<GetT, SetT>::write_size() + 1; }
34 
36  {
38  writer.write(values_);
39  }
40 
43 
44 private:
45  std::vector<std::string> values_;
46 };
47 
48 } // namespace details
49 
51 template<typename GetT, typename SetT>
52 auto ComboInput(const std::string & name, const std::vector<std::string> & values, GetT get_fn, SetT set_fn)
53 {
54  return details::ComboInputImpl(name, values, get_fn, set_fn);
55 }
56 
58 inline auto ComboInput(const std::string & name, const std::vector<std::string> & values, std::string & value)
59 {
60  return ComboInput(name, values, details::read(value), details::write(value));
61 }
62 
63 } // namespace mc_rtc::gui
mc_rtc::gui::details::ComboInputImpl::ComboInputImpl
ComboInputImpl(const std::string &name, const std::vector< std::string > &values, GetT get_fn, SetT set_fn)
Definition: ComboInput.h:26
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::ComboInputImpl
Definition: ComboInput.h:22
mc_rtc::gui::details::ComboInputImpl::type
static constexpr auto type
Definition: ComboInput.h:24
mc_rtc::gui::details::read
auto read(const T &&value)
Definition: traits.h:188
elements.h
mc_rtc::gui::ComboInput
auto ComboInput(const std::string &name, const std::vector< std::string > &values, GetT get_fn, SetT set_fn)
Definition: ComboInput.h:52
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::gui::details::ComboInputImpl::write_size
static constexpr size_t write_size()
Definition: ComboInput.h:33
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::ComboInputImpl::ComboInputImpl
ComboInputImpl()
Definition: ComboInput.h:42
mc_rtc::gui::details::ComboInputImpl::write
void write(mc_rtc::MessagePackBuilder &writer)
Definition: ComboInput.h:35
mc_rtc::gui::Elements::ComboInput
@ ComboInput
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
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