blob: 0d636ee78dbfd710e84ab9b9c5ad9aa7a92874ef (
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
|
#include "memorystore.hpp"
#include <list>
#include <vector>
using namespace std;
std::vector<ref> concepts;
ref alloc(concept * moved) {
ref r = moved ? moved : new concept();
concepts.push_back(r);
return r;
}
bool referenced(ref r) {
for (auto & r2 : concepts) {
if (r2 == r) {
continue;
}
for (auto & l : r2->links) {
if (l.first == r) {
return true;
}
if (l.second == r) {
return true;
}
}
}
return false;
}
void dealloc(ref r) {
if (referenced(r)) {
throw std::logic_error("concept is referenced");
}
for (
auto it = concepts.begin();
it != concepts.end();
++ it)
{
if (*it == r) {
concepts.erase(it);
delete r;
return;
}
}
throw std::logic_error("concept not held");
}
|