-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_data.cpp
More file actions
54 lines (42 loc) · 1.02 KB
/
shared_data.cpp
File metadata and controls
54 lines (42 loc) · 1.02 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
#include "shared_data.h"
SharedData::SharedData()
{
}
SharedData::~SharedData()
{
std::lock_guard<std::mutex> lock(this->mutex);
for (auto iter = map.begin(); iter != map.end(); iter++) {
delete (*iter).second;
}
}
RobotPath * SharedData::unblocked_get(const int id)
{
return this->map.at(id);
}
RobotPath * SharedData::get(const int id)
{
std::lock_guard<std::mutex> lock(this->mutex);
return this->unblocked_get(id);
}
RobotPath * SharedData::operator[](const int id)
{
return this->get(id);
}
RobotPath * SharedData::create(const int id)
{
std::lock_guard<std::mutex> lock(this->mutex);
RobotPath *robot_path;
try {
robot_path = this->unblocked_get(id);
robot_path->reset();
} catch(std::out_of_range) {
robot_path = new RobotPath();
map.insert(std::pair<char,RobotPath*>(id, robot_path) );
}
return robot_path;
}
void SharedData::reset(const int id)
{
RobotPath * robot_path = this->get(id);
robot_path->reset();
}