diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-08 23:20:56 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-08 23:20:56 +0200 |
commit | 90940a774eab876c38d5cef981b4be5bae67a462 (patch) | |
tree | 2e60edc1719ffd53752a55a7f0444166965e90c5 /logic/work.cpp | |
parent | e3292e1ddaa8d69eb320d2700fc582b4675cf8ce (diff) |
modernize only
Diffstat (limited to 'logic/work.cpp')
-rw-r--r-- | logic/work.cpp | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/logic/work.cpp b/logic/work.cpp index 16538382..14d628a7 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -1,6 +1,8 @@ #include "work.hpp" #include "compat/library-path.hpp" +#include <utility> + #include <QObject> #include <QMessageBox> #include <QFileDialog> @@ -29,72 +31,72 @@ QString Work::browse_datalogging_file(main_settings &s) return newfilename; } -std::shared_ptr<TrackLogger> Work::make_logger(main_settings &s) +std::unique_ptr<TrackLogger> Work::make_logger(main_settings &s) { if (s.tracklogging_enabled) { QString filename = browse_datalogging_file(s); if (filename.isEmpty()) { - // The user probably canceled the file dialog. In this case we don't want to do anything. + // The user probably canceled the file dialog. In this case we don't want to do anything. + return {}; } else { - auto logger = std::make_shared<TrackLoggerCSV>(s.tracklogging_filename); + auto logger = std::make_unique<TrackLoggerCSV>(s.tracklogging_filename); + if (!logger->is_open()) { - logger = nullptr; QMessageBox::warning(nullptr, tr("Logging error"), tr("Unable to open file '%1'. Proceeding without logging.").arg(s.tracklogging_filename), QMessageBox::Ok, QMessageBox::NoButton); } else - { return logger; - } } } - return std::make_shared<TrackLogger>(); + + return std::make_unique<TrackLogger>(); } -Work::Work(Mappings& m, event_handler& ev, QFrame* frame, std::shared_ptr<dylib> tracker_, std::shared_ptr<dylib> filter_, std::shared_ptr<dylib> proto_) : +Work::Work(Mappings& m, event_handler& ev, QFrame* frame, + const dylibptr& tracker_, const dylibptr& filter_, const dylibptr& proto_) : libs(frame, tracker_, filter_, proto_), - logger(make_logger(s)), - tracker(std::make_shared<pipeline>(m, libs, ev, *logger)), - sc(std::make_shared<Shortcuts>()), + logger{make_logger(s)}, + pipeline_{ m, libs, ev, *logger }, keys { #if defined OTR_HAS_KEY_UP_SUPPORT - key_tuple(s.key_center1, [&](bool x) { tracker->set_center(); tracker->set_held_center(x); }, false), - key_tuple(s.key_center2, [&](bool x) { tracker->set_center(); tracker->set_held_center(x); }, false), + key_tuple(s.key_center1, [&](bool x) { pipeline_.set_center(); pipeline_.set_held_center(x); }, false), + key_tuple(s.key_center2, [&](bool x) { pipeline_.set_center(); pipeline_.set_held_center(x); }, false), #else - key_tuple(s.key_center1, [&](bool) { tracker->set_center(); }, true), - key_tuple(s.key_center2, [&](bool) { tracker->set_center(); }, true), + key_tuple(s.key_center1, [&](bool) { pipeline_.set_center(); }, true), + key_tuple(s.key_center2, [&](bool) { pipeline_.set_center(); }, true), #endif - key_tuple(s.key_toggle1, [&](bool) { tracker->toggle_enabled(); }, true), - key_tuple(s.key_toggle2, [&](bool) { tracker->toggle_enabled(); }, true), + key_tuple(s.key_toggle1, [&](bool) { pipeline_.toggle_enabled(); }, true), + key_tuple(s.key_toggle2, [&](bool) { pipeline_.toggle_enabled(); }, true), - key_tuple(s.key_zero1, [&](bool) { tracker->toggle_zero(); }, true), - key_tuple(s.key_zero2, [&](bool) { tracker->toggle_zero(); }, true), + key_tuple(s.key_zero1, [&](bool) { pipeline_.toggle_zero(); }, true), + key_tuple(s.key_zero2, [&](bool) { pipeline_.toggle_zero(); }, true), - key_tuple(s.key_toggle_press1, [&](bool x) { tracker->set_enabled(!x); }, false), - key_tuple(s.key_toggle_press2, [&](bool x) { tracker->set_enabled(!x); }, false), + key_tuple(s.key_toggle_press1, [&](bool x) { pipeline_.set_enabled(!x); }, false), + key_tuple(s.key_toggle_press2, [&](bool x) { pipeline_.set_enabled(!x); }, false), - key_tuple(s.key_zero_press1, [&](bool x) { tracker->set_zero(x); }, false), - key_tuple(s.key_zero_press2, [&](bool x) { tracker->set_zero(x); }, false), + key_tuple(s.key_zero_press1, [&](bool x) { pipeline_.set_zero(x); }, false), + key_tuple(s.key_zero_press2, [&](bool x) { pipeline_.set_zero(x); }, false), } { if (!is_ok()) return; reload_shortcuts(); - tracker->start(); + pipeline_.start(); } void Work::reload_shortcuts() { - sc->reload(keys); + sc.reload(keys); } bool Work::is_ok() const @@ -102,10 +104,13 @@ bool Work::is_ok() const return libs.correct; } +// TODO member dtor order looks fine, check valgrind -sh 20180706 +#if 0 Work::~Work() { // order matters, otherwise use-after-free -sh - sc = nullptr; - tracker = nullptr; - libs = runtime_libraries(); + //sc = nullptr; + //pipeline = nullptr; + //libs = runtime_libraries(); } +#endif |