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 | |
parent | e3292e1ddaa8d69eb320d2700fc582b4675cf8ce (diff) |
modernize only
39 files changed, 156 insertions, 214 deletions
diff --git a/compat/copyable-mutex.cpp b/compat/copyable-mutex.cpp index 7c112c5e..dde84c83 100644 --- a/compat/copyable-mutex.cpp +++ b/compat/copyable-mutex.cpp @@ -2,10 +2,7 @@ mutex& mutex::operator=(const mutex& datum) { - inner = nullptr; - inner = std::make_unique<QMutex>(datum->isRecursive() - ? QMutex::Recursive - : QMutex::NonRecursive); + inner.emplace(datum->isRecursive() ? QMutex::Recursive : QMutex::NonRecursive); return *this; } @@ -15,7 +12,7 @@ mutex::mutex(const mutex& datum) } mutex::mutex(mutex::mode m) : - inner(std::make_unique<QMutex>(static_cast<QMutex::RecursionMode>(int(m)))) + inner { std::in_place, static_cast<QMutex::RecursionMode>(int(m)) } { } @@ -31,6 +28,6 @@ QMutex* mutex::operator->() const mutex::operator QMutex*() const { - return const_cast<QMutex*>(inner.get()); + return const_cast<QMutex*>(&inner.value()); } diff --git a/compat/copyable-mutex.hpp b/compat/copyable-mutex.hpp index af82876d..46c6c88c 100644 --- a/compat/copyable-mutex.hpp +++ b/compat/copyable-mutex.hpp @@ -1,6 +1,6 @@ #pragma once -#include <memory> +#include <optional> #include <QMutex> @@ -8,7 +8,7 @@ class OTR_COMPAT_EXPORT mutex { - std::unique_ptr<QMutex> inner; + std::optional<QMutex> inner; public: enum mode @@ -19,7 +19,7 @@ public: mutex& operator=(const mutex& datum); mutex(const mutex& datum); - mutex(mode m = normal); + explicit mutex(mode m = normal); QMutex* operator&() const; operator QMutex*() const; diff --git a/compat/qhash.hpp b/compat/qhash.hpp new file mode 100644 index 00000000..a9685007 --- /dev/null +++ b/compat/qhash.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include <functional> +#include <QString> +#include <QHashFunctions> + +namespace std { +template<> struct hash<QString> +{ + inline unsigned operator()(const QString& value) const + { + return qHash(value); + } +}; +} diff --git a/cv/translation-calibrator.cpp b/cv/translation-calibrator.cpp index 1eb9d1fa..d08e0c43 100644 --- a/cv/translation-calibrator.cpp +++ b/cv/translation-calibrator.cpp @@ -62,8 +62,8 @@ std::tuple<cv::Vec3f, cv::Vec3i> TranslationCalibrator::get_estimate() for (unsigned k = 0; k < 3; k++) { const vec& data = *in[k]; - for (unsigned i = 0; i < data.size(); i++) - if (data[i]) + for (unsigned i : data) + if (i) values[k]++; } diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp index c7547107..9c2b06d4 100644 --- a/dinput/keybinding-worker.cpp +++ b/dinput/keybinding-worker.cpp @@ -16,7 +16,7 @@ #include <windows.h> -Key::Key() {} +Key::Key() = default; bool Key::should_process() { diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp index a6a4edc9..757a9706 100644 --- a/dinput/win32-joystick.hpp +++ b/dinput/win32-joystick.hpp @@ -7,34 +7,24 @@ */ #pragma once -#ifdef _WIN32 - #include "dinput.hpp" #include "compat/timer.hpp" +#include "compat/qhash.hpp" #include "export.hpp" + #include <cstring> #include <memory> #include <vector> #include <functional> #include <algorithm> #include <unordered_map> + #include <QString> #include <QDebug> #include <QMutex> #include <QMutexLocker> #include <QWidget> -namespace std { -template<> -struct hash<QString> -{ - inline std::size_t operator()(const QString& value) const - { - return qHash(value); - } -}; -} - struct OTR_DINPUT_EXPORT win32_joy_ctx final { using fn = std::function<void(const QString& guid, int btn, bool held)>; @@ -102,4 +92,3 @@ private: static enum_state enumerator; }; -#endif diff --git a/filter-accela/ftnoir_filter_accela.cpp b/filter-accela/ftnoir_filter_accela.cpp index 9484fafe..f96bd2d2 100644 --- a/filter-accela/ftnoir_filter_accela.cpp +++ b/filter-accela/ftnoir_filter_accela.cpp @@ -84,8 +84,8 @@ void accela::filter(const double* input, double *output) return; } - const double rot_thres = s.rot_smoothing.to<double>(); - const double pos_thres = s.pos_smoothing.to<double>(); + const double rot_thres { s.rot_smoothing }; + const double pos_thres { s.pos_smoothing }; const double dt = t.elapsed_seconds(); t.start(); diff --git a/filter-ewma2/ftnoir_filter_ewma2.cpp b/filter-ewma2/ftnoir_filter_ewma2.cpp index b29746a0..46c4796d 100644 --- a/filter-ewma2/ftnoir_filter_ewma2.cpp +++ b/filter-ewma2/ftnoir_filter_ewma2.cpp @@ -22,9 +22,7 @@ // to minSmooth at a rate controlled by the powCurve setting. -ewma::ewma() -{ -} +ewma::ewma() = default; void ewma::filter(const double *input, double *output) { diff --git a/filter-kalman/kalman.cpp b/filter-kalman/kalman.cpp index 472f01f0..f88d7f90 100644 --- a/filter-kalman/kalman.cpp +++ b/filter-kalman/kalman.cpp @@ -195,8 +195,8 @@ void kalman::reset() first_run = true; dt_since_last_input = 0; - prev_slider_pos[0] = static_cast<slider_value>(s.noise_pos_slider_value); - prev_slider_pos[1] = static_cast<slider_value>(s.noise_rot_slider_value); + prev_slider_pos[0] = s.noise_pos_slider_value; + prev_slider_pos[1] = s.noise_rot_slider_value; dz_filter.reset(); } diff --git a/gui/init.cpp b/gui/init.cpp index 75f6b1eb..0e9d746a 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -81,7 +81,7 @@ void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString & { const unsigned short* const str_ = msg.utf16(); auto str = reinterpret_cast<const wchar_t* const>(str_); - static_assert(sizeof(*str_) == sizeof(*str), ""); + static_assert(sizeof(*str_) == sizeof(*str)); std::fflush(stderr); if (ctx.function) 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); }; diff --git a/migration/migration.cpp b/migration/migration.cpp index 569dff99..8e5fea5e 100644 --- a/migration/migration.cpp +++ b/migration/migration.cpp @@ -29,11 +29,11 @@ namespace detail { static std::vector<mptr> migration_list; static std::vector<mfun> migration_thunks; -void migrator::register_migration(mptr m) +void migrator::register_migration(mptr const& m) { const QString date = m->unique_date(); - for (mptr m2 : migration_list) + for (mptr const& m2 : migration_list) if (m2->unique_date() == date) std::abort(); @@ -77,7 +77,7 @@ void migrator::eval_thunks() mptr m = fun(); register_migration(m); } - if (migration_thunks.size()) + if (!migration_thunks.empty()) sort_migrations(); migration_thunks.clear(); } @@ -118,7 +118,7 @@ QString migrator::time_after_migrations() { const std::vector<mptr>& list = migrations(); - if (list.size() == 0u) + if (list.empty()) return QStringLiteral("19700101_00"); QString ret = list[list.size() - 1]->unique_date(); diff --git a/migration/migration.hpp b/migration/migration.hpp index 48689fc6..42c8bead 100644 --- a/migration/migration.hpp +++ b/migration/migration.hpp @@ -33,7 +33,7 @@ namespace detail { private: static void sort_migrations(); - static void register_migration(mptr m); + static void register_migration(const mptr& m); static std::vector<mptr>& migrations(); static void eval_thunks(); diff --git a/options/base-value.cpp b/options/base-value.cpp index d900ad0f..bcbbd1dc 100644 --- a/options/base-value.cpp +++ b/options/base-value.cpp @@ -2,7 +2,7 @@ using namespace options; -value_::value_(bundle b, const QString& name, value_::comparator cmp, std::type_index type_idx) : +value_::value_(bundle const& b, const QString& name, value_::comparator cmp, std::type_index type_idx) : b(b), self_name(name), cmp(cmp), @@ -21,11 +21,6 @@ void value_::notify() const bundle_value_changed(); } -void value_::store(const QVariant& datum) -{ - b->store_kv(self_name, datum); -} - namespace options::detail { void set_base_value_to_default(value_* val) diff --git a/options/slider.cpp b/options/slider.cpp index 56d9ba16..5789e951 100644 --- a/options/slider.cpp +++ b/options/slider.cpp @@ -11,7 +11,7 @@ namespace options { -slider_value::slider_value(double cur, double min, double max) : +constexpr slider_value::slider_value(double cur, double min, double max) : cur_(cur), min_(min), max_(max) @@ -24,48 +24,31 @@ slider_value::slider_value(double cur, double min, double max) : cur_ = min_; } -slider_value& slider_value::operator=(const slider_value& v) +template<typename t> +static constexpr auto abs_(t x) { - if (this != &v) - { - cur_ = v.cur(); - min_ = v.min(); - max_ = v.max(); - } - - return *this; + return x < t{0} ? -x : x; } -slider_value::slider_value(const slider_value& v) +constexpr bool slider_value::operator==(const slider_value& v) const { - *this = v; -} - -slider_value::slider_value() : slider_value(0, 0, 0) -{ -} - -bool slider_value::operator==(const slider_value& v) const -{ - using std::fabs; - constexpr double eps = 2e-3; #if 1 - return (fabs(v.cur_ - cur_) < eps && - fabs(v.min_ - min_) < eps && - fabs(v.max_ - max_) < eps); + return (abs_(v.cur_ - cur_) < eps && + abs_(v.min_ - min_) < eps && + abs_(v.max_ - max_) < eps); #else - return (fabs(v.cur_ - cur_) < eps); + return (abs_(v.cur_ - cur_) < eps); #endif } -bool slider_value::operator!=(const slider_value& v) const +constexpr bool slider_value::operator!=(const slider_value& v) const { return !(*this == v); } -slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const +constexpr slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const { slider_value v(*this); @@ -75,11 +58,11 @@ slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) con : (((pos - q_min) * (v.max() - v.min())) / q_diff + v.min()); if (sv_pos < v.min()) - v = slider_value(v.min(), v.min(), v.max()); + v = { v.min(), v.min(), v.max() }; else if (sv_pos > v.max()) - v = slider_value(v.max(), v.min(), v.max()); + v = { v.max(), v.min(), v.max() }; else - v = slider_value(sv_pos, v.min(), v.max()); + v = { sv_pos, v.min(), v.max() }; return v; } diff --git a/options/slider.hpp b/options/slider.hpp index 360c85b8..1366e390 100644 --- a/options/slider.hpp +++ b/options/slider.hpp @@ -22,35 +22,27 @@ namespace options { double cur_, min_, max_; - template<typename t> - using arith_conversion_t = std::enable_if_t<std::is_arithmetic_v<std::decay_t<t>>, std::decay_t<t>>; public: - slider_value(double cur, double min, double max); + constexpr slider_value(double cur, double min, double max); - template<typename t, typename u, typename v> slider_value(t cur, u min, v max) : + template<typename t, typename u, typename v> + constexpr slider_value(t cur, u min, v max) : cur_(double(cur)), min_(double(min)), max_(double(max)) {} - template<typename t> - cc_noinline - operator arith_conversion_t<t>() const - { - return t(cur_); - } - - slider_value& operator=(const slider_value& v); - - slider_value(const slider_value& v); - slider_value(); - bool operator==(const slider_value& v) const; - bool operator!=(const slider_value& v) const; - operator double() const { return cur_; } - double cur() const { return cur_; } - double min() const { return min_; } - double max() const { return max_; } - slider_value update_from_slider(int pos, int q_min, int q_max) const; + slider_value& operator=(const slider_value& v) = default; + constexpr slider_value(const slider_value& v) = default; + constexpr slider_value() : slider_value{0, 0, 0} {}; + + constexpr bool operator==(const slider_value& v) const; + constexpr bool operator!=(const slider_value& v) const; + constexpr operator double() const { return cur_; } + constexpr double cur() const { return cur_; } + constexpr double min() const { return min_; } + constexpr double max() const { return max_; } + constexpr slider_value update_from_slider(int pos, int q_min, int q_max) const; int to_slider_pos(int q_min, int q_max) const; }; } diff --git a/options/tie.hpp b/options/tie.hpp index 59fd0da1..aa83c7cb 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -66,11 +66,11 @@ void tie_setting(value<t>& v, QComboBox* cb, From&& fn_to_index, To&& fn_to_valu }); }, v.DIRECT_CONNTYPE); value_::connect(&v, value_::value_changed<t>(), - cb, [&v, cb, fn_to_index](cv_qualified<t>& v) { + cb, [&v, cb, fn_to_index](cv_qualified<t>& v) { run_in_thread_sync(cb, [&] { cb->setCurrentIndex(fn_to_index(v)); }); - }); + }, v.DIRECT_CONNTYPE); } template<typename t, typename F> diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 08e3a469..12de49d3 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -84,9 +84,7 @@ pose_widget::pose_widget(QWidget* parent) : QWidget(parent), xform(this) rotate_sync(0,0,0, 0,0,0); } -pose_widget::~pose_widget() -{ -} +pose_widget::~pose_widget() = default; void pose_widget::rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z) { diff --git a/proto-flightgear/ftnoir_protocol_fg.cpp b/proto-flightgear/ftnoir_protocol_fg.cpp index c06feefb..4c2156ac 100644 --- a/proto-flightgear/ftnoir_protocol_fg.cpp +++ b/proto-flightgear/ftnoir_protocol_fg.cpp @@ -22,7 +22,7 @@ void flightgear::pose(const double* headpose) { FlightData.r = -headpose[Roll]; FlightData.status = 1; QHostAddress destIP(quint32(s.ip1 << 24 | s.ip2 << 16 | s.ip3 << 8 | s.ip4)); - (void) outSocket.writeDatagram(reinterpret_cast<const char*>(&FlightData), sizeof(FlightData), destIP, static_cast<quint16>(s.port)); + (void) outSocket.writeDatagram(reinterpret_cast<const char*>(&FlightData), sizeof(FlightData), destIP, quint16(s.port)); } module_status flightgear::initialize() diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp index 75815f1b..51472092 100644 --- a/proto-simconnect/ftnoir_protocol_sc.cpp +++ b/proto-simconnect/ftnoir_protocol_sc.cpp @@ -152,7 +152,7 @@ module_status simconnect::initialize() { if (!SCClientLib.isLoaded()) { - ActivationContext ctx(142 + static_cast<int>(s.sxs_manifest)); + ActivationContext ctx(142 + s.sxs_manifest); if (ctx.is_ok()) { diff --git a/proto-vjoystick/vjoystick.cpp b/proto-vjoystick/vjoystick.cpp index a55f8ca4..bb0f0f51 100644 --- a/proto-vjoystick/vjoystick.cpp +++ b/proto-vjoystick/vjoystick.cpp @@ -101,13 +101,8 @@ LONG handle::to_axis_value(unsigned axis_id, double val) return LONG(clamp((val+minmax) * max / (2*minmax) - min, min, max)); } -vjoystick_proto::vjoystick_proto() -{ -} - -vjoystick_proto::~vjoystick_proto() -{ -} +vjoystick_proto::vjoystick_proto() = default; +vjoystick_proto::~vjoystick_proto() = default; module_status vjoystick_proto::initialize() { diff --git a/spline/spline.cpp b/spline/spline.cpp index fc437bb9..69928834 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -492,9 +492,7 @@ settings::settings(bundle b, const QString& axis_name, Axis idx): opts(axis_name, idx) {} -settings::~settings() -{ -} +settings::~settings() = default; } diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index cdadf2e9..b3d75e7d 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -141,7 +141,7 @@ bool aruco_tracker::open_camera() rint = 0; resolution_tuple res = resolution_choices[rint]; int fps; - switch (static_cast<int>(s.force_fps)) + switch (*s.force_fps) { default: case 0: @@ -186,7 +186,7 @@ bool aruco_tracker::open_camera() void aruco_tracker::set_intrinsics() { const int w = grayscale.cols, h = grayscale.rows; - const double diag_fov = static_cast<int>(s.fov) * M_PI / 180.; + const double diag_fov = s.fov * M_PI / 180.; const double fov_w = 2.*atan(tan(diag_fov/2.)/sqrt(1. + h/(double)w * h/(double)w)); const double fov_h = 2.*atan(tan(diag_fov/2.)/sqrt(1. + w/(double)h * w/(double)h)); const double focal_length_w = .5 * w / tan(.5 * fov_w); diff --git a/tracker-fusion/fusion.cpp b/tracker-fusion/fusion.cpp index d1b866c7..5bf979ff 100644 --- a/tracker-fusion/fusion.cpp +++ b/tracker-fusion/fusion.cpp @@ -20,9 +20,7 @@ static auto get_modules() return Modules(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH); } -fusion_tracker::fusion_tracker() -{ -} +fusion_tracker::fusion_tracker() = default; fusion_tracker::~fusion_tracker() { diff --git a/tracker-hydra/ftnoir_tracker_hydra.cpp b/tracker-hydra/ftnoir_tracker_hydra.cpp index 69bb71e9..2e9e1fc5 100644 --- a/tracker-hydra/ftnoir_tracker_hydra.cpp +++ b/tracker-hydra/ftnoir_tracker_hydra.cpp @@ -23,7 +23,7 @@ #endif #include <sixense.h> -Hydra_Tracker::Hydra_Tracker() {} +Hydra_Tracker::Hydra_Tracker() = default; #include <sixense_math.hpp> diff --git a/tracker-joystick/ftnoir_tracker_joystick.cpp b/tracker-joystick/ftnoir_tracker_joystick.cpp index 6257ee24..fce7cf04 100644 --- a/tracker-joystick/ftnoir_tracker_joystick.cpp +++ b/tracker-joystick/ftnoir_tracker_joystick.cpp @@ -11,7 +11,7 @@ joystick::joystick() { - if (static_cast<QString>(s.guid) == "") + if (s.guid->isEmpty()) { std::vector<win32_joy_ctx::joy_info> info = joy_ctx.get_joy_info(); if (!info.empty()) diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index 6116bec5..e86e686b 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -49,12 +49,12 @@ void PointModel::set_model(const pt_settings& s) switch (s.active_model_panel) { case Clip: - M01 = vec3(0, static_cast<f>(s.clip_ty), -static_cast<f>(s.clip_tz)); - M02 = vec3(0, -static_cast<f>(s.clip_by), -static_cast<f>(s.clip_bz)); + M01 = vec3(0, s.clip_ty, -s.clip_tz); + M02 = vec3(0, -s.clip_by, -s.clip_bz); break; case Cap: - M01 = vec3(-static_cast<f>(s.cap_x), -static_cast<f>(s.cap_y), -static_cast<f>(s.cap_z)); - M02 = vec3(static_cast<f>(s.cap_x), -static_cast<f>(s.cap_y), -static_cast<f>(s.cap_z)); + M01 = vec3(-s.cap_x, s.cap_y, -s.cap_z); + M02 = vec3(s.cap_x, -s.cap_y, -s.cap_z); break; case Custom: M01 = vec3(s.m01_x, s.m01_y, s.m01_z); @@ -81,9 +81,7 @@ void PointModel::get_d_order(const vec2* points, unsigned* d_order, const vec2& } -PointTracker::PointTracker() -{ -} +PointTracker::PointTracker() = default; PointTracker::PointOrder PointTracker::find_correspondences_previous(const vec2* points, const PointModel& model, diff --git a/tracker-rs/imagewidget.cpp b/tracker-rs/imagewidget.cpp index 63986234..50a904f5 100644 --- a/tracker-rs/imagewidget.cpp +++ b/tracker-rs/imagewidget.cpp @@ -6,6 +6,7 @@ */ #include "imagewidget.h" +#include <utility> #include <QPainter> ImageWidget::ImageWidget(QWidget *parent) : @@ -14,11 +15,11 @@ ImageWidget::ImageWidget(QWidget *parent) : mImage.fill(Qt::gray); } -void ImageWidget::setImage(const QImage image) +void ImageWidget::setImage(QImage image) { { QMutexLocker lock(&mMutex); - mImage = image; + mImage = std::move(image); } repaint(); } diff --git a/tracker-rs/imagewidget.h b/tracker-rs/imagewidget.h index e8b6e61e..f04eb1a3 100644 --- a/tracker-rs/imagewidget.h +++ b/tracker-rs/imagewidget.h @@ -15,7 +15,7 @@ class ImageWidget : public QWidget { Q_OBJECT public: ImageWidget(QWidget* parent = 0); - void setImage(const QImage image); + void setImage(QImage image); private: QImage mImage; diff --git a/tracker-s2bot/ftnoir_tracker_s2bot.cpp b/tracker-s2bot/ftnoir_tracker_s2bot.cpp index 8748e0f3..0b8976fc 100644 --- a/tracker-s2bot/ftnoir_tracker_s2bot.cpp +++ b/tracker-s2bot/ftnoir_tracker_s2bot.cpp @@ -56,7 +56,7 @@ void tracker_s2bot::run() { int add_indices[] = { s.add_yaw, s.add_pitch, s.add_roll, }; double orient[4] {}; - for (auto line : slist) + for (auto const& line : slist) { QStringList keyval = line.split(' '); if (keyval.count() < 2) continue; diff --git a/tracker-steamvr/steamvr.cpp b/tracker-steamvr/steamvr.cpp index cafdc556..10d73462 100644 --- a/tracker-steamvr/steamvr.cpp +++ b/tracker-steamvr/steamvr.cpp @@ -178,9 +178,7 @@ steamvr::steamvr() : device_index(-1) { } -steamvr::~steamvr() -{ -} +steamvr::~steamvr() = default; module_status steamvr::start_tracker(QFrame*) { diff --git a/tracker-test/test.cpp b/tracker-test/test.cpp index d37d7373..f93f1556 100644 --- a/tracker-test/test.cpp +++ b/tracker-test/test.cpp @@ -81,7 +81,7 @@ test_dialog::test_dialog() connect(ui.buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* btn) { if (btn == ui.buttonBox->button(QDialogButtonBox::Abort)) - *(volatile int*)0 = 0; + *(volatile int*)nullptr = 0; }); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); diff --git a/tracker-wii/wii_camera.cpp b/tracker-wii/wii_camera.cpp index b8b370ab..93dfe4ff 100644 --- a/tracker-wii/wii_camera.cpp +++ b/tracker-wii/wii_camera.cpp @@ -84,13 +84,11 @@ WIICamera::result WIICamera::get_frame(pt_frame& frame_) return { true, cam_info }; } -bool WIICamera::start(int idx, int fps, int res_x, int res_y) +bool WIICamera::start(int, int, int, int) { m_pDev = std::make_unique<wiimote>(); m_pDev->ChangedCallback = on_state_change; - m_pDev->CallbackTriggerFlags = (state_change_flags)(CONNECTED | - EXTENSION_CHANGED | - MOTIONPLUS_CHANGED); + m_pDev->CallbackTriggerFlags = (state_change_flags)(CONNECTED|EXTENSION_CHANGED |MOTIONPLUS_CHANGED); return true; } diff --git a/tracker-wii/wii_frame.hpp b/tracker-wii/wii_frame.hpp index 31967d10..2107646b 100644 --- a/tracker-wii/wii_frame.hpp +++ b/tracker-wii/wii_frame.hpp @@ -59,7 +59,7 @@ private: bool fresh = true; cv::Mat frame_copy, frame_color, frame_resize, frame_out; - wii_camera_status status; + wii_camera_status status = wii_cam_wait_for_dongle; }; } // ns pt_module diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp index 0e3d8257..df1723b3 100644 --- a/variant/default/main-window.hpp +++ b/variant/default/main-window.hpp @@ -39,9 +39,7 @@ #include "ui_main-window.h" -using namespace options; - -class main_window : public QMainWindow, private State +class main_window final : public QMainWindow, private State { Q_OBJECT @@ -147,7 +145,7 @@ signals: void restart_tracker(); public: main_window(); - ~main_window(); + ~main_window() override; static void set_working_directory(); bool maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list); void die_on_config_not_writable(); |