summaryrefslogtreecommitdiffstats
path: root/engine/flatobject.cpp
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2018-11-17 22:46:15 +0100
committerancarola <raffaele.ancarola@epfl.ch>2018-11-17 22:46:15 +0100
commitce7b39f47a1112941b3579f6502dd4e950cb099a (patch)
tree1d2a46f7dde690415302539c989f21067f270324 /engine/flatobject.cpp
downloadflatland-ce7b39f47a1112941b3579f6502dd4e950cb099a.tar.gz
flatland-ce7b39f47a1112941b3579f6502dd4e950cb099a.zip
initialization
Diffstat (limited to 'engine/flatobject.cpp')
-rw-r--r--engine/flatobject.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/engine/flatobject.cpp b/engine/flatobject.cpp
new file mode 100644
index 0000000..464d984
--- /dev/null
+++ b/engine/flatobject.cpp
@@ -0,0 +1,50 @@
+#include "flatobject.h"
+
+#include <string.h>
+
+using namespace std;
+
+FlatObject::FlatObject()
+{
+ /* Collect this object */
+ allObjects.push_back(this);
+}
+
+FlatObject::~FlatObject()
+{
+ /* Eliminate this object reference */
+ allObjects.remove(this);
+}
+
+void FlatObject::setID(const char *id)
+{
+ strncpy(this->id, id, 31);
+ this->id[31] = '\0';
+}
+
+const char* FlatObject::getID() const
+{
+ return &id[0];
+}
+
+bool FlatObject::isAllocated(FlatObject *obj)
+{
+ for (FlatObject * o : allObjects)
+ {
+ if (o == obj)
+ return true;
+ }
+
+ return false;
+}
+
+vector<FlatObject*>& FlatObject::getByID(const char *id, vector<FlatObject*>& l)
+{
+ for (FlatObject * obj : allObjects)
+ {
+ if (!strcmp(id, obj->getID()))
+ l.push_back(obj);
+ }
+
+ return l;
+}