#include #include "People.h" #include "util.h" using namespace std; People::People(Museum & museum) : museum(museum) {} People::~People() { for (Artist * artist : this->artists) { if (artist == nullptr) continue; delete artist; } this->artists.clear(); this->cleanup(); } void People::add_artist(const ArtistData & data) { if (this->artist_count >= 10000) return; this->artists.push_front(new Artist(this->museum, data)); this->artist_count++; } void People::remove_artist(Artist & target) { auto it = find(this->artists.begin(), this->artists.end(), &target); if (it == this->artists.end()) return; this->deleted_artists.push_front(*it); *it = nullptr; this->artist_count--; } forward_list People::get_artists() { return this->artists; } string People::to_string() { string out = ""; out += stringf("%d artists\n", this->artist_count); for (Artist * artist : this->artists) { out += stringf("- at (%.2f,%.2f)\n", artist->data.x, artist->data.y); } return out; } void People::cleanup() { this->artists.remove(nullptr); for (Artist * artist : this->deleted_artists) { delete artist; } this->deleted_artists.clear(); } void People::update() { this->cleanup(); for (Artist * artist : this->artists) { if (artist == nullptr) continue; artist->update(); } }