command-direct-getter.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_getter_h__
8 #define __dg_command_direct_getter_h__
9 
10 /* Define a getter command directly on the attribute (no need to pass by
11  * an explicit function). A typical use is given here:
12  * addCommand("getSize",
13  * makeDirectGetter(*this,&_dimension,
14  * docDirectGetter("dimension","int")));
15  *
16  */
17 
18 #include <boost/assign/list_of.hpp>
19 
20 #include "dynamic-graph/command.h"
21 
22 /* --- GETTER --------------------------------------------------------- */
23 namespace dynamicgraph {
24 namespace command {
25 
26 template <class E, typename T>
27 class DirectGetter : public Command {
28  public:
30  typedef T (E::*GetterMethod)() const;
31 
33  DirectGetter(E &entity, T *ptr, const std::string &docString)
34  : Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr) {}
35 
36  protected:
37  virtual Value doExecute() { return Value(*T_ptr); }
38 
39  private:
40  T *T_ptr;
41 };
42 
43 template <class E, typename T>
45  const std::string &docString) {
46  return new DirectGetter<E, T>(entity, ptr, docString);
47 }
48 
49 inline std::string docDirectGetter(const std::string &name,
50  const std::string &type) {
51  return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " +
52  type + ".\n\n";
53 }
54 
55 } // namespace command
56 } // namespace dynamicgraph
57 
58 #endif // __dg_command_direct_getter_h__
dynamicgraph::command::DirectGetter::T_ptr
T * T_ptr
Definition: command-direct-getter.h:40
dynamicgraph::command::DirectGetter::GetterMethod
T(E::* GetterMethod)() const
Pointer to method that sets parameter of type T.
Definition: command-direct-getter.h:30
dynamicgraph
command.h
dynamicgraph::command::DirectGetter::DirectGetter
DirectGetter(E &entity, T *ptr, const std::string &docString)
Constructor.
Definition: command-direct-getter.h:33
dynamicgraph::command::makeDirectGetter
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
Definition: command-direct-getter.h:44
dynamicgraph::command::DirectGetter
Definition: command-direct-getter.h:27
dynamicgraph::command::Command
Definition: command.h:35
dynamicgraph::command::docDirectGetter
std::string docDirectGetter(const std::string &name, const std::string &type)
Definition: command-direct-getter.h:49
dynamicgraph::command::DirectGetter::doExecute
virtual Value doExecute()
Specific action performed by the command.
Definition: command-direct-getter.h:37
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


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