blob: 58d1a7c1e79c6355ab80cec217dafefe82f4b903 (
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
|
#include "concept.hpp"
ref concept::id()
{
return this;
}
bool concept::linked(ref type)
{
return links.count(type) > 0;
}
bool concept::linked(ref type, ref target)
{
for (ref t : getAll(type)) {
if (t == target) {
return true;
}
}
return false;
}
ref concept::get(ref type)
{
auto result = links.equal_range(type);
if (result.first == result.second) {
throw std::out_of_range("no such concept link to get");
}
return result.first->second;
}
concept::array concept::getAll(ref type)
{
array ret;
for (
auto range = links.equal_range(type);
range.first != range.second;
++ range.first
) {
ret.push_back(range.first->second);
}
return ret;
}
void concept::link(ref type, ref target)
{
links.insert({type, target});
}
void concept::unlink(ref type, ref target)
{
auto ls = links.equal_range(type);
for (auto l = ls.first; l != ls.second; ++ l) {
if (l->second == target) {
links.erase(l);
return;
}
}
throw std::out_of_range("no such concept link to erase");
}
|