aboutsummaryrefslogtreecommitdiff
path: root/People.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-12 14:18:05 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-12 14:18:05 +0200
commit1a30375e369d2d872cb3fd6ecdc6019136c7b1a4 (patch)
tree3077761b96e733fb64be803f04497c44597fe965 /People.cpp
parente113e6e65be07ab31d69243bd8d219d2bc02d094 (diff)
deserialize and display artists
Diffstat (limited to 'People.cpp')
-rw-r--r--People.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/People.cpp b/People.cpp
new file mode 100644
index 0000000..1b3bfb9
--- /dev/null
+++ b/People.cpp
@@ -0,0 +1,40 @@
+#include "People.h"
+#include "Exception.h"
+#include "util.h"
+
+using namespace std;
+
+People::~People() {
+ for (Artist * artist : this->artists) {
+ if (artist == nullptr) continue;
+ delete artist;
+ }
+ this->artists.clear();
+}
+
+void People::add_artist(ArtistData data) {
+ this->artists.push_back(new Artist(data));
+}
+
+size_t People::artists_size() {
+ return this->artists.size();
+}
+
+Artist & People::get_artist(size_t index) {
+ if (index >= this->artists_size())
+ throw Exception("No artist with index %lu", index);
+ return *this->artists[index];
+}
+
+string People::to_string() {
+ string out = "";
+
+ out += stringf("%d artists\n", this->artists_size());
+ for (size_t i = 0; i < this->artists_size(); i++) {
+ Artist & artist = this->get_artist(i);
+ out += stringf("[%d] at (%.2f,%.2f)\n", i, artist.data.x, artist.data.y);
+ }
+
+ return out;
+}
+