Skip to content

Commit 824016c

Browse files
committed
Add command Task.list to list the features
1 parent 74a7316 commit 824016c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/task/task-command.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,33 @@ namespace dynamicgraph { namespace sot {
5656
return Value();
5757
}
5858
}; // class AddFeature
59+
60+
// Command ListFeatures
61+
class ListFeatures : public Command
62+
{
63+
public:
64+
virtual ~ListFeatures() {}
65+
/// Create command and store it in Entity
66+
/// \param entity instance of Entity owning this command
67+
/// \param docstring documentation of the command
68+
ListFeatures(Task& entity, const std::string& docstring) :
69+
Command(entity, std::vector<Value::Type> (), docstring)
70+
{
71+
}
72+
virtual Value doExecute()
73+
{
74+
typedef Task::FeatureList_t FeatureList_t;
75+
Task& task = static_cast<Task&>(owner());
76+
const FeatureList_t& fl = task.getFeatureList();
77+
std::string result("[");
78+
for (FeatureList_t::const_iterator it = fl.begin ();
79+
it != fl.end (); it++) {
80+
result += "'" + (*it)->getName() + "',";
81+
}
82+
result += "]";
83+
return Value(result);
84+
}
85+
}; // class ListFeatures
5986
} // namespace task
6087
} // namespace command
6188
} /* 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)