blob: 70d96b2c8c5c911032711f9dd4d824f81d0af854 (
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
|
#include "Object.h"
#include "Event.h"
#include <AK/Assertions.h>
Object::Object(Object* parent)
: m_parent(parent)
{
if (m_parent)
m_parent->addChild(*this);
}
Object::~Object()
{
if (m_parent)
m_parent->removeChild(*this);
for (auto* child : m_children) {
delete child;
}
}
void Object::event(Event& event)
{
switch (event.type()) {
case Event::Invalid:
ASSERT_NOT_REACHED();
break;
default:
break;
}
}
void Object::addChild(Object& object)
{
m_children.append(&object);
}
void Object::removeChild(Object& object)
{
// Oh geez, Vector needs a remove() huh...
Vector<Object*> newList;
for (auto* child : m_children) {
if (child != &object)
newList.append(child);
}
m_children = std::move(newList);
}
|