Refactor function structs into lambdas (#5675)

* change signature to use lambda

* reuse comparator

* inline structs in forEachCard

* inline structs

* Refactor exportDeckToDecklist

* fix unit test
This commit is contained in:
RickyRister 2025-04-19 21:07:22 -07:00 committed by GitHub
parent 1d259a86c1
commit 26dcb015ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 108 additions and 213 deletions

View file

@ -381,23 +381,7 @@ public:
QString getDeckHash() const;
void refreshDeckHash();
/**
* 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);
}
}
}
void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func);
};
#endif