From 1a267bb841a2a0b8d0bfe478b62d664d7457ae7a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 24 Dec 2022 13:48:50 +0100 Subject: proof of concept working (doesn't use cache yet) --- oop2eindopdr/Pokedex.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/oop2eindopdr/Pokedex.cpp b/oop2eindopdr/Pokedex.cpp index a38cefd..1ffdd20 100644 --- a/oop2eindopdr/Pokedex.cpp +++ b/oop2eindopdr/Pokedex.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "CacheManager.h" #include "Pokedex.h" @@ -24,9 +25,9 @@ void Pokedex::load_collection_remote() { std::vector remote_cards = api->get_set_cards("swshp"); for (PokemonCard* card : remote_cards) { card->set_cache(this->cache); - card->verify_files(); this->cards.push_back(card); } + this->verify_collection(); cache->update_cache(); } @@ -44,6 +45,14 @@ void Pokedex::verify_collection() { } std::vector Pokedex::search_cards_by_id(std::string query) { - return {}; + std::vector out(this->cards.size()); + + // https://cplusplus.com/reference/algorithm/copy_if/ + auto it = std::copy_if(this->cards.begin(), this->cards.end(), out.begin(), [&](const PokemonCard* card) { + return card->id.find(query) != std::string::npos; + }); + out.resize(std::distance(out.begin(), it)); + + return out; } -- cgit v1.2.3