blob: b6a22fda5653f8bca8fa754a15ad0f2c3c3e7235 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include "object.hpp"
#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_t 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->get_id())
l.push_back(obj);
}
return l;
}
|