refactor(clang-tidy): Apply fixes

This commit is contained in:
Michael Carlberg 2016-12-15 03:30:41 +01:00
parent 78b5f9651f
commit f9062d031c
42 changed files with 123 additions and 111 deletions

View File

@ -1,5 +1,5 @@
---
Checks: '-*,performance-*,readability-*,modernize-use-*,-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-*,-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

View File

@ -20,13 +20,16 @@ namespace alsa {
explicit control(int numid);
~control();
control(const control& o) = delete;
control& operator=(const control& o) = delete;
int get_numid();
bool wait(int timeout = -1);
bool test_device_plugged();
void process_events();
private:
std::mutex m_lock;
std::mutex m_lock{};
int m_numid{0};

View File

@ -20,6 +20,9 @@ namespace alsa {
explicit mixer(string&& mixer_selem_name);
~mixer();
mixer(const mixer& o) = delete;
mixer& operator=(const mixer& o) = delete;
const string& get_name();
bool wait(int timeout = -1);
@ -34,7 +37,7 @@ namespace alsa {
bool is_muted();
private:
std::mutex m_lock;
std::mutex m_lock{};
snd_mixer_t* m_mixer{nullptr};
snd_mixer_elem_t* m_elem{nullptr};

View File

@ -112,7 +112,7 @@ namespace mpd {
private:
const logger& m_log;
mpd_connection_t m_connection;
mpd_connection_t m_connection{};
bool m_listactive = false;
bool m_idle = false;
@ -151,21 +151,21 @@ namespace mpd {
int get_seek_position(int percentage);
private:
mpd_status_t m_status;
unique_ptr<mpdsong> m_song;
mpdstate m_state = mpdstate::UNKNOWN;
chrono::system_clock::time_point m_updated_at;
mpd_status_t m_status{};
unique_ptr<mpdsong> m_song{};
mpdstate m_state{mpdstate::UNKNOWN};
chrono::system_clock::time_point m_updated_at{};
bool m_random = false;
bool m_repeat = false;
bool m_single = false;
bool m_random{false};
bool m_repeat{false};
bool m_single{false};
int m_songid;
int m_queuelen;
int m_songid{0};
int m_queuelen{0};
unsigned long m_total_time;
unsigned long m_elapsed_time;
unsigned long m_elapsed_time_ms;
unsigned long m_total_time{0UL};
unsigned long m_elapsed_time{0UL};
unsigned long m_elapsed_time_ms{0UL};
};
// }}}

View File

@ -111,8 +111,8 @@ namespace net {
void query_quality(const int& socket_fd);
private:
shared_ptr<wireless_info> m_info;
string m_essid;
shared_ptr<wireless_info> m_info{};
string m_essid{};
quality_range m_signalstrength{};
quality_range m_linkquality{};
};

View File

@ -1,6 +1,7 @@
#pragma once
#include "common.hpp"
#include "components/renderer.hpp"
#include "components/screen.hpp"
#include "components/types.hpp"
#include "errors.hpp"
@ -20,7 +21,6 @@ POLYBAR_NS
class screen;
class tray_manager;
class logger;
class renderer;
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify> {
public:
@ -58,9 +58,9 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
bar_settings m_opts;
string m_lastinput;
string m_lastinput{};
std::mutex m_mutex;
std::mutex m_mutex{};
event_timer m_buttonpress{0L, 5L};
};

View File

@ -72,7 +72,7 @@ class builder {
private:
const bar_settings m_bar;
string m_output;
string m_output{};
map<syntaxtag, int> m_tags{
// clang-format off
@ -97,8 +97,8 @@ class builder {
uint8_t m_attributes{static_cast<uint8_t>(attribute::NONE)};
uint8_t m_fontindex{1};
string m_background;
string m_foreground;
string m_background{};
string m_foreground{};
};
POLYBAR_NS_END

View File

@ -58,10 +58,10 @@ namespace command_line {
void parse(const string& input, const string& input_next = "");
private:
string m_synopsis;
string m_synopsis{};
const options m_opts;
values m_optvalues;
bool m_skipnext = false;
values m_optvalues{};
bool m_skipnext{false};
};
// }}}

View File

@ -302,7 +302,7 @@ class config {
const xresource_manager& m_xrm;
string m_file;
string m_barname;
sectionmap_t m_sections;
sectionmap_t m_sections{};
};
POLYBAR_NS_END

View File

@ -1,6 +1,7 @@
#pragma once
#include <moodycamel/blockingconcurrentqueue.h>
#include <chrono>
#include <condition_variable>
#include <mutex>
@ -60,7 +61,7 @@ class eventloop : public signal_receiver<SIGN_PRIORITY_EVENTLOOP, process_quit,
void stop();
bool enqueue(event&& evt);
bool enqueue(string&& evt);
bool enqueue(string&& input_data);
void add_module(const alignment pos, module_t&& module);
const modulemap_t& modules() const;

View File

@ -47,8 +47,8 @@ class ipc {
private:
signal_emitter& m_sig;
const logger& m_log;
string m_fifo;
int m_fd;
string m_fifo{};
int m_fd{0};
stateflag m_running{false};
};

View File

@ -77,7 +77,7 @@ struct line_settings {
struct action {
mousebtn button{mousebtn::NONE};
string command;
string command{};
};
struct action_block : public action {
@ -95,9 +95,9 @@ struct bar_settings {
explicit bar_settings() = default;
bar_settings(const bar_settings& other) = default;
xcb_window_t window;
xcb_window_t window{XCB_NONE};
monitor_t monitor;
monitor_t monitor{};
edge origin{edge::TOP};
struct size size {
1U, 1U
@ -113,20 +113,20 @@ struct bar_settings {
uint32_t background{0xFFFFFFFF};
uint32_t foreground{0xFF000000};
line_settings underline;
line_settings overline;
line_settings underline{};
line_settings overline{};
std::unordered_map<edge, border_settings> borders;
std::unordered_map<edge, border_settings> borders{};
uint8_t spacing{1U};
string separator;
string separator{};
string wmname;
string locale;
string wmname{};
string locale{};
bool override_redirect{false};
vector<action> actions;
vector<action> actions{};
const xcb_rectangle_t inner_area(bool abspos = false) const {
xcb_rectangle_t rect{0, 0, size.w, size.h};

View File

@ -30,15 +30,15 @@ namespace drawtypes {
class label : public non_copyable_mixin<label> {
public:
string m_foreground;
string m_background;
string m_underline;
string m_overline;
int m_font = 0;
struct side_values m_padding = {0,0};
struct side_values m_margin = {0,0};
size_t m_maxlen = 0;
bool m_ellipsis = true;
string m_foreground{};
string m_background{};
string m_underline{};
string m_overline{};
int m_font{0};
side_values m_padding{0,0};
side_values m_margin{0,0};
size_t m_maxlen{0};
bool m_ellipsis{true};
explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {}
explicit label(string text, string foreground = "", string background = "", string underline = "",
@ -67,8 +67,9 @@ namespace drawtypes {
void copy_undefined(const label_t& label);
private:
string m_text, m_tokenized;
const vector<token> m_tokens;
string m_text{};
string m_tokenized{};
const vector<token> m_tokens{};
};
label_t load_label(const config& conf, const string& section, string name, bool required = true, string def = "");

View File

@ -16,6 +16,9 @@ namespace file_util {
~file_ptr();
file_ptr(const file_ptr& o) = delete;
file_ptr& operator=(const file_ptr& o) = delete;
operator bool();
FILE* operator()();

View File

@ -21,7 +21,7 @@ namespace inotify_util {
class inotify_watch {
public:
explicit inotify_watch(string path) : m_path(path) {}
explicit inotify_watch(string path);
~inotify_watch() noexcept;
void attach(int mask = IN_MODIFY);

View File

@ -76,9 +76,9 @@ namespace throttle_util {
}
private:
queue m_queue;
limit m_limit;
timewindow m_timewindow;
queue m_queue{};
limit m_limit{};
timewindow m_timewindow{};
};
using throttle_t = unique_ptr<event_throttler>;

View File

@ -5,7 +5,6 @@
#include <xcb/xcb.h>
#include <boost/optional.hpp>
#include <iomanip>
#include <xpp/xpp.hpp>
#include "common.hpp"
#include "utils/factory.hpp"
@ -30,6 +29,7 @@ class connection : public xpp_connection {
connection& operator=(const connection&) {
return *this;
}
connection(const connection& o) = delete;
virtual ~connection() {}

View File

@ -112,7 +112,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
bool is_embedded(const xcb_window_t& win) const;
shared_ptr<tray_client> find_client(const xcb_window_t& win) const;
void remove_client(shared_ptr<tray_client>& client, bool reconfigure = true);
void remove_client(xcb_window_t window, bool reconfigure = true);
void remove_client(xcb_window_t win, bool reconfigure = true);
size_t mapped_clients() const;
void handle(const evt::expose& evt);

View File

@ -52,13 +52,13 @@ class keyboard {
enum class type { NONE = 0U, CAPS_LOCK, NUM_LOCK };
xcb_atom_t atom{};
uint8_t mask{0};
string name;
string name{};
bool enabled{false};
};
struct layout {
string group_name;
vector<string> symbols;
string group_name{};
vector<string> symbols{};
};
explicit keyboard(vector<layout>&& layouts_, map<indicator::type, indicator>&& indicators_, uint8_t group)

View File

@ -15,6 +15,9 @@ class xresource_manager {
explicit xresource_manager(shared_ptr<Display>&&);
~xresource_manager();
xresource_manager(const xresource_manager& o) = delete;
xresource_manager& operator=(const xresource_manager& o) = delete;
string get_string(string name, string fallback = "") const;
float get_float(string name, float fallback = 0.0f) const;
int get_int(string name, int fallback = 0) const;

View File

@ -1,4 +1,4 @@
#include <math.h>
#include <cmath>
#include "adapters/alsa/generic.hpp"
#include "adapters/alsa/mixer.hpp"

View File

@ -5,7 +5,6 @@
#include "components/bar.hpp"
#include "components/config.hpp"
#include "components/parser.hpp"
#include "components/renderer.hpp"
#include "components/screen.hpp"
#include "events/signal.hpp"
#include "events/signal_emitter.hpp"

View File

@ -109,14 +109,13 @@ void config::parse_file() {
}
string key{forward<string>(string_util::trim(forward<string>(line.substr(0, equal_pos)), ' '))};
string value{""};
string value;
auto it = m_sections[section].find(key);
if (it != m_sections[section].end()) {
throw key_error("Duplicate key name \"" + key + "\" defined on line " + to_string(lineno));
}
if (equal_pos + 1 < line.size()) {
value = string_util::trim(forward<string>(string_util::trim(line.substr(equal_pos + 1), ' ')), '"');
}

View File

@ -41,7 +41,8 @@ controller::make_type controller::make(string&& path_confwatch, bool enable_ipc,
* Construct controller object
*/
controller::controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config,
unique_ptr<eventloop>&& eventloop, unique_ptr<bar>&& bar, unique_ptr<ipc>&& ipc, watch_t&& confwatch, bool writeback)
unique_ptr<eventloop>&& eventloop, unique_ptr<bar>&& bar, unique_ptr<ipc>&& ipc, watch_t&& confwatch,
bool writeback)
: m_connection(conn)
, m_sig(emitter)
, m_log(logger)

View File

@ -20,8 +20,7 @@ using namespace signals::eventloop;
* Create instance
*/
screen::make_type screen::make() {
return factory_util::unique<screen>(
connection::make(), signal_emitter::make(), logger::make(), config::make());
return factory_util::unique<screen>(connection::make(), signal_emitter::make(), logger::make(), config::make());
}
/**

View File

@ -1,7 +1,7 @@
#include <utility>
#include "drawtypes/progressbar.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "utils/factory.hpp"
#include "utils/math.hpp"

View File

@ -1,5 +1,5 @@
#include <istream>
#include <fstream>
#include <istream>
#include "modules/cpu.hpp"

View File

@ -199,13 +199,15 @@ namespace modules {
}
try {
using namespace i3_util;
string scrolldir;
const i3_util::connection_t conn{};
const connection_t conn{};
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
const string workspace_num{cmd.substr(strlen(EVENT_CLICK))};
if (i3_util::focused_workspace(conn)->num != atoi(workspace_num.c_str())) {
if (focused_workspace(conn)->num != atoi(workspace_num.c_str())) {
m_log.info("%s: Sending workspace focus command to ipc handler", name());
conn.send_command("workspace number " + workspace_num);
}
@ -217,12 +219,14 @@ namespace modules {
return false;
}
if (scrolldir == "next" && (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).back() != *i3_util::focused_workspace(conn))) {
const string& mon_name{m_bar.monitor->name};
if (scrolldir == "next" && (m_wrap || *workspaces(conn, mon_name).back() != *focused_workspace(conn))) {
m_log.info("%s: Sending workspace next command to ipc handler", name());
i3_util::connection_t{}.send_command("workspace next_on_output");
} else if (scrolldir == "prev" && (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).front() != *i3_util::focused_workspace(conn))) {
conn.send_command("workspace next_on_output");
} else if (scrolldir == "prev" && (m_wrap || *workspaces(conn, mon_name).front() != *focused_workspace(conn))) {
m_log.info("%s: Sending workspace prev command to ipc handler", name());
i3_util::connection_t{}.send_command("workspace prev_on_output");
conn.send_command("workspace prev_on_output");
}
} catch (const exception& err) {
m_log.err("%s: %s", name(), err.what());

View File

@ -1,5 +1,5 @@
#include <istream>
#include <fstream>
#include <istream>
#include "modules/memory.hpp"

View File

@ -123,7 +123,6 @@ namespace modules {
m_output += m_ellipsis ? "..." : "";
}
auto counter_str = to_string(m_counter);
string output{module::get_output()};

View File

@ -20,8 +20,7 @@ namespace modules {
* Construct module
*/
xbacklight_module::xbacklight_module(const bar_settings& bar, string name)
: static_module<xbacklight_module>(bar, move(name))
, m_connection(connection::make()) {}
: static_module<xbacklight_module>(bar, move(name)), m_connection(connection::make()) {}
/**
* Bootstrap the module by grabbing all required components

View File

@ -20,10 +20,8 @@ namespace modules {
/**
* Construct module
*/
xworkspaces_module::xworkspaces_module(
const bar_settings& bar, string name)
: static_module<xworkspaces_module>(bar, move(name))
, m_connection(connection::make()) {}
xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name)
: static_module<xworkspaces_module>(bar, move(name)), m_connection(connection::make()) {}
/**
* Bootstrap the module

View File

@ -11,7 +11,7 @@
POLYBAR_NS
namespace command_util {
command::command(const logger& logger, string cmd) : m_log(logger), m_cmd(cmd) {
command::command(const logger& logger, string cmd) : m_log(logger), m_cmd(move(cmd)) {
if (pipe(m_stdin) != 0) {
throw command_strerror("Failed to allocate input stream");
}

View File

@ -1,6 +1,6 @@
#include <cstring>
#include <thread>
#include <utility>
#include <cstring>
#include "utils/env.hpp"

View File

@ -8,6 +8,11 @@
POLYBAR_NS
namespace inotify_util {
/**
* Construct instance
*/
inotify_watch::inotify_watch(string path) : m_path(move(path)) {}
/**
* Destructor
*/
@ -111,7 +116,7 @@ namespace inotify_util {
}
watch_t make_watch(string path) {
return watch_t{new watch_t::element_type{path}};
return make_unique<watch_t::element_type>(move(path));
}
}

View File

@ -37,7 +37,7 @@ namespace process_util {
* Execute command using shell
*/
void exec_sh(const char* cmd) {
static const string shell{env_util::get("SHELL", "/bin/sh").c_str()};
static const string shell{env_util::get("SHELL", "/bin/sh")};
if (cmd != nullptr) {
execlp(shell.c_str(), shell.c_str(), "-c", cmd, nullptr);

View File

@ -1,6 +1,6 @@
#include <iomanip>
#include <utility>
#include <map>
#include <utility>
#include "errors.hpp"
#include "utils/color.hpp"

View File

@ -9,7 +9,7 @@ namespace ewmh_util {
ewmh_connection_t initialize() {
if (!g_ewmh_connection) {
g_ewmh_connection = memory_util::make_malloc_ptr<xcb_ewmh_connection_t>(
sizeof(xcb_ewmh_connection_t), bind(xcb_ewmh_connection_wipe, std::placeholders::_1));
sizeof(xcb_ewmh_connection_t), [=](xcb_ewmh_connection_t* c) { xcb_ewmh_connection_wipe(c); });
auto* conn = g_ewmh_connection.get();

View File

@ -14,17 +14,15 @@ POLYBAR_NS
* Create window and check for errors
*/
window window::create_checked(int16_t x, int16_t y, uint16_t w, uint16_t h, uint32_t mask, const xcb_params_cw_t* p) {
auto conn = connection();
if (*this == XCB_NONE) {
*this = conn.generate_id();
*this = connection().generate_id();
}
auto root = conn.screen()->root;
auto root = connection().screen()->root;
auto copy = XCB_COPY_FROM_PARENT;
uint32_t values[16]{0};
xutils::pack_values(mask, p, values);
conn.create_window_checked(copy, *this, root, x, y, w, h, 0, copy, copy, mask, values);
connection().create_window_checked(copy, *this, root, x, y, w, h, 0, copy, copy, mask, values);
return *this;
}
@ -85,8 +83,6 @@ window window::reconfigure_pos(int16_t x, int16_t y) {
* Reconfigure the windows ewmh strut
*/
window window::reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom) {
auto& conn = connection();
uint32_t none{0};
uint32_t values[12]{none};
@ -100,8 +96,9 @@ window window::reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom
values[static_cast<int>(strut::TOP_END_X)] = x + w - 1;
}
conn.change_property_checked(XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT, XCB_ATOM_CARDINAL, 32, 4, values);
conn.change_property_checked(XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 32, 12, values);
connection().change_property_checked(XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT, XCB_ATOM_CARDINAL, 32, 4, values);
connection().change_property_checked(
XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 32, 12, values);
return *this;
}
@ -110,10 +107,9 @@ window window::reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom
* Trigger redraw by toggling visibility state
*/
void window::redraw() {
auto conn = connection();
xutils::visibility_notify(conn, *this, XCB_VISIBILITY_FULLY_OBSCURED);
xutils::visibility_notify(conn, *this, XCB_VISIBILITY_UNOBSCURED);
conn.flush();
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_FULLY_OBSCURED);
xutils::visibility_notify(connection(), *this, XCB_VISIBILITY_UNOBSCURED);
connection().flush();
}
POLYBAR_NS_END

View File

@ -101,9 +101,8 @@ namespace xkb_util {
xcb_xkb_get_names_value_list_t values;
void* buffer = xcb_xkb_get_names_value_list(reply);
xcb_xkb_get_names_value_list_unpack(buffer, reply->nTypes, reply->indicators,
reply->virtualMods, reply->groupNames, reply->nKeys, reply->nKeyAliases, reply->nRadioGroups, reply->which,
&values);
xcb_xkb_get_names_value_list_unpack(buffer, reply->nTypes, reply->indicators, reply->virtualMods, reply->groupNames,
reply->nKeys, reply->nKeyAliases, reply->nRadioGroups, reply->which, &values);
vector<reply::get_atom_name> replies;
for (int i = 0; i < xcb_xkb_get_names_value_list_groups_length(reply, &values); i++) {
@ -143,9 +142,8 @@ namespace xkb_util {
xcb_xkb_get_names_value_list_t values;
void* buffer = xcb_xkb_get_names_value_list(reply);
xcb_xkb_get_names_value_list_unpack(buffer, reply->nTypes, reply->indicators,
reply->virtualMods, reply->groupNames, reply->nKeys, reply->nKeyAliases, reply->nRadioGroups, reply->which,
&values);
xcb_xkb_get_names_value_list_unpack(buffer, reply->nTypes, reply->indicators, reply->virtualMods, reply->groupNames,
reply->nKeys, reply->nKeyAliases, reply->nRadioGroups, reply->which, &values);
map<xcb_atom_t, reply::get_atom_name> entries;
for (int i = 0; i < xcb_xkb_get_names_value_list_indicator_names_length(reply, &values); i++) {

View File

@ -19,7 +19,7 @@ namespace xlib {
if (!g_visual_ptr) {
XVisualInfo info;
if (XMatchVisualInfo(get_display().get(), screen, 32, TrueColor, &info)) {
g_visual_ptr = shared_ptr<Visual>(info.visual, bind(XFree, placeholders::_1));
g_visual_ptr = shared_ptr<Visual>(info.visual, [=](Visual* v) { XFree(v); });
}
}

View File

@ -19,7 +19,8 @@ namespace xutils {
if (dsp) {
XSetEventQueueOwner(dsp.get(), XCBOwnsEventQueue);
g_connection_ptr = shared_ptr<xcb_connection_t>(XGetXCBConnection(dsp.get()), bind(xcb_disconnect, placeholders::_1));
g_connection_ptr =
shared_ptr<xcb_connection_t>(XGetXCBConnection(dsp.get()), [=](xcb_connection_t* c) { xcb_disconnect(c); });
}
}