Polygon.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 
9 
10 namespace mc_rtc
11 {
12 
13 namespace gui
14 {
15 
16 namespace plot
17 {
18 
19 namespace impl
20 {
21 
23 template<typename GetT>
24 struct Polygon
25 {
26  static constexpr Type type = Type::Polygon;
27 
28  Polygon(const std::string & name, GetT get_fn, Side side) : name_(name), get_fn_(get_fn), side_(side)
29  {
31  "Polygon element callback must return a PolygonDescription");
32  }
33 
34  void write(mc_rtc::MessagePackBuilder & builder) const
35  {
36  builder.start_array(4);
37  builder.write(static_cast<uint64_t>(type));
38  builder.write(name_);
39  get_fn_().write(builder);
40  builder.write(static_cast<uint64_t>(side_));
41  builder.finish_array();
42  }
43 
44  void update() const {}
45 
46  Polygon & side(Side side)
47  {
48  side_ = side;
49  return *this;
50  }
51 
52 private:
53  std::string name_;
54  GetT get_fn_;
55  Side side_;
56 };
57 
58 } // namespace impl
59 
61 template<typename GetT>
62 impl::Polygon<GetT> Polygon(const std::string & name, GetT get_fn, Side side = Side::Left)
63 {
64  return impl::Polygon<GetT>(name, get_fn, side);
65 }
66 
67 } // namespace plot
68 
69 } // namespace gui
70 
71 } // namespace mc_rtc
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
types.h
mc_rtc::gui::plot::impl::Polygon::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: Polygon.h:34
mc_rtc::gui::plot::impl::Polygon
Definition: Polygon.h:24
mc_rtc::gui::plot::impl::Polygon::type
static constexpr Type type
Definition: Polygon.h:26
mc_rtc::MessagePackBuilder::finish_array
void finish_array()
mc_rtc::gui::plot::Polygon
impl::Polygon< GetT > Polygon(const std::string &name, GetT get_fn, Side side=Side::Left)
Definition: Polygon.h:62
mc_rtc::MessagePackBuilder::start_array
void start_array(size_t size)
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::plot::impl::Polygon::side
Polygon & side(Side side)
Definition: Polygon.h:46
mc_rtc::gui::plot::impl::Polygon::Polygon
Polygon(const std::string &name, GetT get_fn, Side side)
Definition: Polygon.h:28
mc_rtc::gui::plot::Type::Polygon
@ Polygon
mc_rtc::gui::plot::Type
Type
Definition: types.h:30
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
Left
Left
Definition: types.h:158
mc_rtc::gui::plot::impl::Polygon::update
void update() const
Definition: Polygon.h:44
mc_rtc
Definition: Contact.h:87