-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRegistry.cpp
More file actions
65 lines (49 loc) · 1.78 KB
/
Copy pathRegistry.cpp
File metadata and controls
65 lines (49 loc) · 1.78 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
#include "Registry.h"
#include <boost/filesystem/operations.hpp>
#include <QLibrary>
#include "biotracker/core/Exceptions.h"
namespace BioTracker {
namespace Core {
Registry::Registry() {
m_typeByString.insert(std::make_pair("No Tracking", NoTracking));
m_trackerByType.insert(std::make_pair(NoTracking, nullptr));
m_stringByType.insert(std::make_pair(NoTracking, "No Tracking"));
}
bool Registry::registerTrackerType(std::string name, new_tracker_function_t f) {
if (m_typeByString.find(name) != m_typeByString.end()) {
throw std::invalid_argument("Tracker with same name already registered");
}
const TrackerType type = getNextId();
m_typeByString.emplace(name, type);
m_stringByType.emplace(type, name);
m_trackerByType.emplace(type, f);
Q_EMIT newTracker(type);
return true;
}
void Registry::loadTrackerLibrary(const boost::filesystem::path &path) {
typedef void (*RegisterFunction)();
if (!boost::filesystem::exists(path)) {
throw file_not_found("Could not find file " + path.string());
}
QLibrary trackerLibrary(QString::fromStdString(path.string()));
auto registerFunction = static_cast<RegisterFunction>
(trackerLibrary.resolve("registerTracker"));
registerFunction();
}
std::shared_ptr<TrackingAlgorithm> Registry::makeNewTracker(
const TrackerType type, Settings &settings, QWidget *parent) const {
const auto &it = m_trackerByType.find(type);
if (it != m_trackerByType.cend()) {
std::shared_ptr<TrackingAlgorithm> tracker = (it->second)(settings, parent);
tracker->setType(type);
return tracker;
} else {
return nullptr;
}
}
TrackerType getNextId() {
static TrackerType nextType = NoTracking + 1;
return nextType++;
}
}
}