actions.cpp
Go to the documentation of this file.
1 #include "actions.h"
2 
3 #include <RobotAPI/interface/armem/actions.h>
4 
6 {
7 
8  MenuEntry::MenuEntry(const std::string& id,
9  const std::string& text,
10  const std::vector<MenuEntry>& entries) :
11  id(id), text(text), entries(entries)
12  {
13  }
14 
15  MenuEntry&
16  MenuEntry::add(const std::string& id,
17  const std::string& text,
18  const std::vector<MenuEntry>& entries)
19  {
20  return this->entries.emplace_back(id, text, entries);
21  }
22 
23  data::MenuEntryPtr
24  MenuEntry::toIce() const // NOLINT (recursive call chain)
25  {
26  if (entries.empty())
27  {
28  return new data::Action{this->id, this->text};
29  }
30 
31  data::SubMenuPtr ice = new data::SubMenu{this->id, this->text, {}};
32  for (const MenuEntry& entry : entries)
33  {
34  ice->entries.push_back(entry.toIce());
35  }
36  return ice;
37  }
38 
39  MenuEntry
40  MenuEntry::fromIce(const data::MenuEntryPtr& ice) // NOLINT (recursive call chain)
41  {
42  if (ice->ice_isA(data::SubMenu::ice_staticId()))
43  {
45  MenuEntry subMenu{ptr->id, ptr->text, {}};
46  for (const auto& entry : ptr->entries)
47  {
48  subMenu.entries.push_back(MenuEntry::fromIce(entry));
49  }
50  return subMenu;
51  }
52 
53  return MenuEntry{ice->id, ice->text, {}};
54  }
55 
56  Action::Action(const std::string& id, const std::string& text) : MenuEntry(id, text)
57  {
58  }
59 
60  SubMenu::SubMenu(const std::string& id,
61  const std::string& text,
62  const std::vector<MenuEntry>& entries) :
63  MenuEntry(id, text, entries)
64  {
65  }
66 
67  MenuEntry&
68  SubMenu::add(const std::string& id,
69  const std::string& text,
70  const std::vector<MenuEntry>& entries)
71  {
72  return this->entries.emplace_back(id, text, entries);
73  }
74 
75 
76  Menu::Menu(std::initializer_list<MenuEntry> entries) : entries(entries)
77  {
78  }
79 
80  Menu::Menu(const std::vector<MenuEntry>& entries) : entries(entries)
81  {
82  }
83 
84 
85  MenuEntry&
86  Menu::add(const std::string& id, const std::string& text, const std::vector<MenuEntry>& entries)
87  {
88  return this->entries.emplace_back(id, text, entries);
89  }
90 
92  Menu::toIce() const
93  {
94  data::MenuPtr ice{new data::Menu};
95  for (const MenuEntry& entry : entries)
96  {
97  ice->entries.push_back(entry.toIce());
98  }
99  return ice;
100  }
101 
102  Menu
104  {
105  Menu menu;
106  for (const auto& entry : ice->entries)
107  {
108  menu.entries.push_back(MenuEntry::fromIce(entry));
109  }
110  return menu;
111  }
112 } // namespace armarx::armem::actions
armarx::armem::actions::MenuEntry::fromIce
static MenuEntry fromIce(const data::MenuEntryPtr &ice)
Definition: actions.cpp:40
armarx::armem::actions::SubMenu::SubMenu
SubMenu(const std::string &id, const std::string &text, const std::vector< MenuEntry > &entries={})
Definition: actions.cpp:60
armarx::armem::actions::Menu::Menu
Menu(std::initializer_list< MenuEntry > entries)
Definition: actions.cpp:76
armarx::armem::actions::Menu::toIce
data::MenuPtr toIce() const
Definition: actions.cpp:92
armarx::armem::actions::MenuEntry::text
std::string text
Definition: actions.h:29
armarx::armem::actions::MenuEntry
Definition: actions.h:13
armarx::armem::actions::Menu::entries
std::vector< MenuEntry > entries
Definition: actions.h:68
armarx::armem::actions::MenuEntry::entries
std::vector< MenuEntry > entries
Definition: actions.h:30
IceInternal::Handle
Definition: forward_declarations.h:8
actions.h
armarx::armem::actions::Action::Action
Action(const std::string &id, const std::string &text)
Definition: actions.cpp:56
armarx::armem::actions::MenuEntry::toIce
data::MenuEntryPtr toIce() const
Definition: actions.cpp:24
armarx::armem::actions::Menu::fromIce
static Menu fromIce(const data::MenuPtr &ice)
Definition: actions.cpp:103
armarx::armem::actions::Menu::add
MenuEntry & add(const std::string &id, const std::string &text, const std::vector< MenuEntry > &entries={})
Definition: actions.cpp:86
armarx::armem::actions::MenuEntry::MenuEntry
MenuEntry(const std::string &id, const std::string &text, const std::vector< MenuEntry > &entries={})
Definition: actions.cpp:8
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::armem::actions::MenuEntry::add
MenuEntry & add(const std::string &id, const std::string &text, const std::vector< MenuEntry > &entries={})
Definition: actions.cpp:16
armarx::armem::actions::SubMenu::add
MenuEntry & add(const std::string &id, const std::string &text, const std::vector< MenuEntry > &entries={})
Definition: actions.cpp:68
armarx::armem::actions
Definition: actions.cpp:5
armarx::armem::actions::MenuEntry::id
std::string id
Definition: actions.h:28
armarx::armem::actions::Menu
Definition: actions.h:51