Turn: new findAllMatchingCmd() utility method

This commit is contained in:
Olivier Teulière 2012-12-27 13:37:07 +01:00
parent 19387540cd
commit 0097519e96

View file

@ -161,6 +161,28 @@ class Turn
return findMatchingCmd<CMD, TruePred<CMD> >(TruePred<CMD>());
}
/**
* Find all the commands of the template type
*/
template<typename CMD>
vector<const CMD *> findAllMatchingCmd() const
{
vector<const CMD *> results;
// TODO: can probably be simplified using std::find_if() (or something similar)
// associated with a TypePred functor doing the dynamic_cast
vector<Command*>::const_iterator it;
for (it = m_commands.begin(); it != m_commands.end(); ++it)
{
const CMD *cmd = dynamic_cast<const CMD*>(*it);
if (cmd != 0)
{
// Found one!
results.push_back(cmd);
}
}
return results;
}
private:
vector<Command *> m_commands;
/**