aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-24 13:48:50 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-24 13:48:50 +0100
commit1a267bb841a2a0b8d0bfe478b62d664d7457ae7a (patch)
tree0fc15bf960032353f6e0686a8fe6ce107959228e
parent2590dd61794f0e2fdf5dd0f1bbf7f71791df8d0c (diff)
proof of concept working (doesn't use cache yet)
-rw-r--r--oop2eindopdr/Pokedex.cpp13
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;
}