7 #ifndef __dg_command_bind_h__ 8 #define __dg_command_bind_h__ 23 #include "dynamic-graph/command.h" 24 #include <boost/assign/list_of.hpp> 25 #include <boost/bind.hpp> 26 #include <boost/function.hpp> 33 CommandVoid0(E &entity, boost::function<
void(
void)>
function,
34 const std::string &docString)
35 :
Command(entity, EMPTY_ARG, docString), fptr(
function) {}
45 boost::function<void(void)> fptr;
50 boost::function<
void(
void)>
function,
51 const std::string &docString) {
57 boost::function<
void(E *)>
function,
58 const std::string &docString) {
59 return new CommandVoid0<E>(entity, boost::bind(
function, &entity), docString);
64 const std::string &docString) {
65 return new CommandVoid0<E>(entity, boost::bind(
function, &entity), docString);
68 inline std::string docCommandVoid0(
const std::string &doc) {
69 return std::string(
"\n") + doc +
"\n\nNo input.\nVoid return.\n\n";
80 typedef boost::function<void(const T &)> function_t;
82 CommandVoid1(E &entity, function_t
function,
const std::string &docString)
99 template <
class E,
typename T>
101 makeCommandVoid1(E &entity, boost::function<
void(
const T &)>
function,
103 const std::string &docString) {
107 template <
class E,
typename T>
109 makeCommandVoid1(E &entity,
112 boost::function<
void(E *,
const T &)>
function,
113 const std::string &docString) {
118 template <
class E,
typename T>
120 const std::string &docString) {
126 inline std::string docCommandVoid1(
const std::string &doc,
127 const std::string &type) {
128 return std::string(
"\n") + doc +
"\n\nInput:\n - A " + type +
129 ".\nVoid return.\n\n";
139 template <
class E,
typename T1,
typename T2>
141 typedef boost::function<void(const T1 &, const T2 &)> function_t;
143 CommandVoid2(E &entity, function_t
function,
const std::string &docString)
163 template <
class E,
typename T1,
typename T2>
165 makeCommandVoid2(E &entity,
166 boost::function<
void(
const T1 &,
const T2 &)>
function,
167 const std::string &docString) {
171 template <
class E,
typename T1,
typename T2>
173 makeCommandVoid2(E &entity,
176 boost::function<
void(E *,
const T1 &,
const T2 &)>
function,
177 const std::string &docString) {
179 entity, boost::bind(
function, &entity, _1, _2), docString);
182 template <
class E,
typename T1,
typename T2>
184 makeCommandVoid2(E &entity,
void (E::*
function)(
const T1 &,
const T2 &),
185 const std::string &docString) {
187 entity, boost::bind(
function, &entity, _1, _2), docString);
191 inline std::string docCommandVoid2(
const std::string &doc,
192 const std::string &type1,
193 const std::string &type2) {
194 return (std::string(
"\n") + doc +
"\n\n" +
"Input:\n - A " + type1 +
".\n" +
195 "Input:\n - A " + type2 +
".\n" +
"Void return.\n\n");
205 template <
class E,
typename T1,
typename T2,
typename T3>
207 typedef boost::function<void(const T1 &, const T2 &, const T3 &)> function_t;
209 CommandVoid3(E &entity, function_t
function,
const std::string &docString)
222 fptr(val1, val2, val3);
230 template <
class E,
typename T1,
typename T2,
typename T3>
232 makeCommandVoid3(E &entity,
233 typename CommandVoid3<E, T1, T2, T3>::function_t
function,
234 const std::string &docString) {
238 template <
class E,
typename T1,
typename T2,
typename T3>
243 boost::function<
void(E *,
const T1 &,
const T2 &,
const T3 &)>
function,
244 const std::string &docString) {
246 entity, boost::bind(
function, &entity, _1, _2, _3), docString);
249 template <
class E,
typename T1,
typename T2,
typename T3>
251 makeCommandVoid3(E &entity,
252 void (E::*
function)(
const T1 &,
const T2 &,
const T3 &),
253 const std::string &docString) {
255 entity, boost::bind(
function, &entity, _1, _2, _3), docString);
259 inline std::string docCommandVoid3(
const std::string &doc,
260 const std::string &type1,
261 const std::string &type2,
262 const std::string &type3) {
263 return (std::string(
"\n") + doc +
"\n\n" +
"Input:\n - A " + type1 +
".\n" +
264 "Input:\n - A " + type2 +
".\n" +
"Input:\n - A " + type3 +
".\n" +
275 template <
class E,
typename T1,
typename T2,
typename T3,
typename T4>
277 typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &)>
279 typedef void (E::*memberFunction_ptr_t)(
const T1 &,
const T2 &,
const T3 &,
282 CommandVoid4(E &entity, function_t
function,
const std::string &docString)
297 fptr(val1, val2, val3, val4);
305 template <
class E,
typename T1,
typename T2,
typename T3,
typename T4>
307 makeCommandVoid4(E &entity,
308 typename CommandVoid4<E, T1, T2, T3, T4>::function_t
function,
309 const std::string &docString) {
313 template <
class E,
typename T1,
typename T2,
typename T3,
typename T4>
316 boost::function<
void(E *,
const T1 &,
const T2 &,
const T3 &,
const T4 &)>
318 const std::string &docString) {
320 entity, boost::bind(
function, &entity, _1, _2, _3, _4), docString);
323 template <
class E,
typename T1,
typename T2,
typename T3,
typename T4>
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);
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");
353 typedef boost::function<void(std::ostream &)> function_t;
355 CommandVerbose(E &entity, function_t
function,
const std::string &docString)
356 :
Command(entity, EMPTY_ARG, docString), fptr(
function) {}
361 std::ostringstream oss;
363 return Value(oss.str());
372 makeCommandVerbose(E &entity,
typename CommandVerbose<E>::function_t
function,
373 const std::string &docString) {
380 void (E::*
function)(std::ostream &),
381 const std::string &docString) {
387 inline std::string docCommandVerbose(
const std::string &doc) {
388 return std::string(
"\n") + doc +
"\n\nNo input.\n Return a string.\n\n";
394 template <
class E,
class ReturnType>
397 const std::string &docString)
398 :
Command(entity, EMPTY_ARG, docString), fptr(
function) {}
409 boost::function<ReturnType(void)> fptr;
412 template <
class E,
class ReturnType>
414 makeCommandReturnType0(E &entity, boost::function<ReturnType(
void)>
function,
415 const std::string &docString) {
419 template <
class E,
class ReturnType>
421 makeCommandReturnType0(E &entity, boost::function<ReturnType(E *)>
function,
422 const std::string &docString) {
424 entity, boost::bind(
function, &entity), docString);
427 template <
class E,
class ReturnType>
429 makeCommandReturnType0(E &entity, ReturnType (E::*
function)(
void),
430 const std::string &docString) {
432 entity, boost::bind(
function, &entity), docString);
435 template <
typename ReturnType>
436 inline std::string docCommandReturnType0(
const std::string &doc,
437 const std::string &return_type) {
438 return std::string(
"\n") + doc +
"\n\nNo input.\n" +
439 typeid(ReturnType).name() +
" return.\n\n";
449 template <
class E,
typename ReturnType,
typename T>
451 typedef boost::function<ReturnType(const T &)> function_t;
454 const std::string &docString)
463 Value res(fptr(val));
471 template <
class E,
typename ReturnType,
typename T>
473 makeCommandReturnType1(E &entity,
474 boost::function<ReturnType(
const T &)>
function,
475 const std::string &docString) {
479 template <
class E,
typename ReturnType,
typename T>
481 makeCommandReturnType1(E &entity,
484 boost::function<ReturnType(E *,
const T &)>
function,
485 const std::string &docString) {
487 entity, boost::bind(
function, &entity, _1), docString);
490 template <
class E,
typename ReturnType,
typename T>
492 makeCommandReturnType1(E &entity, ReturnType (E::*
function)(
const T &),
493 const std::string &docString) {
495 entity, boost::bind(
function, &entity, _1), docString);
499 template <
typename ReturnType>
500 inline std::string docCommandReturnType1(
const std::string &doc,
501 const std::string &type) {
502 return std::string(
"\n") + doc +
"\n\nInput:\n - A " + type +
".\n" +
503 typeid(ReturnType).name() +
"return.\n\n";
513 template <
class E,
typename ReturnType,
typename T1,
typename T2>
515 typedef boost::function<ReturnType(const T1 &, const T2 &)> function_t;
518 const std::string &docString)
538 template <
class E,
typename ReturnType,
typename T1,
typename T2>
540 E &entity, boost::function<ReturnType(
const T1 &,
const T2 &)>
function,
541 const std::string &docString) {
546 template <
class E,
typename ReturnType,
typename T1,
typename T2>
551 boost::function<ReturnType(E *,
const T1 &,
const T2 &)>
function,
552 const std::string &docString) {
554 entity, boost::bind(
function, &entity, _1, _2), docString);
557 template <
class E,
typename ReturnType,
typename T1,
typename T2>
559 makeCommandReturnType2(E &entity,
560 ReturnType (E::*
function)(
const T1 &,
const T2 &),
561 const std::string &docString) {
563 entity, boost::bind(
function, &entity, _1, _2), docString);
567 template <
typename ReturnType>
568 inline std::string docCommandReturnType2(
const std::string &doc,
569 const std::string &type1,
570 const std::string &type2) {
571 return (std::string(
"\n") + doc +
"\n\n" +
"Input:\n - A " + type1 +
".\n" +
572 "Input:\n - A " + type2 +
".\n" +
573 "ReturnType:\n - Returns:" +
typeid(ReturnType).name() + +
".\n\n");
579 #endif // __dg_command_bind_h__ virtual Value doExecute()
Specific action performed by the command.
Command(Entity &entity, const std::vector< Value::Type > &valueTypes, const std::string &docstring)
This class implements a variant design pattern to handle basic types in Command.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.
const std::vector< Value > & getParameterValues() const
Get parameter values.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.
virtual Value doExecute()
Specific action performed by the command.