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: int
91 //
92 template <class E>
93 class Setter<E, int> : public Command {
94  public:
96  typedef void (E::*SetterMethod)(const int &);
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, int>::Setter(E &entity, SetterMethod setterMethod,
109  const std::string &docString)
110  : Command(entity, boost::assign::list_of(Value::INT), docString),
111  setterMethod_(setterMethod) {}
112 
113 template <class E>
115  const std::vector<Value> &values = getParameterValues();
116  // Get parameter
117  int value = values[0].value();
118  E &entity = static_cast<E &>(owner());
119  (entity.*setterMethod_)(value);
120  return Value();
121 }
122 
123 //
124 // Template specialization: float
125 //
126 template <class E>
127 class Setter<E, float> : public Command {
128  public:
130  typedef void (E::*SetterMethod)(const float &);
132  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
133 
134  protected:
135  virtual Value doExecute();
136 
137  private:
139 }; // Class Setter
140 
141 template <class E>
142 Setter<E, float>::Setter(E &entity, SetterMethod setterMethod,
143  const std::string &docString)
144  : Command(entity, boost::assign::list_of(Value::FLOAT), docString),
145  setterMethod_(setterMethod) {}
146 
147 template <class E>
149  const std::vector<Value> &values = getParameterValues();
150  // Get parameter
151  float value = values[0].value();
152  E &entity = static_cast<E &>(owner());
153  (entity.*setterMethod_)(value);
154  return Value();
155 }
156 
157 //
158 // Template specialization: double
159 //
160 template <class E>
161 class Setter<E, double> : public Command {
162  public:
164  typedef void (E::*SetterMethod)(const double &);
166  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
167 
168  protected:
169  virtual Value doExecute();
170 
171  private:
173 }; // Class Setter
174 
175 template <class E>
176 Setter<E, double>::Setter(E &entity, SetterMethod setterMethod,
177  const std::string &docString)
178  : Command(entity, boost::assign::list_of(Value::DOUBLE), docString),
179  setterMethod_(setterMethod) {}
180 
181 template <class E>
183  const std::vector<Value> &values = getParameterValues();
184  // Get parameter
185  double value = values[0].value();
186  E &entity = static_cast<E &>(owner());
187  (entity.*setterMethod_)(value);
188  return Value();
189 }
190 
191 //
192 // Template specialization: std::string
193 //
194 template <class E>
195 class Setter<E, std::string> : public Command {
196  public:
198  typedef void (E::*SetterMethod)(const std::string &);
200  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
201 
202  protected:
203  virtual Value doExecute();
204 
205  private:
207 }; // Class Setter
208 
209 template <class E>
211  const std::string &docString)
212  : Command(entity, boost::assign::list_of(Value::STRING), docString),
213  setterMethod_(setterMethod) {}
214 
215 template <class E>
217  const std::vector<Value> &values = getParameterValues();
218  // Get parameter
219  std::string value = values[0].value();
220  E &entity = static_cast<E &>(owner());
221  (entity.*setterMethod_)(value);
222  return Value();
223 }
224 
225 //
226 // Template specialization: Vector
227 //
228 template <class E>
229 class Setter<E, Vector> : public Command {
230  public:
232  typedef void (E::*SetterMethod)(const Vector &);
234  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
235 
236  protected:
237  virtual Value doExecute();
238 
239  private:
241 }; // Class Setter
242 
243 template <class E>
244 Setter<E, Vector>::Setter(E &entity, SetterMethod setterMethod,
245  const std::string &docString)
246  : Command(entity, boost::assign::list_of(Value::VECTOR), docString),
247  setterMethod_(setterMethod) {}
248 
249 template <class E>
251  const std::vector<Value> &values = getParameterValues();
252  // Get parameter
253  Vector value = values[0].value();
254  E &entity = static_cast<E &>(owner());
255  (entity.*setterMethod_)(value);
256  return Value();
257 }
258 
259 //
260 // Template specialization: Matrix
261 //
262 template <class E>
263 class Setter<E, Matrix> : public Command {
264  public:
266  typedef void (E::*SetterMethod)(const Matrix &);
268  Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
269 
270  protected:
271  virtual Value doExecute();
272 
273  private:
275 }; // Class Setter
276 
277 template <class E>
278 Setter<E, Matrix>::Setter(E &entity, SetterMethod setterMethod,
279  const std::string &docString)
280  : Command(entity, boost::assign::list_of(Value::MATRIX), docString),
281  setterMethod_(setterMethod) {}
282 
283 template <class E>
285  const std::vector<Value> &values = getParameterValues();
286  // Get parameter
287  Matrix value = values[0].value();
288  E &entity = static_cast<E &>(owner());
289  (entity.*setterMethod_)(value);
290  return Value();
291 }
292 
293 } // namespace command
294 } // namespace dynamicgraph
295 
296 #endif // DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
Eigen::VectorXd Vector
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:50
Setter(E &entity, SetterMethod setterMethod, const std::string &docString)
Constructor.
void(E::* SetterMethod)(const T &)
Pointer to method that sets parameter of type T.
Entity & owner()
Get a reference to the Entity owning this command.
Definition: command.cpp:54
Eigen::MatrixXd Matrix
virtual Value doExecute()
Specific action performed by the command.
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48


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