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 | |
parent | e3292e1ddaa8d69eb320d2700fc582b4675cf8ce (diff) |
modernize only
Diffstat (limited to 'logic')
-rw-r--r-- | logic/pipeline.cpp | 2 | ||||
-rw-r--r-- | logic/tracklogger.cpp | 7 | ||||
-rw-r--r-- | logic/tracklogger.hpp | 38 | ||||
-rw-r--r-- | logic/work.cpp | 61 | ||||
-rw-r--r-- | logic/work.hpp | 19 |
5 files changed, 59 insertions, 68 deletions
diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index c8cdc72d..a7cf0c4e 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -35,7 +35,7 @@ using namespace pipeline_impl; static constexpr inline double r2d = 180. / M_PI; static constexpr inline double d2r = M_PI / 180.; -reltrans::reltrans() {} +reltrans::reltrans() = default; void reltrans::on_center() { diff --git a/logic/tracklogger.cpp b/logic/tracklogger.cpp index 35510cb3..a287b633 100644 --- a/logic/tracklogger.cpp +++ b/logic/tracklogger.cpp @@ -1,7 +1,12 @@ #include "tracklogger.hpp" #include "pipeline.hpp" -TrackLogger::~TrackLogger() {} +#include <QMessageBox> + +void TrackLogger::write_pose(const double* p) +{ + write(p, 6); +} void TrackLogger::reset_dt() { diff --git a/logic/tracklogger.hpp b/logic/tracklogger.hpp index 0a8d5410..d6c34157 100644 --- a/logic/tracklogger.hpp +++ b/logic/tracklogger.hpp @@ -5,41 +5,21 @@ #include <fstream> #include <QString> -#include <QMessageBox> -#include <QWidget> +#include <QDebug> class OTR_LOGIC_EXPORT TrackLogger { - TrackLogger(TrackLogger&&) = delete; - TrackLogger(const TrackLogger&) = delete; - TrackLogger& operator=(const TrackLogger&) = delete; - TrackLogger& operator=(TrackLogger&&) = delete; - Timer t; public: - TrackLogger() - { - } - - virtual ~TrackLogger(); - - virtual void write(const char *) - { - } + TrackLogger() = default; + virtual ~TrackLogger() = default; - virtual void write(const double *, int) - { - } + virtual void write(const char *) {} + virtual void write(const double *, int) {} + virtual void next_line() {} - virtual void next_line() - { - } - - void write_pose(const double *p) - { - write(p, 6); - } + void write_pose(const double *p); void reset_dt(); void write_dt(); @@ -49,10 +29,10 @@ public: class OTR_LOGIC_EXPORT TrackLoggerCSV : public TrackLogger { std::ofstream out; - bool first_col; + bool first_col = true; inline void handle_first_col_sep(); public: - TrackLoggerCSV(const QString &filename) : first_col(true) + explicit TrackLoggerCSV(const QString &filename) { out.open(filename.toStdString()); } 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 diff --git a/logic/work.hpp b/logic/work.hpp index d5bb201e..212bb15d 100644 --- a/logic/work.hpp +++ b/logic/work.hpp @@ -29,22 +29,23 @@ class OTR_LOGIC_EXPORT Work final : public TR { Q_OBJECT + using dylibptr = std::shared_ptr<dylib>; + + static std::unique_ptr<TrackLogger> make_logger(main_settings &s); + static QString browse_datalogging_file(main_settings &s); + public: using fn_t = std::function<void(bool)>; using key_tuple = std::tuple<key_opts&, fn_t, bool>; main_settings s; // tracker needs settings, so settings must come before it runtime_libraries libs; // idem - std::shared_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it - std::shared_ptr<pipeline> tracker; - std::shared_ptr<Shortcuts> sc; + std::unique_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it + pipeline pipeline_; + Shortcuts sc; std::vector<key_tuple> keys; - 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); void reload_shortcuts(); bool is_ok() const; - -private: - static std::shared_ptr<TrackLogger> make_logger(main_settings &s); - static QString browse_datalogging_file(main_settings &s); }; |