-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobject.cpp
More file actions
109 lines (86 loc) · 2.44 KB
/
object.cpp
File metadata and controls
109 lines (86 loc) · 2.44 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This file is part of the "edge" library, available at https://github.com/adigostin/edge
// Copyright (c) 2011-2020 Adi Gostin, distributed under Apache License v2.0.
#include "object.h"
namespace edge
{
void type::add_properties (std::vector<const property*>& properties) const
{
if (this->base_type != nullptr)
this->base_type->add_properties (properties);
for (auto p : props)
properties.push_back (p);
}
std::vector<const property*> type::make_property_list() const
{
std::vector<const property*> props;
this->add_properties (props);
return props;
}
const property* type::find_property (const char* name) const
{
for (auto p : props)
{
if ((p->_name == name) || (strcmp(p->_name, name) == 0))
return p;
}
if (base_type != nullptr)
return base_type->find_property(name);
else
return nullptr;
}
bool type::has_property (const property* p) const
{
for (auto prop : props)
{
if (prop == p)
return true;
}
if (base_type)
return base_type->has_property(p);
return false;
}
bool type::is_derived_from (const type* t) const
{
return (base_type == t) || base_type->is_derived_from(t);
}
bool type::is_derived_from (const type& t) const { return is_derived_from(&t); }
// ========================================================================
// object
void object::on_property_changing (const property_change_args& args)
{
this->event_invoker<property_changing_e>()(this, args);
}
void object::on_property_changed (const property_change_args& args)
{
this->event_invoker<property_changed_e>()(this, args);
}
const type object::_type = { "object", nullptr, { } };
// ========================================================================
// parent_i
void parent_i::call_inserting_into_parent(object* child)
{
child->on_inserting_into_parent();
}
void parent_i::set_parent(object* child)
{
assert (child->_parent == nullptr);
child->_parent = this;
}
void parent_i::call_inserted_into_parent(object* child)
{
child->on_inserted_into_parent();
}
void parent_i::call_removing_from_parent(object* child)
{
child->on_removing_from_parent();
}
void parent_i::clear_parent(object* child)
{
assert (child->_parent == this);
child->_parent = nullptr;
}
void parent_i::call_removed_from_parent(object* child)
{
child->on_removed_from_parent();
}
}