Schema.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 Callback>
23 struct SchemaImpl : public CallbackElement<Element, Callback>
24 {
25  static constexpr auto type = Elements::Schema;
26 
27  SchemaImpl(const std::string & name, const std::string & schema, Callback cb)
28  : CallbackElement<Element, Callback>(name, cb), schema_(schema)
29  {
30  }
31 
32  static constexpr size_t write_size() { return CallbackElement<Element, Callback>::write_size() + 1; }
33 
35  {
37  builder.write(schema_);
38  }
39 
40 private:
41  std::string schema_;
42 };
43 
44 } // namespace details
45 
47 template<typename Callback>
48 auto Schema(const std::string & name, const std::string & schema, Callback cb)
49 {
50  return details::SchemaImpl(name, schema, cb);
51 }
52 
53 } // namespace mc_rtc::gui
mc_rtc::gui::Element
Definition: elements.h:58
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::details::SchemaImpl::write_size
static constexpr size_t write_size()
Definition: Schema.h:32
mc_rtc::gui::Schema
auto Schema(const std::string &name, const std::string &schema, Callback cb)
Definition: Schema.h:48
mc_rtc::gui::CallbackElement
Definition: elements.h:126
mc_rtc::gui::details::SchemaImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Schema.h:34
mc_rtc::gui::details::SchemaImpl
Definition: Schema.h:23
elements.h
mc_rtc::gui::details::write
auto write(T &value)
Definition: traits.h:224
mc_rtc::gui::details::SchemaImpl::type
static constexpr auto type
Definition: Schema.h:25
mc_rtc::gui::Elements::Schema
@ Schema
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::SchemaImpl::SchemaImpl
SchemaImpl(const std::string &name, const std::string &schema, Callback cb)
Definition: Schema.h:27
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61