Skip to content

Commit b3db058

Browse files
olivier-stasseOlivier Stasse
authored andcommitted
[doc] Add doc on commands
1 parent 6304b31 commit b3db058

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed

doc/additionalDoc/doc-command.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/** \page subpage_command Commands
2+
3+
\section subpage_command_intro Quick introduction
4+
5+
Commands are allowing to expand the entities.
6+
It has no real interest in C++, and is mostly targeted to scripting languages
7+
used to manipulate the control graph.
8+
dynamic-graph-python provides a mecanism which is automatically binding command
9+
to python. The main interest for a programmer is that there is no additional
10+
lines to add. It is realized through CMake rules provided by the submodule
11+
jrl-cmakemodules.
12+
13+
\section subpage_command_using Extending entities
14+
15+
\subsection subpage_command_setters_and_getters Setters and getters
16+
17+
To modify a quantity with a special method of your class, it is recommanded to
18+
use Setter.
19+
20+
For instance to specify the size of the state in one entity and calls the
21+
method setStateSize it is possible to write:
22+
23+
\code
24+
docstring = "\n"
25+
" Set size of state vector\n"
26+
"\n";
27+
addCommand("resize", new command::Setter<Device, unsigned int>(
28+
*this, &Device::setStateSize, docstring));
29+
\endcode
30+
31+
Getting the information of the member of the class can be realized with
32+
the following snippet:
33+
34+
\code
35+
addCommand("getTimeStep",
36+
command::makeDirectGetter(
37+
*this, &this->timestep_,
38+
command::docDirectGetter("Time step", "double")));
39+
\endcode
40+
41+
\subsubsection subsubpage_command_void_multiple_args Implementing a command
42+
43+
Templates are provided to create commands returning no value, but with up to
44+
4 arguments.
45+
46+
In order to call the following method:
47+
\code
48+
void four_args(const int &, const int &, const int &, const int &) {
49+
test_four_args_ = true;
50+
}
51+
\endcode
52+
53+
It is sufficient to add in the constructor:
54+
\code
55+
addCommand("4_args",
56+
makeCommandVoid4(
57+
*this, &CustomEntity::four_args,
58+
docCommandVoid4("four args", "int", "int", "int", "int")));
59+
\endcode
60+
61+
The arguments are limited to the types provided by the class Value.
62+
63+
\subsection subpage_command_void_multiple_args Commands returning a value
64+
65+
The templates with the prefix makeCommandReturnType are allowing to return
66+
a type.
67+
68+
For instance to add a command returning a type with two arguments:
69+
\code
70+
std::string two_args_ret(const int &, const int &)
71+
{ test_two_args_ = true; return std::string("return");}
72+
\endcode
73+
74+
In the constructor, the following snippet shows to create the command:
75+
\code
76+
addCommand("2_args_r",
77+
makeCommandReturnType2(
78+
*this, &CustomEntity::two_args_ret,
79+
docCommandVoid2("two args", "int","int")));
80+
\endcode
81+
82+
\section section_calling_a_generic_command Calling a generic command
83+
84+
Of course calling in C++ a command amounts to call directly the method.
85+
However in the context of writing a wrapper for another language,
86+
one may wants to find a command and build the call.
87+
88+
All the commands of an entity are store in a map. The strings storing the
89+
commands name are the map keys.
90+
91+
Therefore calling the previous command can be done with the following snippet:
92+
\code
93+
94+
std::map<const std::string, Command *> aCommandMap =
95+
this->getNewStyleCommandMap();
96+
97+
std::string cmd_name = "4_args";
98+
99+
std::map<const std::string, Command *>::iterator it_map;
100+
101+
it_map = aCommandMap.find(cmd_name);
102+
if (it_map == aCommandMap.end())
103+
104+
int first_arg = 1;
105+
Value aValue(first_arg);
106+
std::vector<Value> values;
107+
108+
for (unsigned int i = 0; i < 4; i++)
109+
values.push_back(aValue);
110+
111+
it_map->second->setParameterValues(values);
112+
it_map->second->execute();
113+
it_map->second->owner();
114+
it_map->second->getDocstring();
115+
116+
\endcode
117+
118+
when returning a value the line with the call to execute is :
119+
\code
120+
Value aValue =it_map->second->execute();
121+
\endcode
122+
123+
*/

doc/additionalDoc/entity.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To add flexibility to a node, it is possible to add command with arguments to
2424
modify the internal behavior of the entity or get information from the entity.
2525
As a command is in general asynchronous and rare with respect to the data-flow
2626
scheme for the signals the command is in general executed in a \b none-real-time
27-
thread.
27+
thread. For more details on command see \subpage subpage_command .
2828
2929
\subsection entity_classes Entity class
3030
Entities are implemented as C++ classes and compiled as dynamic libraries. They
@@ -34,9 +34,9 @@ to load the library, it is not advised to do that during a control-law
3434
computation. Entity instanciation also implies memory allocation which is also
3535
time consuming and thus not advised inside a real-time thread.
3636
37-
The entities will be placed in ${PREFIX}/lib/plugin (since this may change, it
38-
is advised to check the install log or the CMakeLists.txt file to check the
39-
installation path).
37+
The entities will be placed in ${PREFIX}/lib/dynamic-graph-plugin
38+
(since this may change, it is advised to check the install log or the
39+
CMakeLists.txt file to check the installation path).
4040
4141
\subsection entities List of entities in this package
4242
Since most of the functionality in projects using the dynamic-graph framework

0 commit comments

Comments
 (0)