mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-15 23:12:14 -07:00
change signature to use lambda
This commit is contained in:
parent
1d259a86c1
commit
d38e9ca1b9
2 changed files with 17 additions and 17 deletions
|
|
@ -994,3 +994,19 @@ void DeckList::refreshDeckHash()
|
||||||
cachedDeckHash = QString();
|
cachedDeckHash = QString();
|
||||||
emit deckHashChanged();
|
emit deckHashChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls a given function on each card in the deck.
|
||||||
|
*/
|
||||||
|
void DeckList::forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func)
|
||||||
|
{
|
||||||
|
// Support for this is only possible if the internal structure
|
||||||
|
// doesn't get more complicated.
|
||||||
|
for (int i = 0; i < root->size(); i++) {
|
||||||
|
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
||||||
|
for (int j = 0; j < node->size(); j++) {
|
||||||
|
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
||||||
|
func(node, card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -381,23 +381,7 @@ public:
|
||||||
QString getDeckHash() const;
|
QString getDeckHash() const;
|
||||||
void refreshDeckHash();
|
void refreshDeckHash();
|
||||||
|
|
||||||
/**
|
void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func);
|
||||||
* Calls a given function object for each card in the deck. It must
|
|
||||||
* take a InnerDecklistNode* as its first argument and a
|
|
||||||
* DecklistCardNode* as its second.
|
|
||||||
*/
|
|
||||||
template <typename Callback> void forEachCard(Callback &callback)
|
|
||||||
{
|
|
||||||
// Support for this is only possible if the internal structure
|
|
||||||
// doesn't get more complicated.
|
|
||||||
for (int i = 0; i < root->size(); i++) {
|
|
||||||
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
|
||||||
for (int j = 0; j < node->size(); j++) {
|
|
||||||
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
|
||||||
callback(node, card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue