-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotation.cpp
50 lines (42 loc) · 1.54 KB
/
annotation.cpp
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
#include <cassert>
#include <typeinfo>
#include "annotation.hpp"
using namespace std;
const annotatable::specific_annotations_type annotatable::no_specific_annotations;
bool annotatable::has_annotation(const ::annotation&annotation) const {
const_annotations_iterator i = annotations.find(type_index{typeid(annotation)});
if (i == annotations.end()) {
return false;
}
return i->second.find(annotation) != i->second.end();
}
const annotation*annotatable::get_annotation(const ::annotation&annotation) const {
const_annotations_iterator i = annotations.find(type_index{typeid(annotation)});
assert(i != annotations.end());
const_specific_annotations_iterator j = i->second.find(annotation);
assert(j != i->second.end());
return &static_cast<const ::annotation&>(*j);
}
void annotatable::add_annotation(const ::annotation&annotation) const {
annotations[type_index{typeid(annotation)}].insert(annotation);
}
void annotatable::remove_annotation(const ::annotation&annotation) const {
annotations_iterator i = annotations.find(type_index{typeid(annotation)});
if (i == annotations.end()) {
return;
}
const_specific_annotations_iterator j = i->second.find(annotation);
if (j != i->second.end()) {
i->second.erase(j);
if (i->second.empty()) {
annotations.erase(i);
}
}
}
const annotatable::specific_annotations_type&annotatable::get_annotations(type_index type) const {
const_annotations_iterator i = annotations.find(type);
if (i == annotations.end()) {
return no_specific_annotations;
}
return i->second;
}