-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectList.cpp
85 lines (75 loc) · 1.99 KB
/
ObjectList.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "ObjectList.h"
#include "LogManager.h"
namespace df {
//Creates list
ObjectList::ObjectList() {
m_counter = 0;
p_list[MAX] = {};
}
//Clears list
void ObjectList::clear() {
m_counter = 0;
}
//Returns true if it inserts an object in the list, false if there's no room
bool ObjectList::insert(Object *p_object) {
if (m_counter < MAX) {
LM.writeLog(0, "Object %d inserted by ObjectList", p_object->getId());
p_list[m_counter] = p_object;
m_counter++;
return true;
}
LM.writeLog(10, "Object %d NOT inserted by ObjectList", p_object->getId());
return false; //No room left
}
//Returns true if object is in the list and false if it isn't
bool ObjectList::contains(Object* p_object) {
if (!isEmpty()) {
for (int i = 0; i < m_counter; i++) {
if (p_list[i] == p_object) {
LM.writeLog(0, "p_list contains Object %d", p_object->getId());
return true;
}
}
}
return false;
}
//Returns true if object is in the list and removes object from list, returns false if not in the list
bool ObjectList::remove(Object *p_object) {
for (int i = 0; i < m_counter; i++) {
if (p_list[i] == p_object) {
p_list[i] = p_list[m_counter - 1];
m_counter--;
return true;
}
}
return false;
}
//Return count of objects in list
int ObjectList::getCount() const {
return m_counter;
}
//Returns true if the list is empty, false if it isn't
bool ObjectList::isEmpty() const {
if (m_counter == 0) {
return true;
}
return false;
}
//Returns true if the list is full, false if it isn't
bool ObjectList::isFull() const {
if (m_counter == MAX) {
return true;
}
return false;
}
//Combines object lists
ObjectList ObjectList::operator+(ObjectList list) {
ObjectList big_list = *this;
ObjectListIterator li(&list);
for (li.first(); not li.isDone(); li.next()) {
Object* p_o = li.currentObject();
big_list.insert(p_o);
}
return big_list;
}
}