-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.cpp
More file actions
66 lines (51 loc) · 1.31 KB
/
node.cpp
File metadata and controls
66 lines (51 loc) · 1.31 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
#include "node.hpp"
#include "edge.hpp"
node::node(
int id,
std::shared_ptr<data> value
) : item(value), id(id) {
this->component = std::static_pointer_cast<node_component>(
_component_defaults._node->copy()
);
}
node::node(
int id
) : node(id, std::make_shared<data>()) { }
node::node() : node(0, std::make_shared<data>()) { }
node::~node() {
}
std::shared_ptr<component> node::get_component() const {
return this->component;
}
int node::get_id() const {
return this->id;
}
void node::set_component(std::shared_ptr<node_component> component) {
this->component = component;
}
edge & node::operator[](int i) {
return *(this->edges[i]);
}
bool node::add_edge(std::shared_ptr<edge> e) {
if (e->get_u()->get_id() == this->id) {
this->edges[e->get_v()->get_id()] = e;
return true;
}
if (e->get_v()->get_id() == this->id) {
this->edges[e->get_u()->get_id()] = e;
return true;
}
return false;
}
bool node::remove_edge(std::shared_ptr<edge> e) {
int u = e->get_u()->get_id(), v = e->get_v()->get_id();
if (u == this->id && this->edges[v] == e) {
this->edges.erase(v);
return true;
}
if (v == this->id && this->edges[u] == e) {
this->edges.erase(u);
return true;
}
return false;
}