Skip to content

Commit 9cfb5ba

Browse files
author
Olivier Stasse
authored
Merge pull request #44 from jmirabel/master
Add command Task.list to list the features
2 parents 74a7316 + d29563e commit 9cfb5ba

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/task/task-command.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,32 @@ namespace dynamicgraph { namespace sot {
3232
using ::dynamicgraph::command::Command;
3333
using ::dynamicgraph::command::Value;
3434

35-
// Command AddFeature
36-
class AddFeature : public Command
35+
// Command ListFeatures
36+
class ListFeatures : public Command
3737
{
3838
public:
39-
virtual ~AddFeature() {}
39+
virtual ~ListFeatures() {}
4040
/// Create command and store it in Entity
4141
/// \param entity instance of Entity owning this command
4242
/// \param docstring documentation of the command
43-
AddFeature(Task& entity, const std::string& docstring) :
44-
Command(entity, boost::assign::list_of(Value::STRING), docstring)
43+
ListFeatures(Task& entity, const std::string& docstring) :
44+
Command(entity, std::vector<Value::Type> (), docstring)
4545
{
4646
}
4747
virtual Value doExecute()
4848
{
49-
Task& task = static_cast<Task&>(owner());
50-
std::vector<Value> values = getParameterValues();
51-
std::string featureName = values[0].value();
52-
FeatureAbstract& feature =
53-
PoolStorage::getInstance()->getFeature(featureName);
54-
task.addFeature(feature);
55-
// return void
56-
return Value();
49+
typedef Task::FeatureList_t FeatureList_t;
50+
Task& task = static_cast<Task&>(owner());
51+
const FeatureList_t& fl = task.getFeatureList();
52+
std::string result("[");
53+
for (FeatureList_t::const_iterator it = fl.begin ();
54+
it != fl.end (); it++) {
55+
result += "'" + (*it)->getName() + "',";
56+
}
57+
result += "]";
58+
return Value(result);
5759
}
58-
}; // class AddFeature
60+
}; // class ListFeatures
5961
} // namespace task
6062
} // namespace command
6163
} /* namespace sot */} /* namespace dynamicgraph */

src/task/task.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ void Task::initCommands( void )
106106

107107
addCommand("clear",
108108
makeCommandVoid0(*this,&Task::clearFeatureList, docstring));
109+
// List features
110+
docstring = " \n"
111+
" Returns the list of features of the task\n"
112+
" \n";
113+
114+
addCommand("list",
115+
new command::task::ListFeatures (*this, docstring));
109116
}
110117

111118

0 commit comments

Comments
 (0)