dynamic-graph  4.3.1
Dynamic graph library
command-direct-getter.h
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 "dynamic-graph/command.h"
19 #include <boost/assign/list_of.hpp>
20 
21 /* --- GETTER --------------------------------------------------------- */
22 namespace dynamicgraph {
23 namespace command {
24 
25 template <class E, typename T> class DirectGetter : public Command {
26 public:
28  typedef T (E::*GetterMethod)() const;
29 
31  DirectGetter(E &entity, T *ptr, const std::string &docString)
32  : Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr) {}
33 
34 protected:
35  virtual Value doExecute() { return Value(*T_ptr); }
36 
37 private:
38  T *T_ptr;
39 };
40 
41 template <class E, typename T>
42 DirectGetter<E, T> *makeDirectGetter(E &entity, T *ptr,
43  const std::string &docString) {
44  return new DirectGetter<E, T>(entity, ptr, docString);
45 }
46 
47 inline std::string docDirectGetter(const std::string &name,
48  const std::string &type) {
49  return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " +
50  type + ".\n\n";
51 }
52 
53 } // namespace command
54 } // namespace dynamicgraph
55 
56 #endif // __dg_command_direct_getter_h__
DirectGetter(E &entity, T *ptr, const std::string &docString)
Constructor.
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:46
virtual Value doExecute()
Specific action performed by the command.
T(E::* GetterMethod)() const
Pointer to method that sets parameter of type T.