sot-talos-balance  1.5.0
commands-helper.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Gepetto team, LAAS-CNRS
3  *
4  * This file is part of sot-talos-balance.
5  * sot-talos-balance is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * sot-talos-balance is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with sot-talos-balance. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __sot_talos_balance_commands_helper_H__
18 #define __sot_talos_balance_commands_helper_H__
19 
20 /* --- COMMON INCLUDE -------------------------------------------------- */
21 #include <dynamic-graph/command.h>
22 #include <dynamic-graph/command-direct-setter.h>
23 #include <dynamic-graph/command-direct-getter.h>
24 #include <dynamic-graph/command-bind.h>
25 
26 #include <boost/function.hpp>
27 
28 /* --- HELPER ---------------------------------------------------------- */
29 namespace dynamicgraph {
30  namespace sot {
31  namespace talos_balance {
32  using ::dynamicgraph::command::makeDirectGetter;
33  using ::dynamicgraph::command::docDirectGetter;
34  using ::dynamicgraph::command::makeDirectSetter;
35  using ::dynamicgraph::command::docDirectSetter;
36  using ::dynamicgraph::command::makeCommandVoid0;
37  using ::dynamicgraph::command::docCommandVoid0;
38  using ::dynamicgraph::command::makeCommandVoid1;
39  using ::dynamicgraph::command::docCommandVoid1;
40  using ::dynamicgraph::command::makeCommandVoid2;
41  using ::dynamicgraph::command::docCommandVoid2;
42  using ::dynamicgraph::command::makeCommandVerbose;
43  using ::dynamicgraph::command::docCommandVerbose;
44  } // namespace talos_balance
45  } // namespace sot
46 } // namespace dynamicgraph
47 
48 namespace dynamicgraph {
49  namespace command {
50 
51  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5>
52  struct CommandVoid5
53  : public Command
54  {
55  typedef boost::function<void(const T1&,const T2&,const T3&,const T4&,const T5&)> function_t;
56  typedef boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&)> memberFunction_t;
57  typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&,const T3&,const T4&,const T5&);
58 
59  CommandVoid5(E& entity, function_t function,
60  const std::string& docString)
61  :Command(entity,
62  boost::assign::list_of
63  (ValueHelper<T1>::TypeID)
64  (ValueHelper<T2>::TypeID)
65  (ValueHelper<T3>::TypeID)
66  (ValueHelper<T4>::TypeID)
67  (ValueHelper<T5>::TypeID)
68  , docString)
69  ,fptr(function)
70  {}
71 
72  protected:
73  virtual Value doExecute()
74  {
75  assert( getParameterValues().size() == 5 );
76  T1 val1 = getParameterValues()[0].value();
77  T2 val2 = getParameterValues()[1].value();
78  T3 val3 = getParameterValues()[2].value();
79  T4 val4 = getParameterValues()[3].value();
80  T5 val5 = getParameterValues()[4].value();
81  fptr(val1,val2,val3,val4,val5);
82  return Value(); // void
83  }
84  private:
85  function_t fptr;
86  };
87 
88 
89  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5>
91  makeCommandVoid5(E& entity,
93  const std::string& docString)
94  {
95  return new CommandVoid5<E,T1,T2,T3,T4,T5>( entity,function,docString );
96  }
97 
98  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5>
100  makeCommandVoid5(E& entity,
101  boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&)> function,
102  const std::string& docString)
103  {
104  return new CommandVoid5<E,T1,T2,T3,T4,T5>( entity,
105  boost::bind(function,&entity,_1,_2,_3,_4,_5),docString );
106  }
107 
108  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5>
110  makeCommandVoid5(E& entity,
111  void (E::*function) (const T1&,const T2&,const T3&,const T4&,const T5&),
112  const std::string& docString)
113  {
114  return new CommandVoid5<E,T1,T2,T3,T4,T5>( entity,
115  boost::bind(function,&entity,_1,_2,_3,_4,_5),
116  docString );
117  return NULL;
118  }
119 
120  inline std::string docCommandVoid5( const std::string& doc,
121  const std::string& type1,
122  const std::string& type2,
123  const std::string& type3,
124  const std::string& type4,
125  const std::string& type5)
126  {
127  return (std::string("\n")+doc+"\n\n"
128  +"Input:\n - A "+type1+".\n"
129  +"Input:\n - A "+type2+".\n"
130  +"Input:\n - A "+type3+".\n"
131  +"Input:\n - A "+type4+".\n"
132  +"Input:\n - A "+type5+".\n"
133  +"Void return.\n\n" );
134  }
135 
136  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6 >
138  : public Command
139  {
140  typedef boost::function<void(const T1&,const T2&,const T3&,const T4&,const T5&,const T6&)> function_t;
141  typedef boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&,const T6&)> memberFunction_t;
142  typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&,const T3&,const T4&,const T5&,const T6&);
143 
144  CommandVoid6(E& entity, function_t function,
145  const std::string& docString)
146  :Command(entity,
147  boost::assign::list_of
148  (ValueHelper<T1>::TypeID)
149  (ValueHelper<T2>::TypeID)
150  (ValueHelper<T3>::TypeID)
151  (ValueHelper<T4>::TypeID)
152  (ValueHelper<T5>::TypeID)
153  (ValueHelper<T6>::TypeID)
154  , docString)
155  ,fptr(function)
156  {}
157 
158  protected:
159  virtual Value doExecute()
160  {
161  assert( getParameterValues().size() == 6 );
162  T1 val1 = getParameterValues()[0].value();
163  T2 val2 = getParameterValues()[1].value();
164  T3 val3 = getParameterValues()[2].value();
165  T4 val4 = getParameterValues()[3].value();
166  T5 val5 = getParameterValues()[4].value();
167  T6 val6 = getParameterValues()[5].value();
168  fptr(val1,val2,val3,val4,val5,val6);
169  return Value(); // void
170  }
171  private:
172  function_t fptr;
173  };
174 
175 
176  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6 >
178  makeCommandVoid6(E& entity,
180  const std::string& docString)
181  {
182  return new CommandVoid6<E,T1,T2,T3,T4,T5,T6>( entity,function,docString );
183  }
184 
185  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6 >
187  makeCommandVoid6(E& entity,
188  boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&,const T6&)> function,
189  const std::string& docString)
190  {
191  return new CommandVoid6<E,T1,T2,T3,T4,T5,T6>( entity,
192  boost::bind(function,&entity,_1,_2,_3,_4,_5,_6),docString );
193  }
194 
195  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6 >
197  makeCommandVoid6(E& entity,
198  void (E::*function) (const T1&,const T2&,const T3&,const T4&,const T5&,const T6&),
199  const std::string& docString)
200  {
201  return new CommandVoid6<E,T1,T2,T3,T4,T5,T6>( entity,
202  boost::bind(function,&entity,_1,_2,_3,_4,_5,_6),
203  docString );
204  return NULL;
205  }
206 
207  inline std::string docCommandVoid6( const std::string& doc,
208  const std::string& type1,
209  const std::string& type2,
210  const std::string& type3,
211  const std::string& type4,
212  const std::string& type5,
213  const std::string& type6)
214  {
215  return (std::string("\n")+doc+"\n\n"
216  +"Input:\n - A "+type1+".\n"
217  +"Input:\n - A "+type2+".\n"
218  +"Input:\n - A "+type3+".\n"
219  +"Input:\n - A "+type4+".\n"
220  +"Input:\n - A "+type5+".\n"
221  +"Input:\n - A "+type6+".\n"
222  +"Void return.\n\n" );
223  }
224 
225  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7 >
227  : public Command
228  {
229  typedef boost::function<void(const T1&,const T2&,const T3&,const T4&,const T5&,const T6&,const T7&)> function_t;
230  typedef boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&,const T6&,const T7&)> memberFunction_t;
231  typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&,const T3&,const T4&,const T5&,const T6&,const T7&);
232 
233  CommandVoid7(E& entity, function_t function,
234  const std::string& docString)
235  :Command(entity,
236  boost::assign::list_of
237  (ValueHelper<T1>::TypeID)
238  (ValueHelper<T2>::TypeID)
239  (ValueHelper<T3>::TypeID)
240  (ValueHelper<T4>::TypeID)
241  (ValueHelper<T5>::TypeID)
242  (ValueHelper<T6>::TypeID)
243  (ValueHelper<T7>::TypeID)
244  , docString)
245  ,fptr(function)
246  {}
247 
248  protected:
249  virtual Value doExecute()
250  {
251  assert( getParameterValues().size() == 7 );
252  T1 val1 = getParameterValues()[0].value();
253  T2 val2 = getParameterValues()[1].value();
254  T3 val3 = getParameterValues()[2].value();
255  T4 val4 = getParameterValues()[3].value();
256  T5 val5 = getParameterValues()[4].value();
257  T6 val6 = getParameterValues()[5].value();
258  T7 val7 = getParameterValues()[6].value();
259  fptr(val1,val2,val3,val4,val5,val6,val7);
260  return Value(); // void
261  }
262  private:
263  function_t fptr;
264  };
265 
266 
267  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7 >
269  makeCommandVoid7(E& entity,
271  const std::string& docString)
272  {
273  return new CommandVoid7<E,T1,T2,T3,T4,T5,T6,T7>( entity,function,docString );
274  }
275 
276  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7 >
278  makeCommandVoid7(E& entity,
279  boost::function<void(E*,const T1&,const T2&,const T3&,const T4&,const T5&,const T6&,const T7&)> function,
280  const std::string& docString)
281  {
282  return new CommandVoid7<E,T1,T2,T3,T4,T5,T6,T7>( entity,
283  boost::bind(function,&entity,_1,_2,_3,_4,_5,_6,_7),docString );
284  }
285 
286  template <class E,typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7 >
288  makeCommandVoid7(E& entity,
289  void (E::*function) (const T1&,const T2&,const T3&,const T4&,const T5&,const T6&,const T7&),
290  const std::string& docString)
291  {
292  return new CommandVoid7<E,T1,T2,T3,T4,T5,T6,T7>( entity,
293  boost::bind(function,&entity,_1,_2,_3,_4,_5,_6,_7),
294  docString );
295  return NULL;
296  }
297 
298  inline std::string docCommandVoid7( const std::string& doc,
299  const std::string& type1,
300  const std::string& type2,
301  const std::string& type3,
302  const std::string& type4,
303  const std::string& type5,
304  const std::string& type6,
305  const std::string& type7)
306  {
307  return (std::string("\n")+doc+"\n\n"
308  +"Input:\n - A "+type1+".\n"
309  +"Input:\n - A "+type2+".\n"
310  +"Input:\n - A "+type3+".\n"
311  +"Input:\n - A "+type4+".\n"
312  +"Input:\n - A "+type5+".\n"
313  +"Input:\n - A "+type6+".\n"
314  +"Input:\n - A "+type7+".\n"
315  +"Void return.\n\n" );
316  }
317 
318 
319  } // namespace command
320 } // namespace dynamicgraph
321 
322 
323 
324 #endif // __sot_talos_balance_commands_helper_H__
325 
326 
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)
CommandVoid6< E, T1, T2, T3, T4, T5, T6 > * makeCommandVoid6(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &), const std::string &docString)
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> memberFunction_t
CommandVoid5(E &entity, function_t function, const std::string &docString)
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> function_t
CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 > * makeCommandVoid7(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &), const std::string &docString)
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)
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> function_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> memberFunction_t
CommandVoid5< E, T1, T2, T3, T4, T5 > * makeCommandVoid5(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &), const std::string &docString)
CommandVoid7(E &entity, function_t function, const std::string &docString)
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> memberFunction_t
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)
CommandVoid6(E &entity, function_t function, const std::string &docString)