command-direct-setter.h
Go to the documentation of this file.
1 //
2 // Copyright 2010 CNRS
3 //
4 // Author: Nicolas Mansard
5 //
6 
7 #ifndef __dg_command_direct_setter_h__
8 #define __dg_command_direct_setter_h__
9 
10 /* Define a setter command directly on the attribute (no need to pass by
11  * an explicit function). A typical use is given here:
12  * addCommand("setSize",
13  * makeDirectSetter(*this,&_dimension,
14  * docDirectSetter("dimension","int")));
15  *
16  */
17 
18 #include <boost/assign/list_of.hpp>
19 
20 #include "dynamic-graph/command.h"
21 
22 /* --- SETTER --------------------------------------------------------- */
23 namespace dynamicgraph {
24 namespace command {
25 
26 template <class E, typename T>
27 class DirectSetter : public Command {
28  public:
29  DirectSetter(E &entity, T *ptr, const std::string &docString)
30  : Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
31  docString),
32  T_ptr(ptr) {}
33 
34  protected:
35  virtual Value doExecute() {
36  const std::vector<Value> &values = getParameterValues();
37  T val = values[0].value();
38  (*T_ptr) = val;
39  return Value(); // void
40  }
41 
42  private:
43  T *T_ptr;
44 };
45 
46 template <class E, typename T>
48  const std::string &docString) {
49  return new DirectSetter<E, T>(entity, ptr, docString);
50 }
51 
52 inline std::string docDirectSetter(const std::string &name,
53  const std::string &type) {
54  return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type +
55  ".\nVoid return.\n\n";
56 }
57 
58 } // namespace command
59 } // namespace dynamicgraph
60 
61 #endif // __dg_command_direct_setter_h__
dynamicgraph::command::ValueHelper
Definition: value.h:137
dynamicgraph
dynamicgraph::command::DirectSetter::doExecute
virtual Value doExecute()
Specific action performed by the command.
Definition: command-direct-setter.h:35
dynamicgraph::command::Command::getParameterValues
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48
command.h
dynamicgraph::command::DirectSetter::DirectSetter
DirectSetter(E &entity, T *ptr, const std::string &docString)
Definition: command-direct-setter.h:29
dynamicgraph::command::Command
Definition: command.h:35
dynamicgraph::command::docDirectSetter
std::string docDirectSetter(const std::string &name, const std::string &type)
Definition: command-direct-setter.h:52
dynamicgraph::command::DirectSetter::T_ptr
T * T_ptr
Definition: command-direct-setter.h:43
dynamicgraph::command::makeDirectSetter
DirectSetter< E, T > * makeDirectSetter(E &entity, T *ptr, const std::string &docString)
Definition: command-direct-setter.h:47
dynamicgraph::command::Value
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:51
compile.name
name
Definition: compile.py:23
dynamicgraph::command::DirectSetter
Definition: command-direct-setter.h:27


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Thu Jun 13 2024 02:26:21