mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-30 20:34:27 +01:00
Turn: new findAllMatchingCmd() utility method
This commit is contained in:
parent
19387540cd
commit
0097519e96
1 changed files with 22 additions and 0 deletions
22
game/turn.h
22
game/turn.h
|
@ -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;
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue