diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-10-25 17:55:27 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-10-25 17:55:27 +0200 |
commit | 83867b413c449101bbe14615ff857a7785432ede (patch) | |
tree | 3b7a7fd68da8158a97fd67db9806fa6d984ebf80 | |
parent | 00cceaffca6063b963d0848480acaa99f5fecaad (diff) |
cleanup only
- replace warn_unused_result with [[nodiscard]]
- remove some redundant w_a_r
- replace std::decay with remove_cvref_t
- simplify compat/math.hpp
-rw-r--r-- | compat/macros.hpp | 16 | ||||
-rw-r--r-- | compat/math.hpp | 38 | ||||
-rw-r--r-- | gui/mapping-dialog.cpp | 9 | ||||
-rw-r--r-- | logic/pipeline.hpp | 7 | ||||
-rw-r--r-- | logic/win32-shortcuts.h | 4 | ||||
-rw-r--r-- | spline/spline-widget.cpp | 2 | ||||
-rw-r--r-- | spline/spline-widget.hpp | 2 | ||||
-rw-r--r-- | spline/spline.cpp | 2 | ||||
-rw-r--r-- | spline/spline.hpp | 4 | ||||
-rw-r--r-- | tracker-pt/module/camera.h | 4 | ||||
-rw-r--r-- | tracker-pt/pt-api.hpp | 8 |
11 files changed, 40 insertions, 56 deletions
diff --git a/compat/macros.hpp b/compat/macros.hpp index 42d5d649..5d82c4ee 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -12,12 +12,6 @@ # define cc_forceinline __attribute__((always_inline)) #endif -#if defined _MSC_VER -# define cc_warn_unused_result _Check_return_ -#else -# define cc_warn_unused_result __attribute__((warn_unused_result)) -#endif - #if !defined likely # if defined __GNUC__ # define likely(x) __builtin_expect(!!(x),1) @@ -65,7 +59,7 @@ template<typename t> using remove_cvref_t = typename cxx20_compat::remove_cvref<t>::type; template<typename t> -using to_const_lvalue_reference_t = remove_cvref_t<t> const&; +using to_const_cvref_t = std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>; // causes ICE in Visual Studio 2017 Preview. the ICE was reported and they handle them seriously in due time. // the ICE is caused by decltype(auto) and const& return value @@ -77,15 +71,15 @@ using to_const_lvalue_reference_t = remove_cvref_t<t> const&; #define eval_once__3(expr, ident) \ ([&]() -> decltype(auto) { \ static auto INIT##ident = (expr); \ - return static_cast<to_const_lvalue_reference_t<decltype(INIT##ident)>>(INIT##ident); \ + return static_cast<to_const_cvref_t<decltype(INIT##ident)>>(INIT##ident); \ }()) #include <type_traits> template<typename t> -using cv_qualified = std::conditional_t<std::is_fundamental_v<std::decay_t<t>>, - std::decay_t<t>, - std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>>; +using cv_qualified = std::conditional_t<std::is_fundamental_v<remove_cvref_t<t>>, + remove_cvref_t<t>, + to_const_cvref_t<t>>; template<bool> [[deprecated]] constexpr cc_forceinline void static_warn() {} diff --git a/compat/math.hpp b/compat/math.hpp index 04a6e08d..656e10a8 100644 --- a/compat/math.hpp +++ b/compat/math.hpp @@ -13,10 +13,10 @@ inline auto clamp_float(n val, n min_, n max_) return std::fmin(std::fmax(val, min_), max_); } -template<typename t, typename n> +template<typename t> struct clamp final { - static inline auto clamp_(const n& val, const n& min_, const n& max_) + static inline auto clamp_(t val, t min_, t max_) { if (unlikely(val > max_)) return max_; @@ -26,8 +26,8 @@ struct clamp final } }; -template<typename t> -struct clamp<float, t> +template<> +struct clamp<float> { static inline auto clamp_(float val, float min_, float max_) { @@ -35,8 +35,8 @@ struct clamp<float, t> } }; -template<typename t> -struct clamp<double, t> +template<> +struct clamp<double> { static inline auto clamp_(double val, double min_, double max_) { @@ -46,29 +46,27 @@ struct clamp<double, t> } // ns util_detail -template<typename t, typename u, typename w> -inline auto clamp(const t& val, const u& min, const w& max) +template<typename t, typename u, typename v> +inline auto clamp(const t& val, const u& min, const v& max) { - using tp = decltype(val + min + max); - return ::util_detail::clamp<std::decay_t<tp>, tp>::clamp_(val, min, max); + using w = cv_qualified<decltype(val + min + max)>; + return ::util_detail::clamp<w>::clamp_(val, min, max); } -template<typename t, typename integral_type = int> -inline auto iround(t val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, integral_type> +template<typename t> +inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, int> { - return static_cast<integral_type>(std::round(val)); + return (int)std::round(val); } template<typename t> -inline auto uround(const t& val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, t> +inline auto uround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, unsigned> { - return (unsigned) std::fmax(0, std::round(val)); + return (unsigned)std::fmax(0, std::round(val)); } -#include "macros.hpp" - -template <typename T> -static cc_forceinline constexpr auto signum(T x) +template <typename t> +static cc_forceinline constexpr int signum(const t& x) { - return x < T(0) ? -1 : 1; + return x < t{0} ? -1 : 1; } diff --git a/gui/mapping-dialog.cpp b/gui/mapping-dialog.cpp index 83a045a0..021489dc 100644 --- a/gui/mapping-dialog.cpp +++ b/gui/mapping-dialog.cpp @@ -131,7 +131,7 @@ void mapping_dialog::load() using c = axis_opts::max_clamp; - auto update_xstep = [idx, &conf, &qfc](int clamp_x) { + auto update_xstep = [&qfc](int clamp_x) { int value; if (clamp_x <= c::r20) @@ -144,7 +144,7 @@ void mapping_dialog::load() qfc.set_x_step(value); }; - auto update_ystep = [idx, &conf, &qfc](int clamp_y) { + auto update_ystep = [&qfc](int clamp_y) { int value; switch (clamp_y) { @@ -159,10 +159,7 @@ void mapping_dialog::load() qfc.set_y_step(value); }; - if (idx >= Yaw) - qfc.set_snap(.5, 1); - else - qfc.set_snap(.5, 1); + qfc.set_snap(.5, 1); connect(&axis.opts.clamp_x_, value_::value_changed<int>(), &qfc, update_xstep); connect(&axis.opts.clamp_y_, value_::value_changed<int>(), &qfc, update_ystep); diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp index 1cae6db4..91dfc668 100644 --- a/logic/pipeline.hpp +++ b/logic/pipeline.hpp @@ -59,15 +59,10 @@ public: void on_center(); - cc_warn_unused_result euler_t rotate(const rmat& rmat, const euler_t& in, vec3_bool disable) const; - - cc_warn_unused_result + euler_t apply_neck(const rmat& R, int nz, bool disable_tz) const; Pose apply_pipeline(reltrans_state state, const Pose& value, const vec6_bool& disable, bool neck_enable, int neck_z); - - cc_warn_unused_result - euler_t apply_neck(const rmat& R, int nz, bool disable_tz) const; }; using namespace time_units; diff --git a/logic/win32-shortcuts.h b/logic/win32-shortcuts.h index af90472f..afc909ed 100644 --- a/logic/win32-shortcuts.h +++ b/logic/win32-shortcuts.h @@ -13,8 +13,8 @@ struct OTR_LOGIC_EXPORT win_key //win_key(int win, Qt::Key qt) : win(win), qt(qt) {} int win; Qt::Key qt; - static bool from_qt(const QKeySequence& qt_, int& dik, Qt::KeyboardModifiers &mods); - static bool to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods); + [[nodiscard]] static bool from_qt(const QKeySequence& qt_, int& dik, Qt::KeyboardModifiers &mods); + [[nodiscard]] static bool to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods); }; #endif diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index a4b9534f..2d66371c 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -49,7 +49,7 @@ void spline_widget::setConfig(base_spline* spl) update_range(); std::shared_ptr<base_spline::base_settings> s = spl->get_settings(); - connection = connect(s.get(), &spline::base_settings::recomputed, + connection = connect(s.get(), &base_spline::base_settings::recomputed, this, [this] { reload_spline(); }, Qt::QueuedConnection); } diff --git a/spline/spline-widget.hpp b/spline/spline-widget.hpp index 737b29f1..a6d0eb9d 100644 --- a/spline/spline-widget.hpp +++ b/spline/spline-widget.hpp @@ -34,7 +34,7 @@ class OTR_SPLINE_EXPORT spline_widget final : public QWidget Q_PROPERTY(int x_step READ x_step WRITE set_x_step) Q_PROPERTY(int y_step READ y_step WRITE set_y_step) - using points_t = spline::points_t; + using points_t = base_spline::points_t; public: explicit spline_widget(QWidget *parent = nullptr); ~spline_widget() override; diff --git a/spline/spline.cpp b/spline/spline.cpp index ae32b896..203822e7 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -100,7 +100,7 @@ float spline::get_value_no_save_internal(double x) return ret; } -cc_warn_unused_result bool spline::get_last_value(QPointF& point) +bool spline::get_last_value(QPointF& point) { QMutexLocker foo(&_mutex); point = last_input_value; diff --git a/spline/spline.hpp b/spline/spline.hpp index faecbb2c..eb6c7b8c 100644 --- a/spline/spline.hpp +++ b/spline/spline.hpp @@ -55,7 +55,7 @@ struct OTR_SPLINE_EXPORT base_spline_ virtual float get_value(double x) = 0; virtual float get_value_no_save(double x) const = 0; - cc_warn_unused_result virtual bool get_last_value(QPointF& point) = 0; + [[nodiscard]] virtual bool get_last_value(QPointF& point) = 0; virtual void set_tracking_active(bool value) = 0; virtual double max_input() const = 0; @@ -139,7 +139,7 @@ public: float get_value(double x) override; float get_value_no_save(double x) const override; - cc_warn_unused_result bool get_last_value(QPointF& point) override; + [[nodiscard]] bool get_last_value(QPointF& point) override; void add_point(QPointF pt) override; void add_point(double x, double y) override; diff --git a/tracker-pt/module/camera.h b/tracker-pt/module/camera.h index f3f88cc5..f8f140de 100644 --- a/tracker-pt/module/camera.h +++ b/tracker-pt/module/camera.h @@ -37,7 +37,7 @@ struct Camera final : pt_camera void show_camera_settings() override; private: - cc_warn_unused_result bool _get_frame(cv::Mat& Frame); + [[nodiscard]] bool _get_frame(cv::Mat& Frame); double dt_mean = 0, fov = 30; Timer t; @@ -56,7 +56,7 @@ private: pt_settings s; - static constexpr inline double dt_eps = 1./384; + static constexpr inline double dt_eps = 1./256; }; } // ns pt_module diff --git a/tracker-pt/pt-api.hpp b/tracker-pt/pt-api.hpp index 19fab03e..12085560 100644 --- a/tracker-pt/pt-api.hpp +++ b/tracker-pt/pt-api.hpp @@ -42,7 +42,7 @@ struct pt_frame : pt_pixel_pos_mixin template<typename t> t* as() & { - using u = std::decay_t<t>; + using u = remove_cvref_t<t>; static_assert(std::is_convertible_v<u*, pt_frame*>, "must be derived from pt_frame"); return static_cast<t*>(this); @@ -69,11 +69,11 @@ struct pt_camera pt_camera(); virtual ~pt_camera(); - virtual cc_warn_unused_result bool start(int idx, int fps, int res_x, int res_y) = 0; + [[nodiscard]] virtual bool start(int idx, int fps, int res_x, int res_y) = 0; virtual void stop() = 0; - virtual cc_warn_unused_result result get_frame(pt_frame& frame) = 0; - virtual cc_warn_unused_result result get_info() const = 0; + virtual result get_frame(pt_frame& frame) = 0; + virtual result get_info() const = 0; virtual pt_camera_info get_desired() const = 0; virtual QString get_desired_name() const = 0; |