summaryrefslogtreecommitdiffstats
path: root/engine/object.cpp
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2019-01-22 01:29:43 +0100
committerancarola <raffaele.ancarola@epfl.ch>2019-01-22 01:29:43 +0100
commit7170c16a463fdb1f446ab7458270205bf08e7c89 (patch)
tree58be57180690416272be1167900b74d4a56bfed2 /engine/object.cpp
parentFix typo to compile (diff)
downloadflatland-7170c16a463fdb1f446ab7458270205bf08e7c89.tar.gz
flatland-7170c16a463fdb1f446ab7458270205bf08e7c89.zip
Signal change
Diffstat (limited to 'engine/object.cpp')
-rw-r--r--engine/object.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/engine/object.cpp b/engine/object.cpp
new file mode 100644
index 0000000..eb74e1a
--- /dev/null
+++ b/engine/object.cpp
@@ -0,0 +1,62 @@
+#include "flatobject.h"
+
+#include <stdlib.h>
+
+using namespace std;
+using namespace flat::core;
+
+list<object*> object::all_objects;
+
+object::object()
+{
+ /* Collect this object */
+ object::all_objects.push_back(this);
+}
+
+object::~object()
+{
+ /* Eliminate this object reference */
+ object::all_objects.remove(this);
+}
+
+void object::set_id(const string& id)
+{
+ this->id = id;
+}
+
+const string& object::get_id() const
+{
+ return id;
+}
+
+string object::random_id(uint8_t length) {
+
+ string out;
+
+ for (Uint8 i = 0; i < length; ++i)
+ out += (char)(rand() % 93 + 33);
+
+ return out;
+}
+
+bool object::is_allocated(object *obj)
+{
+ for (object * o : object::all_objects)
+ {
+ if (o == obj)
+ return true;
+ }
+
+ return false;
+}
+
+vector<object*>& object::get_by_id(const string& id, vector<object*>& l)
+{
+ for (object * obj : object::all_objects)
+ {
+ if (id == obj->getID())
+ l.push_back(obj);
+ }
+
+ return l;
+}