Skip to content

Commit 116fe5a

Browse files
committed
Add command List to entity Task.
1 parent 9cfb5ba commit 116fe5a

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

include/sot/core/sot.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ namespace dynamicgraph {
8181
return CLASS_NAME;
8282
}
8383

84-
protected:
85-
8684
/*! \brief Defines a type for a list of tasks */
8785
typedef std::list<TaskAbstract*> StackType;
8886

87+
protected:
8988

9089
/*! \brief This field is a list of controllers
9190
managed by the stack of tasks. */
@@ -149,6 +148,7 @@ namespace dynamicgraph {
149148
/*! \name Methods to handle the stack.
150149
@{
151150
*/
151+
virtual const StackType& tasks () const { return stack; }
152152

153153
/*! \brief Push the task in the stack.
154154
It has a lowest priority than the previous ones.

src/sot/sot-command.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,38 @@ namespace dynamicgraph { namespace sot {
183183
}
184184
}; // class Display
185185

186+
// Command List
187+
class List : public Command
188+
{
189+
public:
190+
virtual ~List() {}
191+
/// Create command and store it in Entity
192+
/// \param entity instance of Entity owning this command
193+
/// \param docstring documentation of the command
194+
List(Sot& entity, const std::string& docstring) :
195+
Command(entity, std::vector<Value::Type> (), docstring)
196+
{
197+
}
198+
virtual Value doExecute()
199+
{
200+
Sot& sot = static_cast<Sot&>(owner());
201+
typedef Sot::StackType StackType;
202+
const StackType& stack = sot.tasks();
203+
204+
std::stringstream returnString;
205+
returnString << "( ";
206+
for (StackType::const_iterator it = stack.begin();
207+
it != stack.end(); ++it)
208+
{
209+
returnString << '"' << (*it)->getName() << "\", ";
210+
}
211+
returnString << ")";
212+
213+
// return the stack
214+
return Value(returnString.str());
215+
}
216+
}; // class List
217+
186218
// Command Clear
187219
class Clear : public Command
188220
{

src/sot/sot.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ Sot( const std::string& name )
161161
addCommand("clear",
162162
new command::classSot::Clear(*this, docstring));
163163

164+
// List
165+
docstring =" \n"
166+
" returns the list of tasks pushed inside the stack.\n"
167+
" \n";
168+
addCommand("list",
169+
new command::classSot::List(*this, docstring));
170+
164171

165172
}
166173

0 commit comments

Comments
 (0)