command-setter.t.cpp
Go to the documentation of this file.
1 //
2 // Copyright 2010 CNRS
3 //
4 // Author: Florent Lamiraux
5 //
6 
7 #ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
8 #define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
9 
11 
12 #include <boost/assign/list_of.hpp>
13 #include <sstream>
14 
16 
17 namespace dynamicgraph {
18 class Entity;
19 namespace command {
20 
21 //
22 // Template specialization: bool
23 //
24 template <class E>
25 class Setter<E, bool> : public Command {
26  public:
28  typedef void (E::*SetterMethod)(const bool &);
30  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
31 
32  protected:
33  virtual Value doExecute();
34 
35  private:
37 }; // Class Setter
38 
39 template <class E>
40 Setter<E, bool>::Setter(E &entity, SetterMethod setterMethod,
41  const std::string &docString)
42  : Command(entity, boost::assign::list_of(Value::BOOL), docString),
43  setterMethod_(setterMethod) {}
44 
45 template <class E>
47  const std::vector<Value> &values = getParameterValues();
48  // Get parameter
49  bool value = values[0].value();
50  E &entity = static_cast<E &>(owner());
51  (entity.*setterMethod_)(value);
52  return Value();
53 }
54 
55 //
56 // Template specialization: unsigned
57 //
58 template <class E>
59 class Setter<E, unsigned> : public Command {
60  public:
62  typedef void (E::*SetterMethod)(const unsigned &);
64  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
65 
66  protected:
67  virtual Value doExecute();
68 
69  private:
71 }; // Class Setter
72 
73 template <class E>
74 Setter<E, unsigned>::Setter(E &entity, SetterMethod setterMethod,
75  const std::string &docString)
76  : Command(entity, boost::assign::list_of(Value::UNSIGNED), docString),
77  setterMethod_(setterMethod) {}
78 
79 template <class E>
81  const std::vector<Value> &values = getParameterValues();
82  // Get parameter
83  unsigned value = values[0].value();
84  E &entity = static_cast<E &>(owner());
85  (entity.*setterMethod_)(value);
86  return Value();
87 }
88 
89 //
90 // Template specialization: unsigned long
91 //
92 template <class E>
93 class Setter<E, std::uint64_t> : public Command {
94  public:
96  typedef void (E::*SetterMethod)(const std::uint64_t &);
98  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
99 
100  protected:
101  virtual Value doExecute();
102 
103  private:
105 }; // Class Setter
106 
107 template <class E>
108 Setter<E, std::uint64_t>::Setter(E &entity, SetterMethod setterMethod,
109  const std::string &docString)
110  : Command(entity, boost::assign::list_of(Value::UNSIGNEDLONGINT),
111  docString),
112  setterMethod_(setterMethod) {}
113 
114 template <class E>
116  const std::vector<Value> &values = getParameterValues();
117  // Get parameter
118  std::uint64_t value = values[0].value();
119  E &entity = static_cast<E &>(owner());
120  (entity.*setterMethod_)(value);
121  return Value();
122 }
123 
124 //
125 // Template specialization: int
126 //
127 template <class E>
128 class Setter<E, int> : public Command {
129  public:
131  typedef void (E::*SetterMethod)(const int &);
133  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
134 
135  protected:
136  virtual Value doExecute();
137 
138  private:
140 }; // Class Setter
141 
142 template <class E>
143 Setter<E, int>::Setter(E &entity, SetterMethod setterMethod,
144  const std::string &docString)
145  : Command(entity, boost::assign::list_of(Value::INT), docString),
146  setterMethod_(setterMethod) {}
147 
148 template <class E>
150  const std::vector<Value> &values = getParameterValues();
151  // Get parameter
152  int value = values[0].value();
153  E &entity = static_cast<E &>(owner());
154  (entity.*setterMethod_)(value);
155  return Value();
156 }
157 
158 //
159 // Template specialization: int64_t
160 //
161 template <class E>
162 class Setter<E, std::int64_t> : public Command {
163  public:
165  typedef void (E::*SetterMethod)(const std::int64_t &);
167  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
168 
169  protected:
170  virtual Value doExecute();
171 
172  private:
174 }; // Class Setter
175 
176 template <class E>
177 Setter<E, std::int64_t>::Setter(E &entity, SetterMethod setterMethod,
178  const std::string &docString)
179  : Command(entity, boost::assign::list_of(Value::LONGINT), docString),
180  setterMethod_(setterMethod) {}
181 
182 template <class E>
184  const std::vector<Value> &values = getParameterValues();
185  // Get parameter
186  std::int64_t value = values[0].value();
187  E &entity = static_cast<E &>(owner());
188  (entity.*setterMethod_)(value);
189  return Value();
190 }
191 
192 //
193 // Template specialization: float
194 //
195 template <class E>
196 class Setter<E, float> : public Command {
197  public:
199  typedef void (E::*SetterMethod)(const float &);
201  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
202 
203  protected:
204  virtual Value doExecute();
205 
206  private:
208 }; // Class Setter
209 
210 template <class E>
211 Setter<E, float>::Setter(E &entity, SetterMethod setterMethod,
212  const std::string &docString)
213  : Command(entity, boost::assign::list_of(Value::FLOAT), docString),
214  setterMethod_(setterMethod) {}
215 
216 template <class E>
218  const std::vector<Value> &values = getParameterValues();
219  // Get parameter
220  float value = values[0].value();
221  E &entity = static_cast<E &>(owner());
222  (entity.*setterMethod_)(value);
223  return Value();
224 }
225 
226 //
227 // Template specialization: double
228 //
229 template <class E>
230 class Setter<E, double> : public Command {
231  public:
233  typedef void (E::*SetterMethod)(const double &);
235  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
236 
237  protected:
238  virtual Value doExecute();
239 
240  private:
242 }; // Class Setter
243 
244 template <class E>
245 Setter<E, double>::Setter(E &entity, SetterMethod setterMethod,
246  const std::string &docString)
247  : Command(entity, boost::assign::list_of(Value::DOUBLE), docString),
248  setterMethod_(setterMethod) {}
249 
250 template <class E>
252  const std::vector<Value> &values = getParameterValues();
253  // Get parameter
254  double value = values[0].value();
255  E &entity = static_cast<E &>(owner());
256  (entity.*setterMethod_)(value);
257  return Value();
258 }
259 
260 //
261 // Template specialization: std::string
262 //
263 template <class E>
264 class Setter<E, std::string> : public Command {
265  public:
267  typedef void (E::*SetterMethod)(const std::string &);
269  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
270 
271  protected:
272  virtual Value doExecute();
273 
274  private:
276 }; // Class Setter
277 
278 template <class E>
279 Setter<E, std::string>::Setter(E &entity, SetterMethod setterMethod,
280  const std::string &docString)
281  : Command(entity, boost::assign::list_of(Value::STRING), docString),
282  setterMethod_(setterMethod) {}
283 
284 template <class E>
286  const std::vector<Value> &values = getParameterValues();
287  // Get parameter
288  std::string value = values[0].value();
289  E &entity = static_cast<E &>(owner());
290  (entity.*setterMethod_)(value);
291  return Value();
292 }
293 
294 //
295 // Template specialization: Vector
296 //
297 template <class E>
298 class Setter<E, Vector> : public Command {
299  public:
301  typedef void (E::*SetterMethod)(const Vector &);
303  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
304 
305  protected:
306  virtual Value doExecute();
307 
308  private:
310 }; // Class Setter
311 
312 template <class E>
313 Setter<E, Vector>::Setter(E &entity, SetterMethod setterMethod,
314  const std::string &docString)
315  : Command(entity, boost::assign::list_of(Value::VECTOR), docString),
316  setterMethod_(setterMethod) {}
317 
318 template <class E>
320  const std::vector<Value> &values = getParameterValues();
321  // Get parameter
322  Vector value = values[0].value();
323  E &entity = static_cast<E &>(owner());
324  (entity.*setterMethod_)(value);
325  return Value();
326 }
327 
328 //
329 // Template specialization: Matrix
330 //
331 template <class E>
332 class Setter<E, Matrix> : public Command {
333  public:
335  typedef void (E::*SetterMethod)(const Matrix &);
337  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
338 
339  protected:
340  virtual Value doExecute();
341 
342  private:
344 }; // Class Setter
345 
346 template <class E>
347 Setter<E, Matrix>::Setter(E &entity, SetterMethod setterMethod,
348  const std::string &docString)
349  : Command(entity, boost::assign::list_of(Value::MATRIX), docString),
350  setterMethod_(setterMethod) {}
351 
352 template <class E>
354  const std::vector<Value> &values = getParameterValues();
355  // Get parameter
356  Matrix value = values[0].value();
357  E &entity = static_cast<E &>(owner());
358  (entity.*setterMethod_)(value);
359  return Value();
360 }
361 
362 } // namespace command
363 } // namespace dynamicgraph
364 
365 #endif // DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
linear-algebra.h
dynamicgraph::command::Setter< E, int >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:139
command-setter.h
dynamicgraph
dynamicgraph::command::Setter::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.h:56
dynamicgraph::command::Setter< E, std::uint64_t >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:104
dynamicgraph::command::Command::getParameterValues
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
Definition: linear-algebra.h:13
dynamicgraph::command::Setter::SetterMethod
void(E::* SetterMethod)(const T &)
Pointer to method that sets parameter of type T.
Definition: command-setter.h:48
dynamicgraph::command::Setter::doExecute
virtual Value doExecute()
Specific action performed by the command.
dynamicgraph::command::Setter::Setter
Setter(E &entity, SetterMethod setterMethod, const std::string &docString)
Constructor.
dynamicgraph::command::Setter< E, unsigned >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:70
dynamicgraph::command::Setter< E, Vector >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:309
dynamicgraph::command::Command
Definition: command.h:35
dynamicgraph::command::Setter< E, float >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:207
dynamicgraph::Vector
Eigen::VectorXd Vector
Definition: linear-algebra.h:14
dynamicgraph::command::Setter< E, std::int64_t >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:173
dynamicgraph::command::Setter< E, bool >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:36
dynamicgraph::command::Setter< E, double >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:241
dynamicgraph::command::Setter< E, std::string >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:275
dynamicgraph::command::Setter
Definition: command-setter.h:45
dynamicgraph::command::Setter< E, Matrix >::setterMethod_
SetterMethod setterMethod_
Definition: command-setter.t.cpp:343
dynamicgraph::command::Value
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:51
dynamicgraph::command::Command::owner
Entity & owner()
Get a reference to the Entity owning this command.
Definition: command.cpp:54


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38