GCC Code Coverage Report


Directory: ./
File: src/sot/sot-command.h
Date: 2024-08-13 12:13:25
Exec Total Coverage
Lines: 0 69 0.0%
Branches: 0 142 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * Florent Lamiraux
4 *
5 * CNRS
6 *
7 */
8
9 #ifndef SOT_COMMAND_H
10 #define SOT_COMMAND_H
11
12 #include <dynamic-graph/command-getter.h>
13 #include <dynamic-graph/command-setter.h>
14 #include <dynamic-graph/command.h>
15
16 #include <boost/assign/list_of.hpp>
17
18 namespace dynamicgraph {
19 namespace sot {
20 namespace command {
21 namespace classSot {
22 using ::dynamicgraph::command::Command;
23 using ::dynamicgraph::command::Value;
24
25 // Command Push
26 class Push : public Command {
27 public:
28 virtual ~Push() {}
29 /// Create command and store it in Entity
30 /// \param entity instance of Entity owning this command
31 /// \param docstring documentation of the command
32 Push(Sot &entity, const std::string &docstring)
33 : Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
34 virtual Value doExecute() {
35 Sot &sot = static_cast<Sot &>(owner());
36 std::vector<Value> values = getParameterValues();
37 std::string taskName = values[0].value();
38
39 TaskAbstract &task = PoolStorage::getInstance()->getTask(taskName);
40 sot.push(task);
41 // return void
42 return Value();
43 }
44 }; // class Push
45
46 // Command Remove
47 class Remove : public Command {
48 public:
49 virtual ~Remove() {}
50 /// Create command and store it in Entity
51 /// \param entity instance of Entity owning this command
52 /// \param docstring documentation of the command
53 Remove(Sot &entity, const std::string &docstring)
54 : Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
55 virtual Value doExecute() {
56 Sot &sot = static_cast<Sot &>(owner());
57 std::vector<Value> values = getParameterValues();
58 std::string taskName = values[0].value();
59
60 TaskAbstract &task = PoolStorage::getInstance()->getTask(taskName);
61 sot.remove(task);
62 // return void
63 return Value();
64 }
65 }; // class Remove
66
67 // Command Up
68 class Up : public Command {
69 public:
70 virtual ~Up() {}
71 /// Create command and store it in Entity
72 /// \param entity instance of Entity owning this command
73 /// \param docstring documentation of the command
74 Up(Sot &entity, const std::string &docstring)
75 : Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
76 virtual Value doExecute() {
77 Sot &sot = static_cast<Sot &>(owner());
78 std::vector<Value> values = getParameterValues();
79 std::string taskName = values[0].value();
80
81 TaskAbstract &task = PoolStorage::getInstance()->getTask(taskName);
82 sot.up(task);
83 // return void
84 return Value();
85 }
86 }; // class Remove
87
88 // Command Down
89 class Down : public Command {
90 public:
91 virtual ~Down() {}
92 /// Create command and store it in Entity
93 /// \param entity instance of Entity owning this command
94 /// \param docstring documentation of the command
95 Down(Sot &entity, const std::string &docstring)
96 : Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
97 virtual Value doExecute() {
98 Sot &sot = static_cast<Sot &>(owner());
99 std::vector<Value> values = getParameterValues();
100 std::string taskName = values[0].value();
101
102 TaskAbstract &task = PoolStorage::getInstance()->getTask(taskName);
103 sot.down(task);
104 // return void
105 return Value();
106 }
107 }; // class Down
108
109 // Command Display
110 class Display : public Command {
111 public:
112 virtual ~Display() {}
113 /// Create command and store it in Entity
114 /// \param entity instance of Entity owning this command
115 /// \param docstring documentation of the command
116 Display(Sot &entity, const std::string &docstring)
117 : Command(entity, std::vector<Value::Type>(), docstring) {}
118 virtual Value doExecute() {
119 std::stringstream returnString;
120 Sot &sot = static_cast<Sot &>(owner());
121 sot.display(returnString);
122
123 // return the stack
124 return Value(returnString.str());
125 }
126 }; // class Display
127
128 // Command List
129 class List : public Command {
130 public:
131 virtual ~List() {}
132 /// Create command and store it in Entity
133 /// \param entity instance of Entity owning this command
134 /// \param docstring documentation of the command
135 List(Sot &entity, const std::string &docstring)
136 : Command(entity, std::vector<Value::Type>(), docstring) {}
137 virtual Value doExecute() {
138 Sot &sot = static_cast<Sot &>(owner());
139 typedef Sot::StackType StackType;
140 const StackType &stack = sot.tasks();
141
142 std::stringstream returnString;
143 returnString << "( ";
144 for (StackType::const_iterator it = stack.begin(); it != stack.end();
145 ++it) {
146 returnString << '"' << (*it)->getName() << "\", ";
147 }
148 returnString << ")";
149
150 // return the stack
151 return Value(returnString.str());
152 }
153 }; // class List
154
155 // Command Clear
156 class Clear : public Command {
157 public:
158 virtual ~Clear() {}
159 /// Clear the stack
160 /// \param docstring documentation of the command
161 Clear(Sot &entity, const std::string &docstring)
162 : Command(entity, std::vector<Value::Type>(), docstring) {}
163 virtual Value doExecute() {
164 std::stringstream returnString;
165 Sot &sot = static_cast<Sot &>(owner());
166 sot.clear();
167 // return the stack
168 return Value();
169 }
170 }; // class Clear
171
172 } // namespace classSot
173 } // namespace command
174 } /* namespace sot */
175 } /* namespace dynamicgraph */
176
177 #endif // SOT_COMMAND_H
178