diff options
-rw-r--r-- | oop2eindopdr/Pokedex.cpp | 13 |
1 files 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 <fstream> #include <iostream> +#include <algorithm> #include "CacheManager.h" #include "Pokedex.h" @@ -24,9 +25,9 @@ void Pokedex::load_collection_remote() { std::vector<PokemonCard*> 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<PokemonCard*> Pokedex::search_cards_by_id(std::string query) { - return {}; + std::vector<PokemonCard*> 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; } |