-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathAnnotationList.cpp
More file actions
152 lines (132 loc) · 4.14 KB
/
AnnotationList.cpp
File metadata and controls
152 lines (132 loc) · 4.14 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "AnnotationList.h"
#include "Annotation.h"
#include "AnnotationGroup.h"
AnnotationList::AnnotationList() {
}
AnnotationList::~AnnotationList() {
removeAllAnnotations();
removeAllGroups();
}
bool AnnotationList::isModified() {
for (std::vector<std::shared_ptr<Annotation> >::iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
if ((*it)->isModified()) {
return true;
}
}
for (std::vector<std::shared_ptr<AnnotationGroup> >::iterator it = _groups.begin(); it != _groups.end(); ++it) {
if ((*it)->isModified()) {
return true;
}
}
return false;
}
void AnnotationList::resetModifiedStatus() {
for (std::vector<std::shared_ptr<Annotation> >::iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
(*it)->resetModifiedStatus();
}
for (std::vector<std::shared_ptr<AnnotationGroup> >::iterator it = _groups.begin(); it != _groups.end(); ++it) {
(*it)->resetModifiedStatus();
}
}
bool AnnotationList::addGroup(const std::shared_ptr<AnnotationGroup>& group) {
if (group) {
_groups.push_back(group);
return true;
}
return false;
}
bool AnnotationList::addAnnotation(const std::shared_ptr<Annotation>& annotation) {
if (annotation) {
_annotations.push_back(annotation);
return true;
}
return false;
}
std::shared_ptr<AnnotationGroup> AnnotationList::getGroup(const int& index) {
if (index < 0) {
return *(_groups.end() - abs(index));
}
else {
return *(_groups.begin() + index);
}
}
std::shared_ptr<AnnotationGroup> AnnotationList::getGroup(std::string name) {
for (std::vector<std::shared_ptr<AnnotationGroup> >::const_iterator it = _groups.begin(); it != _groups.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
return (*it);
}
}
return NULL;
}
std::shared_ptr<Annotation> AnnotationList::getAnnotation(const int& index) {
if (index < 0) {
return *(_annotations.end() - abs(index));
}
else {
return *(_annotations.begin() + index);
}
}
std::shared_ptr<Annotation> AnnotationList::getAnnotation(std::string name) {
for (std::vector<std::shared_ptr<Annotation> >::const_iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
return (*it);
}
}
return NULL;
}
std::vector<std::shared_ptr<Annotation> > AnnotationList::getAnnotations() const {
return _annotations;
}
std::vector<std::shared_ptr<AnnotationGroup> > AnnotationList::getGroups() const {
return _groups;
}
void AnnotationList::setAnnotations(const std::vector<std::shared_ptr<Annotation> >& annotations) {
this->removeAllAnnotations();
_annotations = annotations;
}
void AnnotationList::setGroups(const std::vector<std::shared_ptr<AnnotationGroup> >& groups) {
this->removeAllGroups();
_groups = groups;
}
void AnnotationList::removeGroup(const int& index) {
if (index < 0) {
(_groups.end() - abs(index))->reset();
_groups.erase(_groups.end() - abs(index));
}
else {
(_groups.begin() + index)->reset();
_groups.erase(_groups.begin() + index);
}
}
void AnnotationList::removeGroup(std::string name) {
for (std::vector<std::shared_ptr<AnnotationGroup> >::iterator it = _groups.begin(); it != _groups.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
_groups.erase(it);
break;
}
}
}
void AnnotationList::removeAnnotation(const int& index) {
if (index < 0) {
(_annotations.end() - abs(index))->reset();
_annotations.erase(_annotations.end() - abs(index));
}
else {
(_annotations.begin() + index)->reset();
_annotations.erase(_annotations.begin() + index);
}
}
void AnnotationList::removeAnnotation(std::string name) {
for (std::vector<std::shared_ptr<Annotation> >::iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
_annotations.erase(it);
break;
}
}
}
void AnnotationList::removeAllAnnotations() {
_annotations.clear();
}
void AnnotationList::removeAllGroups() {
_groups.clear();
}