diff options
Diffstat (limited to 'People.cpp')
-rw-r--r-- | People.cpp | 21 |
1 files changed, 4 insertions, 17 deletions
@@ -8,12 +8,9 @@ using namespace std; People::People(Museum & museum) : museum(museum) {} People::~People() { - for (Artist * artist : this->artists) { - if (artist == nullptr) continue; + for (Artist * artist : this->artists) delete artist; - } this->artists.clear(); - this->cleanup(); } void People::add_artist(const ArtistData & data) { @@ -26,9 +23,10 @@ void People::add_artist(const ArtistData & data) { 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; + Artist * artist = *it; + this->artists.remove(&target); this->artist_count--; + delete artist; } forward_list<Artist *> People::get_artists() { @@ -40,25 +38,14 @@ string People::to_string() { out += stringf("%d artists\n", this->artist_count); for (Artist * artist : this->artists) { - if (artist == nullptr) continue; 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(); } } |