summaryrefslogtreecommitdiffstats
path: root/src/object.h
blob: a5ad5692e9e1ad2a44d15af5f0488a36d434d285 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Temporary file
 *
 * Authors:
 *   Adrian Boguszewski
 *
 * Copyright (C) 2016 Adrian Boguszewski
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#ifndef INKSCAPE_PROTOTYPE_OBJECT_H
#define INKSCAPE_PROTOTYPE_OBJECT_H

#include <string>
#include <sigc++/signal.h>
#include <sigc++/connection.h>
#include <boost/intrusive/list.hpp>

// this causes some warning, but it's only for this prototype
class Object;
struct delete_disposer
{
    void operator()(Object *delete_this) {
        delete delete_this;
    }
};

class Object {
private:
    std::string name;
    Object* parent;

    typedef boost::intrusive::list_member_hook<
            boost::intrusive::link_mode<
                    boost::intrusive::auto_unlink
            >> list_hook;
    list_hook child_hook;

    typedef boost::intrusive::list<
            Object,
            boost::intrusive::constant_time_size<false>,
            boost::intrusive::member_hook<
                    Object,
                    list_hook,
                    &Object::child_hook
            >> list;
    list children;

    sigc::signal<bool, Object*> release_signal;

public:
    Object(std::string name);
    virtual ~Object();

    list &getChildren() {
        return children;
    }

    const std::string &getName() const;
    Object * getParent() ;

    sigc::connection connectRelease(sigc::slot<bool, Object*> slot);
    void addChild(Object* o);
    bool isDescendantOf(Object* o);

    bool operator==(Object o) {
        return name == o.name;
    }

    bool operator!=(Object o) {
        return name != o.name;
    }
};

#endif //INKSCAPE_PROTOTYPE_OBJECT_H