summaryrefslogtreecommitdiffstats
path: root/src/object.cpp
blob: c05d50b3aa77c14cef772111ee64bda4a5eff490 (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
/*
 * Temporary file
 *
 * Authors:
 *   Adrian Boguszewski
 *
 * Copyright (C) 2016 Adrian Boguszewski
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include "object.h"

Object::Object(std::string name) : name(name), parent(NULL) { }

Object::~Object() {
    // only for this prototype
    // call destructor on every child
    children.clear_and_dispose(delete_disposer());
    release_signal.emit(this);
}

const std::string& Object::getName() const {
    return name;
}

Object *Object::getParent()  {
    return parent;
}

bool Object::isDescendantOf(Object *o) {
    Object* p = parent;
    while(p != NULL) {
        if (p == o) {
            return true;
        }
        p = p->parent;
    }
    return false;
}

void Object::addChild(Object* o) {
    o->parent = this;
    children.push_back(*o);
}

sigc::connection Object::connectRelease(sigc::slot<bool, Object*> slot) {
    return release_signal.connect(slot);
}