sot-torque-control  1.5.2
commands-helper.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011, Nicolas Mansard, LAAS-CNRS
3  *
4  */
5 
6 #ifndef __sot_torquecontrol_commands_helper_H__
7 #define __sot_torquecontrol_commands_helper_H__
8 
9 #include <boost/function.hpp>
10 
11 /* --- COMMON INCLUDE -------------------------------------------------- */
12 #include <dynamic-graph/command.h>
13 #include <dynamic-graph/command-direct-setter.h>
14 #include <dynamic-graph/command-direct-getter.h>
15 #include <dynamic-graph/command-bind.h>
16 
17 /* --- HELPER ---------------------------------------------------------- */
18 namespace dynamicgraph {
19 namespace sot {
20 namespace torquecontrol {
21 using ::dynamicgraph::command::docCommandVerbose;
22 using ::dynamicgraph::command::docCommandVoid0;
23 using ::dynamicgraph::command::docCommandVoid1;
24 using ::dynamicgraph::command::docCommandVoid2;
25 using ::dynamicgraph::command::docDirectGetter;
26 using ::dynamicgraph::command::docDirectSetter;
27 using ::dynamicgraph::command::makeCommandVerbose;
28 using ::dynamicgraph::command::makeCommandVoid0;
29 using ::dynamicgraph::command::makeCommandVoid1;
30 using ::dynamicgraph::command::makeCommandVoid2;
31 using ::dynamicgraph::command::makeDirectGetter;
32 using ::dynamicgraph::command::makeDirectSetter;
33 } // namespace torquecontrol
34 } // namespace sot
35 } // namespace dynamicgraph
36 
37 namespace dynamicgraph {
38 namespace command {
39 
40 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
41 struct CommandVoid5 : public Command {
42  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&)> function_t;
43  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> memberFunction_t;
44  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&);
45 
46  CommandVoid5(E& entity, function_t function, const std::string& docString)
47  : Command(entity,
48  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
49  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
50  docString),
51  fptr(function) {}
52 
53  protected:
54  virtual Value doExecute() {
55  assert(getParameterValues().size() == 5);
56  T1 val1 = getParameterValues()[0].value();
57  T2 val2 = getParameterValues()[1].value();
58  T3 val3 = getParameterValues()[2].value();
59  T4 val4 = getParameterValues()[3].value();
60  T5 val5 = getParameterValues()[4].value();
61  fptr(val1, val2, val3, val4, val5);
62  return Value(); // void
63  }
64 
65  private:
66  function_t fptr;
67 };
68 
69 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
71  E& entity, typename CommandVoid5<E, T1, T2, T3, T4, T5>::function_t function, const std::string& docString) {
72  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
73 }
74 
75 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
77  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> function,
78  const std::string& docString) {
79  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
80  docString);
81 }
82 
83 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
85  void (E::*function)(const T1&, const T2&, const T3&, const T4&,
86  const T5&),
87  const std::string& docString) {
88  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
89  docString);
90  return NULL;
91 }
92 
93 inline std::string docCommandVoid5(const std::string& doc, const std::string& type1, const std::string& type2,
94  const std::string& type3, const std::string& type4, const std::string& type5) {
95  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
96  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
97  "Void return.\n\n");
98 }
99 
100 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
101 struct CommandVoid6 : public Command {
102  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function_t;
103  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> memberFunction_t;
104  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&);
105 
106  CommandVoid6(E& entity, function_t function, const std::string& docString)
107  : Command(entity,
108  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
109  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID),
110  docString),
111  fptr(function) {}
112 
113  protected:
114  virtual Value doExecute() {
115  assert(getParameterValues().size() == 6);
116  T1 val1 = getParameterValues()[0].value();
117  T2 val2 = getParameterValues()[1].value();
118  T3 val3 = getParameterValues()[2].value();
119  T4 val4 = getParameterValues()[3].value();
120  T5 val5 = getParameterValues()[4].value();
121  T6 val6 = getParameterValues()[5].value();
122  fptr(val1, val2, val3, val4, val5, val6);
123  return Value(); // void
124  }
125 
126  private:
127  function_t fptr;
128 };
129 
130 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
132  E& entity, typename CommandVoid6<E, T1, T2, T3, T4, T5, T6>::function_t function, const std::string& docString) {
133  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function, docString);
134 }
135 
136 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
138  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function,
139  const std::string& docString) {
140  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
141  docString);
142 }
143 
144 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
146  void (E::*function)(const T1&, const T2&, const T3&,
147  const T4&, const T5&, const T6&),
148  const std::string& docString) {
149  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
150  docString);
151  return NULL;
152 }
153 
154 inline std::string docCommandVoid6(const std::string& doc, const std::string& type1, const std::string& type2,
155  const std::string& type3, const std::string& type4, const std::string& type5,
156  const std::string& type6) {
157  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
158  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
159  "Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
160 }
161 
162 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
163 struct CommandVoid7 : public Command {
164  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
166  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
168  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&);
169 
170  CommandVoid7(E& entity, function_t function, const std::string& docString)
171  : Command(
172  entity,
173  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
174  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
175  docString),
176  fptr(function) {}
177 
178  protected:
179  virtual Value doExecute() {
180  assert(getParameterValues().size() == 7);
181  T1 val1 = getParameterValues()[0].value();
182  T2 val2 = getParameterValues()[1].value();
183  T3 val3 = getParameterValues()[2].value();
184  T4 val4 = getParameterValues()[3].value();
185  T5 val5 = getParameterValues()[4].value();
186  T6 val6 = getParameterValues()[5].value();
187  T7 val7 = getParameterValues()[6].value();
188  fptr(val1, val2, val3, val4, val5, val6, val7);
189  return Value(); // void
190  }
191 
192  private:
193  function_t fptr;
194 };
195 
196 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
198  E& entity, typename CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>::function_t function,
199  const std::string& docString) {
200  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function, docString);
201 }
202 
203 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
205  E& entity,
206  boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)> function,
207  const std::string& docString) {
209  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
210 }
211 
212 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
214  E& entity, void (E::*function)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&),
215  const std::string& docString) {
217  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
218  return NULL;
219 }
220 
221 inline std::string docCommandVoid7(const std::string& doc, const std::string& type1, const std::string& type2,
222  const std::string& type3, const std::string& type4, const std::string& type5,
223  const std::string& type6, const std::string& type7) {
224  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
225  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
226  "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" + "Void return.\n\n");
227 }
228 
229 } // namespace command
230 } // namespace dynamicgraph
231 
232 #endif // __sot_torquecontrol_commands_helper_H__
dynamicgraph::command::makeCommandVoid7
CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 > * makeCommandVoid7(E &entity, typename CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:197
dynamicgraph::command::makeCommandVoid6
CommandVoid6< E, T1, T2, T3, T4, T5, T6 > * makeCommandVoid6(E &entity, typename CommandVoid6< E, T1, T2, T3, T4, T5, T6 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:131
dynamicgraph::command::CommandVoid7::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:179
dynamicgraph::command::CommandVoid5::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> function_t
Definition: commands-helper.hh:42
dynamicgraph::command::CommandVoid5::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)
Definition: commands-helper.hh:44
dynamicgraph::command::CommandVoid7::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)
Definition: commands-helper.hh:168
dynamicgraph
to read text file
Definition: treeview.dox:22
dynamicgraph::command::CommandVoid5::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> memberFunction_t
Definition: commands-helper.hh:43
dynamicgraph::command::CommandVoid6::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)
Definition: commands-helper.hh:104
dynamicgraph::command::CommandVoid5
Definition: commands-helper.hh:41
dynamicgraph::command::CommandVoid5::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:54
dynamicgraph::command::CommandVoid5::CommandVoid5
CommandVoid5(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:46
dynamicgraph::command::CommandVoid7::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> function_t
Definition: commands-helper.hh:165
dynamicgraph::command::CommandVoid6
Definition: commands-helper.hh:101
dynamicgraph::command::CommandVoid7::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> memberFunction_t
Definition: commands-helper.hh:167
dynamicgraph::command::CommandVoid6::CommandVoid6
CommandVoid6(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:106
dynamicgraph::command::CommandVoid6::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> function_t
Definition: commands-helper.hh:102
dynamicgraph::command::CommandVoid7::CommandVoid7
CommandVoid7(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:170
dynamicgraph::command::docCommandVoid5
std::string docCommandVoid5(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5)
Definition: commands-helper.hh:93
dynamicgraph::command::docCommandVoid7
std::string docCommandVoid7(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5, const std::string &type6, const std::string &type7)
Definition: commands-helper.hh:221
dynamicgraph::command::makeCommandVoid5
CommandVoid5< E, T1, T2, T3, T4, T5 > * makeCommandVoid5(E &entity, typename CommandVoid5< E, T1, T2, T3, T4, T5 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:70
dynamicgraph::command::CommandVoid7
Definition: commands-helper.hh:163
dynamicgraph::command::CommandVoid6::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:114
dynamicgraph::command::docCommandVoid6
std::string docCommandVoid6(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5, const std::string &type6)
Definition: commands-helper.hh:154
dynamicgraph::command::CommandVoid6::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> memberFunction_t
Definition: commands-helper.hh:103