From ff9be848c7afb18bca8c5d30c114cf33359883ad Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 25 Nov 2016 13:55:15 +0100 Subject: [PATCH] refactor(clang-tidy): Apply fixes --- .clang-tidy | 2 +- cmake/build/core.cmake | 1 - include/adapters/alsa.hpp | 25 ++-- include/adapters/mpd.hpp | 1 + include/adapters/net.hpp | 3 +- include/common.hpp | 32 ----- include/components/bar.hpp | 3 +- include/components/builder.hpp | 10 +- include/components/command_line.hpp | 13 ++- include/components/config.hpp | 3 +- include/components/controller.hpp | 2 +- include/components/eventloop.hpp | 2 +- include/components/ipc.hpp | 6 +- include/components/logger.hpp | 2 +- include/components/parser.hpp | 5 +- include/components/renderer.hpp | 2 +- include/drawtypes/animation.hpp | 3 +- include/drawtypes/iconset.hpp | 4 +- include/drawtypes/label.hpp | 6 +- include/drawtypes/progressbar.hpp | 4 +- include/drawtypes/ramp.hpp | 2 +- include/errors.hpp | 32 +++++ include/modules/backlight.hpp | 4 +- include/modules/battery.hpp | 2 +- include/modules/bspwm.hpp | 2 +- include/modules/counter.hpp | 2 +- include/modules/cpu.hpp | 2 +- include/modules/date.hpp | 2 +- include/modules/fs.hpp | 2 +- include/modules/i3.hpp | 2 +- include/modules/ipc.hpp | 4 +- include/modules/memory.hpp | 2 +- include/modules/menu.hpp | 2 +- include/modules/meta/base.hpp | 7 +- include/modules/mpd.hpp | 2 +- include/modules/network.hpp | 2 +- include/modules/script.hpp | 2 +- include/modules/temperature.hpp | 2 +- include/modules/unsupported.hpp | 8 ++ include/modules/volume.hpp | 6 +- include/modules/xbacklight.hpp | 6 +- include/modules/xwindow.hpp | 2 +- include/utils/bspwm.hpp | 2 +- include/utils/file.hpp | 4 +- include/utils/i3.hpp | 2 +- include/utils/io.hpp | 6 +- include/utils/process.hpp | 2 +- include/utils/socket.hpp | 2 +- include/utils/string.hpp | 16 +-- include/x11/connection.hpp | 4 +- include/x11/fonts.hpp | 2 +- include/x11/tray.hpp | 9 +- include/x11/wm.hpp | 2 +- include/x11/xresources.hpp | 2 +- src/adapters/alsa.cpp | 168 ++++++++++++++++++++------- src/adapters/mpd.cpp | 50 +++++--- src/adapters/net.cpp | 87 +++++++++----- src/components/bar.cpp | 57 +++++---- src/components/builder.cpp | 166 ++++++++++++++++---------- src/components/command_line.cpp | 44 +++---- src/components/config.cpp | 22 ++-- src/components/controller.cpp | 94 ++++++++------- src/components/eventloop.cpp | 24 ++-- src/components/ipc.cpp | 27 +++-- src/components/logger.cpp | 21 ++-- src/components/parser.cpp | 44 ++++--- src/components/renderer.cpp | 43 ++++--- src/drawtypes/animation.cpp | 15 ++- src/drawtypes/iconset.cpp | 9 +- src/drawtypes/label.cpp | 79 ++++++++----- src/drawtypes/progressbar.cpp | 44 ++++--- src/drawtypes/ramp.cpp | 9 +- src/main.cpp | 3 +- src/modules/backlight.cpp | 30 +++-- src/modules/battery.cpp | 83 ++++++++----- src/modules/bspwm.cpp | 43 ++++--- src/modules/counter.cpp | 2 +- src/modules/cpu.cpp | 53 +++++---- src/modules/date.cpp | 16 ++- src/modules/fs.cpp | 20 ++-- src/modules/i3.cpp | 48 ++++---- src/modules/ipc.cpp | 22 ++-- src/modules/memory.cpp | 27 +++-- src/modules/menu.cpp | 32 +++-- src/modules/meta/base.cpp | 76 +++++++----- src/modules/mpd.cpp | 145 +++++++++++++---------- src/modules/network.cpp | 54 +++++---- src/modules/script.cpp | 27 +++-- src/modules/temperature.cpp | 34 +++--- src/modules/text.cpp | 18 ++- src/modules/volume.cpp | 173 ++++++++++++++++++---------- src/modules/xbacklight.cpp | 41 ++++--- src/modules/xwindow.cpp | 2 +- src/utils/bspwm.cpp | 18 ++- src/utils/command.cpp | 73 +++++++----- src/utils/env.cpp | 3 +- src/utils/file.cpp | 18 +-- src/utils/i3.cpp | 2 +- src/utils/inotify.cpp | 22 ++-- src/utils/io.cpp | 35 +++--- src/utils/process.cpp | 15 ++- src/utils/socket.cpp | 21 ++-- src/utils/string.cpp | 73 ++++++++---- src/utils/throttle.cpp | 7 +- src/x11/color.cpp | 4 +- src/x11/connection.cpp | 27 +++-- src/x11/draw.cpp | 6 +- src/x11/ewmh.cpp | 9 +- src/x11/fonts.cpp | 51 +++++--- src/x11/graphics.cpp | 1 + src/x11/icccm.cpp | 6 +- src/x11/randr.cpp | 38 +++--- src/x11/tray.cpp | 80 +++++++++---- src/x11/winspec.cpp | 12 +- src/x11/wm.cpp | 2 +- src/x11/xembed.cpp | 4 +- src/x11/xlib.cpp | 3 +- src/x11/xresources.cpp | 34 +++--- src/x11/xutils.cpp | 3 +- 119 files changed, 1752 insertions(+), 1046 deletions(-) create mode 100644 include/errors.hpp diff --git a/.clang-tidy b/.clang-tidy index 5da6bc80..ceec6c43 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '-*,performance-faster-string-find,performance-for-range-copy,readability-*,modernize-*,-modernize-raw-string-literal,-modernize-use-bool-literals,-readability-implicit-bool-cast,-readability-else-after-return,-readability-named-parameter' +Checks: '-*,performance-*,readability-*,modernize-use-*,-modernize-raw-string-literal,-modernize-use-bool-literals,-readability-implicit-bool-cast,-readability-else-after-return,-readability-named-parameter' CheckOptions: - key: modernize-loop-convert.NamingStyle value: lower_case diff --git a/cmake/build/core.cmake b/cmake/build/core.cmake index 76a6cb3d..1d6f0e2c 100644 --- a/cmake/build/core.cmake +++ b/cmake/build/core.cmake @@ -21,7 +21,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") diff --git a/include/adapters/alsa.hpp b/include/adapters/alsa.hpp index d5dc2c76..9bcf17da 100644 --- a/include/adapters/alsa.hpp +++ b/include/adapters/alsa.hpp @@ -9,6 +9,7 @@ #include "common.hpp" #include "config.hpp" +#include "errors.hpp" #include "utils/concurrency.hpp" #define MAX_LINEAR_DB_SCALE 24 @@ -40,17 +41,17 @@ class alsa_ctl_interface { void process_events(); private: - int m_numid = 0; + int m_numid{0}; - concurrency_util::spin_lock m_lock; + std::mutex m_lock; - snd_hctl_t* m_hctl = nullptr; - snd_hctl_elem_t* m_elem = nullptr; + snd_hctl_t* m_hctl{nullptr}; + snd_hctl_elem_t* m_elem{nullptr}; - snd_ctl_t* m_ctl = nullptr; - snd_ctl_elem_info_t* m_info = nullptr; - snd_ctl_elem_value_t* m_value = nullptr; - snd_ctl_elem_id_t* m_id = nullptr; + snd_ctl_t* m_ctl{nullptr}; + snd_ctl_elem_info_t* m_info{nullptr}; + snd_ctl_elem_value_t* m_value{nullptr}; + snd_ctl_elem_id_t* m_id{nullptr}; }; // }}} @@ -58,7 +59,7 @@ class alsa_ctl_interface { class alsa_mixer { public: - explicit alsa_mixer(string mixer_control_name); + explicit alsa_mixer(const string& mixer_control_name); ~alsa_mixer(); string get_name(); @@ -77,10 +78,10 @@ class alsa_mixer { private: string m_name; - concurrency_util::spin_lock m_lock; + std::mutex m_lock; - snd_mixer_t* m_hardwaremixer = nullptr; - snd_mixer_elem_t* m_mixerelement = nullptr; + snd_mixer_t* m_hardwaremixer{nullptr}; + snd_mixer_elem_t* m_mixerelement{nullptr}; }; // }}} diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index 43b29f9a..685bac48 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -5,6 +5,7 @@ #include #include "common.hpp" +#include "errors.hpp" POLYBAR_NS diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index 4cd57a93..ea0f91dc 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -12,6 +12,7 @@ #include "common.hpp" #include "config.hpp" +#include "errors.hpp" POLYBAR_NS @@ -20,7 +21,7 @@ namespace chrono = std::chrono; namespace net { DEFINE_ERROR(network_error); - bool is_wireless_interface(string ifname); + bool is_wireless_interface(const string& ifname); // types {{{ diff --git a/include/common.hpp b/include/common.hpp index 2ad4cb7d..b8afaea7 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -5,7 +5,6 @@ #endif #include -#include #include #include #include @@ -42,10 +41,6 @@ POLYBAR_NS -//================================================== -// Include common types (i.e, unclutter editor!) -//================================================== - namespace di = boost::di; namespace placeholders = std::placeholders; @@ -66,32 +61,5 @@ using std::array; using std::map; using std::vector; using std::to_string; -using std::strerror; -using std::exception; - -//================================================== -// Errors and exceptions -//================================================== - -class application_error : public std::runtime_error { - public: - int m_code; - - explicit application_error(string&& message, int code = 0) - : std::runtime_error(forward(message)), m_code(code) {} -}; - -class system_error : public application_error { - public: - explicit system_error() : application_error(strerror(errno), errno) {} - explicit system_error(string&& message) - : application_error(forward(message) + " (reason: " + strerror(errno) + ")", errno) {} -}; - -#define DEFINE_CHILD_ERROR(error, parent) \ - class error : public parent { \ - using parent::parent; \ - } -#define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error) POLYBAR_NS_END diff --git a/include/components/bar.hpp b/include/components/bar.hpp index b188d0b7..1de9156c 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -3,6 +3,7 @@ #include "common.hpp" #include "components/config.hpp" #include "components/types.hpp" +#include "errors.hpp" #include "utils/concurrency.hpp" #include "utils/throttle.hpp" #include "x11/connection.hpp" @@ -28,7 +29,7 @@ class bar : public xpp::event::sink defined_bars() const; string build_path(const string& section, const string& key) const; - void warn_deprecated(string section, string key, string replacement) const; + void warn_deprecated(const string& section, const string& key, string replacement) const; /** * Get parameter for the current bar by name diff --git a/include/components/controller.hpp b/include/components/controller.hpp index 731c84aa..d19f170e 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -52,7 +52,7 @@ class controller { void bootstrap_modules(); void on_ipc_action(const ipc_action& message); - void on_mouse_event(string input); + void on_mouse_event(const string& input); void on_unrecognized_action(string input); void on_update(); diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index 0096a5d2..c86dce19 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -49,7 +49,7 @@ class eventloop { void forward_event(entry_t evt); void on_update(); - void on_input(string input); + void on_input(char* input); void on_check(); void on_quit(); diff --git a/include/components/ipc.hpp b/include/components/ipc.hpp index c12c10c3..d32c61f2 100644 --- a/include/components/ipc.hpp +++ b/include/components/ipc.hpp @@ -42,9 +42,9 @@ class ipc { protected: void parse(const string& payload) const; - void delegate(const ipc_command& msg) const; - void delegate(const ipc_hook& msg) const; - void delegate(const ipc_action& msg) const; + void delegate(const ipc_command& message) const; + void delegate(const ipc_hook& message) const; + void delegate(const ipc_action& message) const; private: const logger& m_log; diff --git a/include/components/logger.hpp b/include/components/logger.hpp index aafee342..41651c65 100644 --- a/include/components/logger.hpp +++ b/include/components/logger.hpp @@ -15,7 +15,7 @@ enum class loglevel { TRACE, }; -loglevel parse_loglevel_name(string name); +loglevel parse_loglevel_name(const string& name); class logger { public: diff --git a/include/components/parser.hpp b/include/components/parser.hpp index cb96cd81..f1d41841 100644 --- a/include/components/parser.hpp +++ b/include/components/parser.hpp @@ -1,6 +1,7 @@ #pragma once #include "common.hpp" +#include "errors.hpp" POLYBAR_NS @@ -24,9 +25,9 @@ class parser { protected: uint32_t parse_color(string s, uint32_t fallback = 0); int8_t parse_fontindex(string s); - attribute parse_attr(const char s); + attribute parse_attr(const char attr); mousebtn parse_action_btn(string data); - string parse_action_cmd(string data); + string parse_action_cmd(const string& data); private: const logger& m_log; diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index f1db7005..b3b635cc 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -44,7 +44,7 @@ class renderer { void draw_character(const uint16_t character); void draw_textstring(const char* text, const size_t len); - void begin_action(const mousebtn btn, const string cmd); + void begin_action(const mousebtn btn, const string& cmd); void end_action(const mousebtn btn); const vector get_actions(); diff --git a/include/drawtypes/animation.hpp b/include/drawtypes/animation.hpp index b2ef98da..22aa7d58 100644 --- a/include/drawtypes/animation.hpp +++ b/include/drawtypes/animation.hpp @@ -38,7 +38,8 @@ namespace drawtypes { using animation_t = shared_ptr; - animation_t load_animation(const config& conf, string section, string name = "animation", bool required = true); + animation_t load_animation( + const config& conf, const string& section, string name = "animation", bool required = true); } POLYBAR_NS_END diff --git a/include/drawtypes/iconset.hpp b/include/drawtypes/iconset.hpp index f4d7ab1b..78683a32 100644 --- a/include/drawtypes/iconset.hpp +++ b/include/drawtypes/iconset.hpp @@ -10,8 +10,8 @@ namespace drawtypes { class iconset : public non_copyable_mixin { public: void add(string id, icon_t&& icon); - bool has(string id); - icon_t get(string id, string fallback_id = ""); + bool has(const string& id); + icon_t get(const string& id, const string& fallback_id = ""); operator bool(); protected: diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index 6a6ad764..5ecd5092 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -59,8 +59,8 @@ namespace drawtypes { operator bool(); label_t clone(); void reset_tokens(); - bool has_token(string token); - void replace_token(string token, string replacement); + bool has_token(const string& token); + void replace_token(const string& token, string replacement); void replace_defined_values(const label_t& label); void copy_undefined(const label_t& label); @@ -69,7 +69,7 @@ namespace drawtypes { const vector m_token_bounds; }; - label_t load_label(const config& conf, string section, string name, bool required = true, string def = ""); + label_t load_label(const config& conf, const string& section, string name, bool required = true, string def = ""); label_t load_optional_label(const config& conf, string section, string name, string def = ""); diff --git a/include/drawtypes/progressbar.hpp b/include/drawtypes/progressbar.hpp index c9c026b1..a3416e40 100644 --- a/include/drawtypes/progressbar.hpp +++ b/include/drawtypes/progressbar.hpp @@ -12,7 +12,7 @@ POLYBAR_NS namespace drawtypes { class progressbar : public non_copyable_mixin { public: - explicit progressbar(const bar_settings bar, int width, string format); + explicit progressbar(const bar_settings& bar, int width, string format); void set_fill(icon_t&& fill); void set_empty(icon_t&& empty); @@ -40,7 +40,7 @@ namespace drawtypes { using progressbar_t = shared_ptr; - progressbar_t load_progressbar(const bar_settings& bar, const config& conf, string section, string name); + progressbar_t load_progressbar(const bar_settings& bar, const config& conf, const string& section, string name); } POLYBAR_NS_END diff --git a/include/drawtypes/ramp.hpp b/include/drawtypes/ramp.hpp index 5499f34f..270b7347 100644 --- a/include/drawtypes/ramp.hpp +++ b/include/drawtypes/ramp.hpp @@ -24,7 +24,7 @@ namespace drawtypes { using ramp_t = shared_ptr; - ramp_t load_ramp(const config& conf, string section, string name, bool required = true); + ramp_t load_ramp(const config& conf, const string& section, string name, bool required = true); } POLYBAR_NS_END diff --git a/include/errors.hpp b/include/errors.hpp new file mode 100644 index 00000000..4b7afbc0 --- /dev/null +++ b/include/errors.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include "common.hpp" + +POLYBAR_NS + +using std::strerror; +using std::exception; +using std::runtime_error; + +class application_error : public runtime_error { + public: + explicit application_error(const string& message, int code = 0) : runtime_error(message), code(code) {} + int code{0}; +}; + +class system_error : public application_error { + public: + explicit system_error() : application_error(strerror(errno), errno) {} + explicit system_error(const string& message) + : application_error(message + " (reason: " + strerror(errno) + ")", errno) {} +}; + +#define DEFINE_CHILD_ERROR(error, parent) \ + class error : public parent { \ + using parent::parent; \ + } +#define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error) + +POLYBAR_NS_END diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index 4fa543d9..56887b6d 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -8,7 +8,7 @@ POLYBAR_NS namespace modules { struct brightness_handle { - void filepath(string path); + void filepath(const string& path); float read() const; private: @@ -22,7 +22,7 @@ namespace modules { void setup(); void idle(); bool on_event(inotify_event* event); - bool build(builder* builder, string tag) const; + bool build(builder* builder, const string& tag) const; private: static constexpr auto TAG_LABEL = "