command-bind.h
Go to the documentation of this file.
1 //
2 // Copyright 2010 CNRS
3 //
4 // Author: Nicolas Mansard
5 //
6 
7 #ifndef __dg_command_bind_h__
8 #define __dg_command_bind_h__
9 
10 /* Create a command from a bind directly. Examples are:
11 
12  * addCommand("myProcVoid",
13  * makeCommandVoid0(*this,&ClassName::functionNoArg,
14  * docCommandVoid0("Simple line doc here.")));
15 
16  * addCommand("myProcOneString",
17  * makeCommandVoid1(*this,&EntityName::functionOneStringArg,
18  * docCommandVoid1("Simple line doc here.",
19  * "string")));
20  *
21  */
22 
23 #include <boost/assign/list_of.hpp>
24 #include <boost/bind.hpp>
25 #include <boost/function.hpp>
26 
27 #include "dynamic-graph/command.h"
28 
29 /* --- FUNCTION 0 ARGS ----------------------------------------------------- */
30 namespace dynamicgraph {
31 namespace command {
32 
33 template <class E>
34 struct CommandVoid0 : public Command {
35  CommandVoid0(E &entity, boost::function<void(void)> function,
36  const std::string &docString)
37  : Command(entity, EMPTY_ARG, docString), fptr(function) {}
38 
39  protected:
40  virtual Value doExecute() {
41  assert(getParameterValues().size() == 0);
42  fptr();
43  return Value(); // void
44  }
45 
46  private:
47  boost::function<void(void)> fptr;
48 };
49 
50 template <class E>
52  boost::function<void(void)> function,
53  const std::string &docString) {
54  return new CommandVoid0<E>(entity, function, docString);
55 }
56 
57 template <class E>
59  boost::function<void(E *)> function,
60  const std::string &docString) {
61  return new CommandVoid0<E>(entity, boost::bind(function, &entity), docString);
62 }
63 
64 template <class E>
65 CommandVoid0<E> *makeCommandVoid0(E &entity, void (E::*function)(void),
66  const std::string &docString) {
67  return new CommandVoid0<E>(entity, boost::bind(function, &entity), docString);
68 }
69 
70 inline std::string docCommandVoid0(const std::string &doc) {
71  return std::string("\n") + doc + "\n\nNo input.\nVoid return.\n\n";
72 }
73 
74 } // namespace command
75 } // namespace dynamicgraph
76 
77 /* --- FUNCTION 1 ARGS ------------------------------------------------------ */
78 namespace dynamicgraph {
79 namespace command {
80 
81 template <class E, typename T>
82 struct CommandVoid1 : public Command {
83  typedef boost::function<void(const T &)> function_t;
84 
85  CommandVoid1(E &entity, function_t function, const std::string &docString)
86  : Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
87  docString),
88  fptr(function) {}
89 
90  protected:
91  virtual Value doExecute() {
92  assert(getParameterValues().size() == 1);
93  T val = getParameterValues()[0].value();
94  fptr(val);
95  return Value(); // void
96  }
97 
98  private:
99  function_t fptr;
100 };
101 
102 template <class E, typename T>
104  E &entity, boost::function<void(const T &)> function,
105  // typename CommandVoid1<E,T>::function_t function ,
106  const std::string &docString) {
107  return new CommandVoid1<E, T>(entity, function, docString);
108 }
109 
110 template <class E, typename T>
112  E &entity,
113  // The following syntaxt don't compile when not specializing
114  // the template arg... why ???
115  boost::function<void(E *, const T &)> function,
116  const std::string &docString) {
117  return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1),
118  docString);
119 }
120 
121 template <class E, typename T>
122 CommandVoid1<E, T> *makeCommandVoid1(E &entity, void (E::*function)(const T &),
123  const std::string &docString) {
124  return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1),
125  docString);
126  return NULL;
127 }
128 
129 inline std::string docCommandVoid1(const std::string &doc,
130  const std::string &type) {
131  return std::string("\n") + doc + "\n\nInput:\n - A " + type +
132  ".\nVoid return.\n\n";
133 }
134 
135 } // namespace command
136 } // namespace dynamicgraph
137 
138 /* --- FUNCTION 2 ARGS ------------------------------------------------------ */
139 namespace dynamicgraph {
140 namespace command {
141 
142 template <class E, typename T1, typename T2>
143 struct CommandVoid2 : public Command {
144  typedef boost::function<void(const T1 &, const T2 &)> function_t;
145 
146  CommandVoid2(E &entity, function_t function, const std::string &docString)
147  : Command(entity,
148  boost::assign::list_of(ValueHelper<T1>::TypeID)(
149  ValueHelper<T2>::TypeID),
150  docString),
151  fptr(function) {}
152 
153  protected:
154  virtual Value doExecute() {
155  assert(getParameterValues().size() == 2);
156  T1 val1 = getParameterValues()[0].value();
157  T2 val2 = getParameterValues()[1].value();
158  fptr(val1, val2);
159  return Value(); // void
160  }
161 
162  private:
163  function_t fptr;
164 };
165 
166 template <class E, typename T1, typename T2>
168  E &entity, boost::function<void(const T1 &, const T2 &)> function,
169  const std::string &docString) {
170  return new CommandVoid2<E, T1, T2>(entity, function, docString);
171 }
172 
173 template <class E, typename T1, typename T2>
175  E &entity,
176  // The following syntaxt don't compile when not specializing
177  // the template arg... why ???
178  boost::function<void(E *, const T1 &, const T2 &)> function,
179  const std::string &docString) {
180  return new CommandVoid2<E, T1, T2>(
181  entity, boost::bind(function, &entity, _1, _2), docString);
182 }
183 
184 template <class E, typename T1, typename T2>
186  void (E::*function)(const T1 &,
187  const T2 &),
188  const std::string &docString) {
189  return new CommandVoid2<E, T1, T2>(
190  entity, boost::bind(function, &entity, _1, _2), docString);
191  return NULL;
192 }
193 
194 inline std::string docCommandVoid2(const std::string &doc,
195  const std::string &type1,
196  const std::string &type2) {
197  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
198  "Input:\n - A " + type2 + ".\n" + "Void return.\n\n");
199 }
200 
201 } // namespace command
202 } // namespace dynamicgraph
203 
204 /* --- FUNCTION 3 ARGS ------------------------------------------------------ */
205 namespace dynamicgraph {
206 namespace command {
207 
208 template <class E, typename T1, typename T2, typename T3>
209 struct CommandVoid3 : public Command {
210  typedef boost::function<void(const T1 &, const T2 &, const T3 &)> function_t;
211 
212  CommandVoid3(E &entity, function_t function, const std::string &docString)
213  : Command(entity,
214  boost::assign::list_of(ValueHelper<T1>::TypeID)(
215  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID),
216  docString),
217  fptr(function) {}
218 
219  protected:
220  virtual Value doExecute() {
221  assert(getParameterValues().size() == 3);
222  T1 val1 = getParameterValues()[0].value();
223  T2 val2 = getParameterValues()[1].value();
224  T3 val3 = getParameterValues()[2].value();
225  fptr(val1, val2, val3);
226  return Value(); // void
227  }
228 
229  private:
230  function_t fptr;
231 };
232 
233 template <class E, typename T1, typename T2, typename T3>
235  E &entity, typename CommandVoid3<E, T1, T2, T3>::function_t function,
236  const std::string &docString) {
237  return new CommandVoid3<E, T1, T2, T3>(entity, function, docString);
238 }
239 
240 template <class E, typename T1, typename T2, typename T3>
242  E &entity,
243  // The following syntaxt don't compile when not specializing the template
244  // arg... why ???
245  boost::function<void(E *, const T1 &, const T2 &, const T3 &)> function,
246  const std::string &docString) {
247  return new CommandVoid3<E, T1, T2, T3>(
248  entity, boost::bind(function, &entity, _1, _2, _3), docString);
249 }
250 
251 template <class E, typename T1, typename T2, typename T3>
253  E &entity, void (E::*function)(const T1 &, const T2 &, const T3 &),
254  const std::string &docString) {
255  return new CommandVoid3<E, T1, T2, T3>(
256  entity, boost::bind(function, &entity, _1, _2, _3), docString);
257  return NULL;
258 }
259 
260 inline std::string docCommandVoid3(const std::string &doc,
261  const std::string &type1,
262  const std::string &type2,
263  const std::string &type3) {
264  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
265  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
266  "Void return.\n\n");
267 }
268 
269 } // namespace command
270 } // namespace dynamicgraph
271 
272 /* --- FUNCTION 4 ARGS ------------------------------------------------------ */
273 namespace dynamicgraph {
274 namespace command {
275 
276 template <class E, typename T1, typename T2, typename T3, typename T4>
277 struct CommandVoid4 : public Command {
278  typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &)>
280  typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
281  const T4 &);
282 
283  CommandVoid4(E &entity, function_t function, const std::string &docString)
284  : Command(entity,
285  boost::assign::list_of(ValueHelper<T1>::TypeID)(
286  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
287  ValueHelper<T4>::TypeID),
288  docString),
289  fptr(function) {}
290 
291  protected:
292  virtual Value doExecute() {
293  assert(getParameterValues().size() == 4);
294  T1 val1 = getParameterValues()[0].value();
295  T2 val2 = getParameterValues()[1].value();
296  T3 val3 = getParameterValues()[2].value();
297  T4 val4 = getParameterValues()[3].value();
298  fptr(val1, val2, val3, val4);
299  return Value(); // void
300  }
301 
302  private:
304 };
305 
306 template <class E, typename T1, typename T2, typename T3, typename T4>
308  E &entity, typename CommandVoid4<E, T1, T2, T3, T4>::function_t function,
309  const std::string &docString) {
310  return new CommandVoid4<E, T1, T2, T3, T4>(entity, function, docString);
311 }
312 
313 template <class E, typename T1, typename T2, typename T3, typename T4>
315  E &entity,
316  boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &)>
317  function,
318  const std::string &docString) {
320  entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
321 }
322 
323 template <class E, typename T1, typename T2, typename T3, typename T4>
325  E &entity,
326  void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &),
327  const std::string &docString) {
329  entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
330  return NULL;
331 }
332 
333 inline std::string docCommandVoid4(const std::string &doc,
334  const std::string &type1,
335  const std::string &type2,
336  const std::string &type3,
337  const std::string &type4) {
338  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
339  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
340  "Input:\n - A " + type4 + ".\n" + "Void return.\n\n");
341 }
342 
343 } // namespace command
344 } // namespace dynamicgraph
345 
346 /* --- FUNCTION 5 ARGS ------------------------------------------------------ */
347 namespace dynamicgraph {
348 namespace command {
349 
350 template <class E, typename T1, typename T2, typename T3, typename T4,
351  typename T5>
352 struct CommandVoid5 : public Command {
353  typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
354  const T5 &)>
356  typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
357  const T4 &, const T5 &);
358 
359  CommandVoid5(E &entity, function_t function, const std::string &docString)
360  : Command(entity,
361  boost::assign::list_of(ValueHelper<T1>::TypeID)(
362  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
363  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
364  docString),
365  fptr(function) {}
366 
367  protected:
368  virtual Value doExecute() {
369  assert(getParameterValues().size() == 5);
370  T1 val1 = getParameterValues()[0].value();
371  T2 val2 = getParameterValues()[1].value();
372  T3 val3 = getParameterValues()[2].value();
373  T4 val4 = getParameterValues()[3].value();
374  T5 val5 = getParameterValues()[4].value();
375  fptr(val1, val2, val3, val4, val5);
376  return Value(); // void
377  }
378 
379  private:
381 };
382 
383 template <class E, typename T1, typename T2, typename T3, typename T4,
384  typename T5>
386  E &entity,
388  const std::string &docString) {
389  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
390 }
391 
392 template <class E, typename T1, typename T2, typename T3, typename T4,
393  typename T5>
395  E &entity,
396  boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
397  const T5 &)>
398  function,
399  const std::string &docString) {
401  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5), docString);
402 }
403 
404 template <class E, typename T1, typename T2, typename T3, typename T4,
405  typename T5>
407  E &entity,
408  void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
409  const T5 &),
410  const std::string &docString) {
412  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5), docString);
413  return NULL;
414 }
415 
416 inline std::string docCommandVoid5(const std::string &doc,
417  const std::string &type1,
418  const std::string &type2,
419  const std::string &type3,
420  const std::string &type4,
421  const std::string &type5) {
422  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
423  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
424  "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
425  "Void return.\n\n");
426 }
427 
428 } // namespace command
429 } // namespace dynamicgraph
430 
431 /* --- FUNCTION 6 ARGS ------------------------------------------------------ */
432 namespace dynamicgraph {
433 namespace command {
434 
435 template <class E, typename T1, typename T2, typename T3, typename T4,
436  typename T5, typename T6>
437 struct CommandVoid6 : public Command {
438  typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
439  const T5 &, const T6 &)>
441  typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
442  const T4 &, const T5 &, const T6 &);
443 
444  CommandVoid6(E &entity, function_t function, const std::string &docString)
445  : Command(entity,
446  boost::assign::list_of(ValueHelper<T1>::TypeID)(
447  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
448  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
449  ValueHelper<T6>::TypeID),
450  docString),
451  fptr(function) {}
452 
453  protected:
454  virtual Value doExecute() {
455  assert(getParameterValues().size() == 6);
456  T1 val1 = getParameterValues()[0].value();
457  T2 val2 = getParameterValues()[1].value();
458  T3 val3 = getParameterValues()[2].value();
459  T4 val4 = getParameterValues()[3].value();
460  T5 val5 = getParameterValues()[4].value();
461  T6 val6 = getParameterValues()[5].value();
462  fptr(val1, val2, val3, val4, val5, val6);
463  return Value(); // void
464  }
465 
466  private:
468 };
469 
470 template <class E, typename T1, typename T2, typename T3, typename T4,
471  typename T5, typename T6>
473  E &entity,
475  const std::string &docString) {
476  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function,
477  docString);
478 }
479 
480 template <class E, typename T1, typename T2, typename T3, typename T4,
481  typename T5, typename T6>
483  E &entity,
484  boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
485  const T5 &, const T6 &)>
486  function,
487  const std::string &docString) {
489  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
490  docString);
491 }
492 
493 template <class E, typename T1, typename T2, typename T3, typename T4,
494  typename T5, typename T6>
496  E &entity,
497  void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
498  const T5 &, const T6 &),
499  const std::string &docString) {
501  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
502  docString);
503  return NULL;
504 }
505 
506 inline std::string docCommandVoid6(
507  const std::string &doc, const std::string &type1, const std::string &type2,
508  const std::string &type3, const std::string &type4,
509  const std::string &type5, const std::string &type6) {
510  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
511  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
512  "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
513  "Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
514 }
515 
516 } // namespace command
517 } // namespace dynamicgraph
518 
519 /* --- FUNCTION 7 ARGS ------------------------------------------------------ */
520 namespace dynamicgraph {
521 namespace command {
522 
523 template <class E, typename T1, typename T2, typename T3, typename T4,
524  typename T5, typename T6, typename T7>
525 struct CommandVoid7 : public Command {
526  typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
527  const T5 &, const T6 &, const T7 &)>
529  typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
530  const T4 &, const T5 &, const T6 &,
531  const T7 &);
532 
533  CommandVoid7(E &entity, function_t function, const std::string &docString)
534  : Command(entity,
535  boost::assign::list_of(ValueHelper<T1>::TypeID)(
536  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
537  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
538  ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
539  docString),
540  fptr(function) {}
541 
542  protected:
543  virtual Value doExecute() {
544  assert(getParameterValues().size() == 7);
545  T1 val1 = getParameterValues()[0].value();
546  T2 val2 = getParameterValues()[1].value();
547  T3 val3 = getParameterValues()[2].value();
548  T4 val4 = getParameterValues()[3].value();
549  T5 val5 = getParameterValues()[4].value();
550  T6 val6 = getParameterValues()[5].value();
551  T7 val7 = getParameterValues()[6].value();
552  fptr(val1, val2, val3, val4, val5, val6, val7);
553  return Value(); // void
554  }
555 
556  private:
558 };
559 
560 template <class E, typename T1, typename T2, typename T3, typename T4,
561  typename T5, typename T6, typename T7>
563  E &entity,
565  const std::string &docString) {
566  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function,
567  docString);
568 }
569 
570 template <class E, typename T1, typename T2, typename T3, typename T4,
571  typename T5, typename T6, typename T7>
573  E &entity,
574  boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
575  const T5 &, const T6 &, const T7 &)>
576  function,
577  const std::string &docString) {
579  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7),
580  docString);
581 }
582 
583 template <class E, typename T1, typename T2, typename T3, typename T4,
584  typename T5, typename T6, typename T7>
586  E &entity,
587  void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
588  const T5 &, const T6 &, const T7 &),
589  const std::string &docString) {
591  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7),
592  docString);
593  return NULL;
594 }
595 
596 inline std::string docCommandVoid7(
597  const std::string &doc, const std::string &type1, const std::string &type2,
598  const std::string &type3, const std::string &type4,
599  const std::string &type5, const std::string &type6,
600  const std::string &type7) {
601  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
602  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
603  "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
604  "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" +
605  "Void return.\n\n");
606 }
607 
608 } // namespace command
609 } // namespace dynamicgraph
610 
611 /* --- FUNCTION 8 ARGS ------------------------------------------------------ */
612 namespace dynamicgraph {
613 namespace command {
614 
615 template <class E, typename T1, typename T2, typename T3, typename T4,
616  typename T5, typename T6, typename T7, typename T8>
617 struct CommandVoid8 : public Command {
618  typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
619  const T5 &, const T6 &, const T7 &, const T8 &)>
621  typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
622  const T4 &, const T5 &, const T6 &,
623  const T7 &, const T8 &);
624 
625  CommandVoid8(E &entity, function_t function, const std::string &docString)
626  : Command(entity,
627  boost::assign::list_of(ValueHelper<T1>::TypeID)(
628  ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
629  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
630  ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID)(
631  ValueHelper<T8>::TypeID),
632  docString),
633  fptr(function) {}
634 
635  protected:
636  virtual Value doExecute() {
637  assert(getParameterValues().size() == 8);
638  T1 val1 = getParameterValues()[0].value();
639  T2 val2 = getParameterValues()[1].value();
640  T3 val3 = getParameterValues()[2].value();
641  T4 val4 = getParameterValues()[3].value();
642  T5 val5 = getParameterValues()[4].value();
643  T6 val6 = getParameterValues()[5].value();
644  T7 val7 = getParameterValues()[6].value();
645  T8 val8 = getParameterValues()[7].value();
646  fptr(val1, val2, val3, val4, val5, val6, val7, val8);
647  return Value(); // void
648  }
649 
650  private:
652 };
653 
654 template <class E, typename T1, typename T2, typename T3, typename T4,
655  typename T5, typename T6, typename T7, typename T8>
657  E &entity,
659  function,
660  const std::string &docString) {
661  return new CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8>(entity, function,
662  docString);
663 }
664 
665 template <class E, typename T1, typename T2, typename T3, typename T4,
666  typename T5, typename T6, typename T7, typename T8>
668  E &entity,
669  boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
670  const T5 &, const T6 &, const T7 &, const T8 &)>
671  function,
672  const std::string &docString) {
674  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7, _8),
675  docString);
676 }
677 
678 template <class E, typename T1, typename T2, typename T3, typename T4,
679  typename T5, typename T6, typename T7, typename T8>
681  E &entity,
682  void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
683  const T5 &, const T6 &, const T7 &, const T8 &),
684  const std::string &docString) {
686  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7, _8),
687  docString);
688  return NULL;
689 }
690 
691 inline std::string docCommandVoid8(
692  const std::string &doc, const std::string &type1, const std::string &type2,
693  const std::string &type3, const std::string &type4,
694  const std::string &type5, const std::string &type6,
695  const std::string &type7, const std::string &type8) {
696  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
697  "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
698  "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
699  "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" +
700  "Input:\n - A " + type8 + ".\n" + "Void return.\n\n");
701 }
702 
703 } // namespace command
704 } // namespace dynamicgraph
705 
706 /* --- FUNCTION VERBOSE ----------------------------------------------------- */
707 /* This bind a function void f( ostream& ) that display some results into
708  * a string f( void ) that return some string results. */
709 
710 namespace dynamicgraph {
711 namespace command {
712 template <class E>
713 struct CommandVerbose : public Command {
714  typedef boost::function<void(std::ostream &)> function_t;
715 
716  CommandVerbose(E &entity, function_t function, const std::string &docString)
717  : Command(entity, EMPTY_ARG, docString), fptr(function) {}
718 
719  protected:
720  virtual Value doExecute() {
721  assert(getParameterValues().size() == 0);
722  std::ostringstream oss;
723  fptr(oss);
724  return Value(oss.str()); // return string
725  }
726 
727  private:
728  function_t fptr;
729 };
730 
731 template <class E>
733  E &entity, typename CommandVerbose<E>::function_t function,
734  const std::string &docString) {
735  return new CommandVerbose<E>(entity, function, docString);
736  return NULL;
737 }
738 
739 template <class E>
741  void (E::*function)(std::ostream &),
742  const std::string &docString) {
743  return new CommandVerbose<E>(entity, boost::bind(function, &entity, _1),
744  docString);
745  return NULL;
746 }
747 
748 inline std::string docCommandVerbose(const std::string &doc) {
749  return std::string("\n") + doc + "\n\nNo input.\n Return a string.\n\n";
750 }
751 /*************************/
752 /* Template return types */
753 /*************************/
754 
755 template <class E, class ReturnType>
756 struct CommandReturnType0 : public Command {
757  CommandReturnType0(E &entity, boost::function<ReturnType(void)> function,
758  const std::string &docString)
759  : Command(entity, EMPTY_ARG, docString), fptr(function) {}
760 
761  protected:
762  virtual Value doExecute() {
763  assert(getParameterValues().size() == 0);
764  Value res(fptr());
765  return res;
766  }
767 
768  private:
769  boost::function<ReturnType(void)> fptr;
770 };
771 
772 template <class E, class ReturnType>
774  E &entity, boost::function<ReturnType(void)> function,
775  const std::string &docString) {
776  return new CommandReturnType0<E, ReturnType>(entity, function, docString);
777 }
778 
779 template <class E, class ReturnType>
781  E &entity, boost::function<ReturnType(E *)> function,
782  const std::string &docString) {
784  entity, boost::bind(function, &entity), docString);
785 }
786 
787 template <class E, class ReturnType>
789  E &entity, ReturnType (E::*function)(void), const std::string &docString) {
791  entity, boost::bind(function, &entity), docString);
792 }
793 
794 template <typename ReturnType>
795 inline std::string docCommandReturnType0(
796  const std::string &doc, const std::string & /* return_type */) {
797  return std::string("\n") + doc + "\n\nNo input.\n" +
798  typeid(ReturnType).name() + " return.\n\n";
799 }
800 
801 } // namespace command
802 } // namespace dynamicgraph
803 
804 /* --- FUNCTION 1 ARGS ------------------------------------------------------ */
805 namespace dynamicgraph {
806 namespace command {
807 
808 template <class E, typename ReturnType, typename T>
809 struct CommandReturnType1 : public Command {
810  typedef boost::function<ReturnType(const T &)> function_t;
811 
812  CommandReturnType1(E &entity, function_t function,
813  const std::string &docString)
814  : Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
815  docString),
816  fptr(function) {}
817 
818  protected:
819  virtual Value doExecute() {
820  assert(getParameterValues().size() == 1);
821  T val = getParameterValues()[0].value();
822  Value res(fptr(val));
823  return res;
824  }
825 
826  private:
827  function_t fptr;
828 };
829 
830 template <class E, typename ReturnType, typename T>
832  E &entity, boost::function<ReturnType(const T &)> function,
833  const std::string &docString) {
834  return new CommandReturnType1<E, ReturnType, T>(entity, function, docString);
835 }
836 
837 template <class E, typename ReturnType, typename T>
839  E &entity,
840  // The following syntaxt don't compile when not
841  // specializing the template arg... why ???
842  boost::function<ReturnType(E *, const T &)> function,
843  const std::string &docString) {
845  entity, boost::bind(function, &entity, _1), docString);
846 }
847 
848 template <class E, typename ReturnType, typename T>
850  E &entity, ReturnType (E::*function)(const T &),
851  const std::string &docString) {
853  entity, boost::bind(function, &entity, _1), docString);
854  return NULL;
855 }
856 
857 template <typename ReturnType>
858 inline std::string docCommandReturnType1(const std::string &doc,
859  const std::string &type) {
860  return std::string("\n") + doc + "\n\nInput:\n - A " + type + ".\n" +
861  typeid(ReturnType).name() + "return.\n\n";
862 }
863 
864 } // namespace command
865 } // namespace dynamicgraph
866 
867 /*********** FUNCTION 2 Arguments ************************/
868 namespace dynamicgraph {
869 namespace command {
870 
871 template <class E, typename ReturnType, typename T1, typename T2>
872 struct CommandReturnType2 : public Command {
873  typedef boost::function<ReturnType(const T1 &, const T2 &)> function_t;
874 
875  CommandReturnType2(E &entity, function_t function,
876  const std::string &docString)
877  : Command(entity,
878  boost::assign::list_of(ValueHelper<T1>::TypeID)(
879  ValueHelper<T2>::TypeID),
880  docString),
881  fptr(function) {}
882 
883  protected:
884  virtual Value doExecute() {
885  assert(getParameterValues().size() == 2);
886  T1 val1 = getParameterValues()[0].value();
887  T2 val2 = getParameterValues()[1].value();
888  Value res(fptr(val1, val2));
889  return res;
890  }
891 
892  private:
893  function_t fptr;
894 };
895 
896 template <class E, typename ReturnType, typename T1, typename T2>
898  E &entity, boost::function<ReturnType(const T1 &, const T2 &)> function,
899  const std::string &docString) {
900  return new CommandReturnType2<E, ReturnType, T1, T2>(entity, function,
901  docString);
902 }
903 
904 template <class E, typename ReturnType, typename T1, typename T2>
906  E &entity,
907  // The following syntaxt don't compile when not specializing the template
908  // arg... why ???
909  boost::function<ReturnType(E *, const T1 &, const T2 &)> function,
910  const std::string &docString) {
912  entity, boost::bind(function, &entity, _1, _2), docString);
913 }
914 
915 template <class E, typename ReturnType, typename T1, typename T2>
917  E &entity, ReturnType (E::*function)(const T1 &, const T2 &),
918  const std::string &docString) {
920  entity, boost::bind(function, &entity, _1, _2), docString);
921  return NULL;
922 }
923 
924 template <typename ReturnType>
925 inline std::string docCommandReturnType2(const std::string &doc,
926  const std::string &type1,
927  const std::string &type2) {
928  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
929  "Input:\n - A " + type2 + ".\n" +
930  "ReturnType:\n - Returns:" + typeid(ReturnType).name() + +".\n\n");
931 }
932 
933 } // namespace command
934 } // namespace dynamicgraph
935 
936 #endif // __dg_command_bind_h__
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: command-bind.h:506
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: command-bind.h:385
CommandVoid0< E > * makeCommandVoid0(E &entity, boost::function< void(void)> function, const std::string &docString)
Definition: command-bind.h:51
CommandVoid4(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:283
std::string docCommandReturnType2(const std::string &doc, const std::string &type1, const std::string &type2)
Definition: command-bind.h:925
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:543
CommandVoid2(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:146
CommandVoid3(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:212
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:50
boost::function< void(const T1 &, const T2 &)> function_t
Definition: command-bind.h:144
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:636
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:762
boost::function< void(std::ostream &)> function_t
Definition: command-bind.h:714
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &, const T8 &)> function_t
Definition: command-bind.h:620
boost::function< ReturnType(void)> fptr
Definition: command-bind.h:769
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
Definition: command-bind.h:103
std::string docCommandVoid1(const std::string &doc, const std::string &type)
Definition: command-bind.h:129
boost::function< void(void)> fptr
Definition: command-bind.h:47
std::string docCommandVoid4(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4)
Definition: command-bind.h:333
boost::function< ReturnType(const T &)> function_t
Definition: command-bind.h:810
CommandReturnType0< E, ReturnType > * makeCommandReturnType0(E &entity, boost::function< ReturnType(void)> function, const std::string &docString)
Definition: command-bind.h:773
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:819
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:40
std::string docCommandVoid0(const std::string &doc)
Definition: command-bind.h:70
std::string docCommandVoid3(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3)
Definition: command-bind.h:260
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: command-bind.h:416
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:91
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> function_t
Definition: command-bind.h:440
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:720
CommandVoid3< E, T1, T2, T3 > * makeCommandVoid3(E &entity, typename CommandVoid3< E, T1, T2, T3 >::function_t function, const std::string &docString)
Definition: command-bind.h:234
CommandVoid1(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:85
boost::function< ReturnType(const T1 &, const T2 &)> function_t
Definition: command-bind.h:873
boost::function< void(const T &)> function_t
Definition: command-bind.h:83
CommandVoid6(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:444
boost::function< void(const T1 &, const T2 &, const T3 &)> function_t
Definition: command-bind.h:210
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:884
CommandVoid4< E, T1, T2, T3, T4 > * makeCommandVoid4(E &entity, typename CommandVoid4< E, T1, T2, T3, T4 >::function_t function, const std::string &docString)
Definition: command-bind.h:307
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> function_t
Definition: command-bind.h:355
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> function_t
Definition: command-bind.h:528
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:292
static const std::vector< Value::Type > EMPTY_ARG
Definition: command.h:68
CommandReturnType2(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:875
std::string docCommandReturnType0(const std::string &doc, const std::string &)
Definition: command-bind.h:795
CommandReturnType2< E, ReturnType, T1, T2 > * makeCommandReturnType2(E &entity, boost::function< ReturnType(const T1 &, const T2 &)> function, const std::string &docString)
Definition: command-bind.h:897
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: command-bind.h:472
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:368
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:220
CommandVoid8(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:625
CommandVerbose< E > * makeCommandVerbose(E &entity, typename CommandVerbose< E >::function_t function, const std::string &docString)
Definition: command-bind.h:732
CommandVerbose(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:716
std::string docCommandReturnType1(const std::string &doc, const std::string &type)
Definition: command-bind.h:858
std::string docCommandVoid2(const std::string &doc, const std::string &type1, const std::string &type2)
Definition: command-bind.h:194
CommandReturnType0(E &entity, boost::function< ReturnType(void)> function, const std::string &docString)
Definition: command-bind.h:757
CommandVoid8< E, T1, T2, T3, T4, T5, T6, T7, T8 > * makeCommandVoid8(E &entity, typename CommandVoid8< E, T1, T2, T3, T4, T5, T6, T7, T8 >::function_t function, const std::string &docString)
Definition: command-bind.h:656
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48
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: command-bind.h:596
CommandReturnType1< E, ReturnType, T > * makeCommandReturnType1(E &entity, boost::function< ReturnType(const T &)> function, const std::string &docString)
Definition: command-bind.h:831
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:454
virtual Value doExecute()
Specific action performed by the command.
Definition: command-bind.h:154
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: command-bind.h:562
CommandVoid7(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:533
CommandVoid5(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:359
CommandReturnType1(E &entity, function_t function, const std::string &docString)
Definition: command-bind.h:812
std::string docCommandVoid8(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, const std::string &type8)
Definition: command-bind.h:691
CommandVoid0(E &entity, boost::function< void(void)> function, const std::string &docString)
Definition: command-bind.h:35
std::string docCommandVerbose(const std::string &doc)
Definition: command-bind.h:748
CommandVoid2< E, T1, T2 > * makeCommandVoid2(E &entity, boost::function< void(const T1 &, const T2 &)> function, const std::string &docString)
Definition: command-bind.h:167
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &)> function_t
Definition: command-bind.h:279


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03