-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectManager.cpp
45 lines (41 loc) · 1.12 KB
/
ObjectManager.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
#include "ObjectManager.h"
#include "StorableObject.h"
ObjectManager::ObjectManager(token) {
termination_ = false;
}
ObjectManager::~ObjectManager() {}
void ObjectManager::Set(std::string label, std::shared_ptr<StorableObject> object, bool replace) {
std::lock_guard<std::mutex> lock(access_mutex_);
if (termination_) return;
if (replace) {
objects_[label] = object;
}
else {
auto f = objects_.find(label);
if (f == objects_.end()) {
objects_[label] = object;
}
else {
throw std::string("Object already set!");
}
}
}
std::shared_ptr<StorableObject> ObjectManager::Get(std::string label) {
std::lock_guard<std::mutex> lock(access_mutex_);
if (termination_) return 0;
auto f = objects_.find(label);
if (f != objects_.end()) {
return objects_[label];
}
else {
return 0;
}
}
void ObjectManager::Remove(std::string label) {
std::lock_guard<std::mutex> lock(access_mutex_);
termination_ = true;
auto f = objects_.find(label);
if (f != objects_.end()) {
objects_.erase(label);
}
}