commands-helper.hh 12 KB
Newer Older
andreadelprete's avatar
andreadelprete committed
1
2
3
4
5
6
7
8
/*
 * Copyright 2011, Nicolas Mansard, LAAS-CNRS
 *
 */

#ifndef __sot_torquecontrol_commands_helper_H__
#define __sot_torquecontrol_commands_helper_H__

9
10
#include <boost/function.hpp>

andreadelprete's avatar
andreadelprete committed
11
/* --- COMMON INCLUDE -------------------------------------------------- */
12
#include <dynamic-graph/config.hh>
andreadelprete's avatar
andreadelprete committed
13
14
15
16
17
18
19
#include <dynamic-graph/command.h>
#include <dynamic-graph/command-direct-setter.h>
#include <dynamic-graph/command-direct-getter.h>
#include <dynamic-graph/command-bind.h>

/* --- HELPER ---------------------------------------------------------- */
namespace dynamicgraph {
Guilhem Saurel's avatar
Guilhem Saurel committed
20
namespace sot {
Guilhem Saurel's avatar
Guilhem Saurel committed
21
namespace dg = dynamicgraph;
Guilhem Saurel's avatar
Guilhem Saurel committed
22
23
24
25
26
namespace torquecontrol {
using ::dynamicgraph::command::docCommandVerbose;
using ::dynamicgraph::command::docCommandVoid0;
using ::dynamicgraph::command::docCommandVoid1;
using ::dynamicgraph::command::docCommandVoid2;
27
28
using ::dynamicgraph::command::docCommandVoid3;
using ::dynamicgraph::command::docCommandVoid4;
Guilhem Saurel's avatar
Guilhem Saurel committed
29
30
31
32
33
34
using ::dynamicgraph::command::docDirectGetter;
using ::dynamicgraph::command::docDirectSetter;
using ::dynamicgraph::command::makeCommandVerbose;
using ::dynamicgraph::command::makeCommandVoid0;
using ::dynamicgraph::command::makeCommandVoid1;
using ::dynamicgraph::command::makeCommandVoid2;
35
36
using ::dynamicgraph::command::makeCommandVoid3;
using ::dynamicgraph::command::makeCommandVoid4;
Guilhem Saurel's avatar
Guilhem Saurel committed
37
38
39
40
41
using ::dynamicgraph::command::makeDirectGetter;
using ::dynamicgraph::command::makeDirectSetter;
}  // namespace torquecontrol
}  // namespace sot
}  // namespace dynamicgraph
andreadelprete's avatar
andreadelprete committed
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#if DYNAMIC_GRAPH_VERSION_AT_LEAST(4, 4, 0)
namespace dynamicgraph {
namespace sot {
namespace dg = dynamicgraph;
namespace torquecontrol {
using ::dynamicgraph::command::docCommandVoid5;
using ::dynamicgraph::command::docCommandVoid6;
using ::dynamicgraph::command::docCommandVoid7;
using ::dynamicgraph::command::docCommandVoid8;
using ::dynamicgraph::command::makeCommandVoid5;
using ::dynamicgraph::command::makeCommandVoid6;
using ::dynamicgraph::command::makeCommandVoid7;
using ::dynamicgraph::command::makeCommandVoid8;
}  // namespace torquecontrol
}  // namespace sot
}  // namespace dynamicgraph
#else

andreadelprete's avatar
andreadelprete committed
61
namespace dynamicgraph {
Guilhem Saurel's avatar
Guilhem Saurel committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
namespace command {

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
struct CommandVoid5 : public Command {
  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&)> function_t;
  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> memberFunction_t;
  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&);

  CommandVoid5(E& entity, function_t function, const std::string& docString)
      : Command(entity,
                boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
                    ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
                docString),
        fptr(function) {}

 protected:
  virtual Value doExecute() {
    assert(getParameterValues().size() == 5);
    T1 val1 = getParameterValues()[0].value();
    T2 val2 = getParameterValues()[1].value();
    T3 val3 = getParameterValues()[2].value();
    T4 val4 = getParameterValues()[3].value();
    T5 val5 = getParameterValues()[4].value();
    fptr(val1, val2, val3, val4, val5);
    return Value();  // void
  }

 private:
  function_t fptr;
};

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
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) {
  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
CommandVoid5<E, T1, T2, T3, T4, T5>* makeCommandVoid5(
    E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> function,
    const std::string& docString) {
  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
                                                 docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
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) {
  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
                                                 docString);
  return NULL;
}

inline 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) {
  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
          "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
          "Void return.\n\n");
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct CommandVoid6 : public Command {
  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function_t;
  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> memberFunction_t;
  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&);

  CommandVoid6(E& entity, function_t function, const std::string& docString)
      : Command(entity,
                boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
                    ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID),
                docString),
        fptr(function) {}

 protected:
  virtual Value doExecute() {
    assert(getParameterValues().size() == 6);
    T1 val1 = getParameterValues()[0].value();
    T2 val2 = getParameterValues()[1].value();
    T3 val3 = getParameterValues()[2].value();
    T4 val4 = getParameterValues()[3].value();
    T5 val5 = getParameterValues()[4].value();
    T6 val6 = getParameterValues()[5].value();
    fptr(val1, val2, val3, val4, val5, val6);
    return Value();  // void
  }

 private:
  function_t fptr;
};

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
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) {
  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function, docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
CommandVoid6<E, T1, T2, T3, T4, T5, T6>* makeCommandVoid6(
    E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function,
    const std::string& docString) {
  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
                                                     docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
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) {
  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
                                                     docString);
  return NULL;
}

inline 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) {
  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
          "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
          "Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct CommandVoid7 : public Command {
  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
      function_t;
  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
      memberFunction_t;
  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&);

  CommandVoid7(E& entity, function_t function, const std::string& docString)
      : Command(
            entity,
            boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
                ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
            docString),
        fptr(function) {}

 protected:
  virtual Value doExecute() {
    assert(getParameterValues().size() == 7);
    T1 val1 = getParameterValues()[0].value();
    T2 val2 = getParameterValues()[1].value();
    T3 val3 = getParameterValues()[2].value();
    T4 val4 = getParameterValues()[3].value();
    T5 val5 = getParameterValues()[4].value();
    T6 val6 = getParameterValues()[5].value();
    T7 val7 = getParameterValues()[6].value();
    fptr(val1, val2, val3, val4, val5, val6, val7);
    return Value();  // void
  }

 private:
  function_t fptr;
};

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
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) {
  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function, docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>* makeCommandVoid7(
    E& entity,
    boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)> function,
    const std::string& docString) {
  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(
      entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
}

template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
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) {
  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(
      entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
  return NULL;
}

inline 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) {
  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
          "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
          "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" + "Void return.\n\n");
}

}  // namespace command
}  // namespace dynamicgraph
255
#endif
Guilhem Saurel's avatar
Guilhem Saurel committed
256
257

#endif  // __sot_torquecontrol_commands_helper_H__