From 39d3f6149739d2d7d39e377aaa97ca10803fc575 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 31 May 2016 05:58:58 +0200 Subject: [PATCH] refactor(core): Clean-up - use "#pragma once" instead of the regular include guard - fix errors and warnings reported by cppcheck --- CMakeLists.txt | 8 +-- include/bar.hpp | 7 +-- include/config.hpp.cmake | 5 +- include/drawtypes/animation.hpp | 7 +-- include/drawtypes/bar.hpp | 9 ++-- include/drawtypes/icon.hpp | 5 +- include/drawtypes/label.hpp | 5 +- include/drawtypes/ramp.hpp | 7 +-- include/eventloop.hpp | 7 +-- include/exception.hpp | 10 ++-- include/interfaces/alsa.hpp | 24 ++++----- include/interfaces/mpd.hpp | 29 ++++++----- include/interfaces/net.hpp | 32 +++++------- include/lemonbuddy.hpp | 5 +- include/modules/backlight.hpp | 20 ++++---- include/modules/base.hpp | 49 ++++++++++--------- include/modules/battery.hpp | 9 ++-- include/modules/bspwm.hpp | 13 ++--- include/modules/counter.hpp | 9 ++-- include/modules/cpu.hpp | 17 +++---- include/modules/date.hpp | 15 ++---- include/modules/i3.hpp | 18 ++----- include/modules/memory.hpp | 13 ++--- include/modules/menu.hpp | 17 +++---- include/modules/mpd.hpp | 57 ++++++++++----------- include/modules/network.hpp | 23 ++++----- include/modules/script.hpp | 9 ++-- include/modules/text.hpp | 9 ++-- include/modules/torrent.hpp | 11 ++--- include/modules/volume.hpp | 25 +++++----- include/registry.hpp | 17 ++----- include/services/builder.hpp | 9 ++-- include/services/command.hpp | 24 ++++----- include/services/inotify.hpp | 9 ++-- include/services/logger.hpp | 8 ++- include/services/store.hpp | 4 ++ include/utils/cli.hpp | 10 +--- include/utils/concurrency.hpp | 6 ++- include/utils/config.hpp | 52 +++++--------------- include/utils/io.hpp | 16 +++--- include/utils/macros.hpp | 13 +++++ include/utils/math.hpp | 5 +- include/utils/memory.hpp | 5 +- include/utils/proc.hpp | 16 ++---- include/utils/streams.hpp | 5 +- include/utils/string.hpp | 12 ++--- include/utils/timer.hpp | 9 ++-- include/utils/xlib.hpp | 7 +-- src/bar.cpp | 6 +-- src/drawtypes/animation.cpp | 2 +- src/drawtypes/bar.cpp | 9 ++-- src/eventloop.cpp | 36 +++++++------- src/interfaces/alsa.cpp | 32 ++++++------ src/interfaces/mpd.cpp | 87 +++++++++++++++++---------------- src/interfaces/net.cpp | 29 +++++------ src/lemonbuddy.cpp | 9 ++-- src/modules/backlight.cpp | 18 ++++--- src/modules/battery.cpp | 11 +++-- src/modules/bspwm.cpp | 23 +++++---- src/modules/cpu.cpp | 5 +- src/modules/date.cpp | 4 +- src/modules/i3.cpp | 3 +- src/modules/memory.cpp | 3 +- src/modules/menu.cpp | 4 +- src/modules/mpd.cpp | 23 ++++----- src/modules/network.cpp | 7 +-- src/modules/script.cpp | 6 +-- src/modules/text.cpp | 2 +- src/modules/volume.cpp | 11 ++--- src/registry.cpp | 4 +- src/services/builder.cpp | 6 +-- src/services/command.cpp | 74 ++++++++++++++-------------- src/services/inotify.cpp | 11 +++-- src/services/logger.cpp | 8 +-- src/utils/cli.cpp | 3 +- src/utils/config.cpp | 19 +++---- src/utils/io.cpp | 44 ++++++++--------- src/utils/proc.cpp | 13 ++--- src/utils/string.cpp | 30 ++++++------ src/utils/timer.cpp | 2 + src/utils/xlib.cpp | 73 ++++++++++++++------------- 81 files changed, 588 insertions(+), 730 deletions(-) create mode 100644 include/utils/macros.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 77b5c1c9..e716217d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ set(PROJECT_LINK_LIBS if(ENABLE_I3) find_program(I3_EXECUTABLE "i3") if(NOT I3_EXECUTABLE) - message(WARNING "${ANSI}[41;30mDisabling \"i3 module\" support (prerequisites failed)${ANSI}[0m") + message(WARNING "${ANSI}[41;1mDisabling \"i3 module\" support (prerequisites failed)${ANSI}[0m") set(ENABLE_I3 OFF) endif() endif() @@ -109,7 +109,7 @@ if(ENABLE_ALSA) set(PROJECT_INCL_DIRS ${PROJECT_INCL_DIRS} ${ALSA_INCLUDE_DIR}) set(PROJECT_LINK_LIBS ${PROJECT_LINK_LIBS} ${ALSA_LIBRARY}) else(ALSA_FOUND) - message(WARNING "${ANSI}[41;30mDisabling \"volume module\" support (prerequisites failed)${ANSI}[0m") + message(WARNING "${ANSI}[41;1mDisabling \"volume module\" support (prerequisites failed)${ANSI}[0m") set(ENABLE_ALSA OFF) endif() endif() @@ -120,7 +120,7 @@ if(ENABLE_MPD) set(PROJECT_INCL_DIRS ${PROJECT_INCL_DIRS} ${LIBMPDCLIENT_INCLUDE_DIR}) set(PROJECT_LINK_LIBS ${PROJECT_LINK_LIBS} ${LIBMPDCLIENT_LIBRARY}) else(LIBMPDCLIENT_FOUND) - message(WARNING "${ANSI}[41;30mDisabling \"mpd module\" support (prerequisites failed)${ANSI}[0m") + message(WARNING "${ANSI}[41;1mDisabling \"mpd module\" support (prerequisites failed)${ANSI}[0m") set(ENABLE_MPD OFF) endif() endif() @@ -131,7 +131,7 @@ if(ENABLE_NETWORK) set(PROJECT_INCL_DIRS ${PROJECT_INCL_DIRS} ${LIBIW_INCLUDE_DIR}) set(PROJECT_LINK_LIBS ${PROJECT_LINK_LIBS} ${LIBIW_LIBRARY}) else(LIBIW_FOUND) - message(WARNING "${ANSI}[41;30mDisabling \"network module\" support (prerequisites failed)${ANSI}[0m") + message(WARNING "${ANSI}[41;1mDisabling \"network module\" support (prerequisites failed)${ANSI}[0m") set(ENABLE_NETWORK OFF) endif() endif() diff --git a/include/bar.hpp b/include/bar.hpp index 72b667c6..96f92608 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -1,5 +1,4 @@ -#ifndef _BAR_HPP_ -#define _BAR_HPP_ +#pragma once #include #include @@ -12,7 +11,7 @@ DefineBaseException(ConfigurationError); struct CompiledWithoutModuleSupport : public ConfigurationError { - CompiledWithoutModuleSupport(std::string module_name) + explicit CompiledWithoutModuleSupport(std::string module_name) : ConfigurationError(std::string(APP_NAME) + " was not compiled with support for module \""+ module_name +"\"") {} }; @@ -96,5 +95,3 @@ class Bar std::shared_ptr &get_bar(); const Options& bar_opts(); - -#endif diff --git a/include/config.hpp.cmake b/include/config.hpp.cmake index ffdc9caa..412c6064 100644 --- a/include/config.hpp.cmake +++ b/include/config.hpp.cmake @@ -1,5 +1,4 @@ -#ifndef _CONFIG_HPP_ -#define _CONFIG_HPP_ +#pragma once #define APP_NAME "@PROJECT_NAME@" @@ -22,5 +21,3 @@ #define BSPWM_STATUS_PREFIX "@SETTING_BSPWM_STATUS_PREFIX@" #define PATH_CPU_INFO "@SETTING_PATH_CPU_INFO@" #define PATH_MEMORY_INFO "@SETTING_PATH_MEMORY_INFO@" - -#endif // _CONFIG_HPP_ diff --git a/include/drawtypes/animation.hpp b/include/drawtypes/animation.hpp index 9346cc6f..1ddffff2 100644 --- a/include/drawtypes/animation.hpp +++ b/include/drawtypes/animation.hpp @@ -1,5 +1,4 @@ -#ifndef _DRAWTYPES_ANIMATION_HPP_ -#define _DRAWTYPES_ANIMATION_HPP_ +#pragma once #include #include @@ -21,7 +20,7 @@ namespace drawtypes public: Animation(std::vector> &&frames, int framerate_ms = 1); - Animation(int framerate_ms) + explicit Animation(int framerate_ms) : framerate_ms(framerate_ms){} void add(std::unique_ptr &&frame); @@ -37,5 +36,3 @@ namespace drawtypes std::unique_ptr get_config_animation(const std::string& config_path, const std::string& animation_name = "animation", bool required = true); } - -#endif diff --git a/include/drawtypes/bar.hpp b/include/drawtypes/bar.hpp index d39ccd34..1a9379aa 100644 --- a/include/drawtypes/bar.hpp +++ b/include/drawtypes/bar.hpp @@ -1,5 +1,4 @@ -#ifndef _DRAWTYPES_BAR_HPP_ -#define _DRAWTYPES_BAR_HPP_ +#pragma once #include #include @@ -16,7 +15,7 @@ namespace drawtypes protected: std::unique_ptr builder; std::vector colors; - bool gradient; + bool gradient = false; unsigned int width; std::string format; @@ -25,7 +24,7 @@ namespace drawtypes std::unique_ptr indicator; public: - Bar(int width, const std::string& format, bool lazy_builder_closing = true); + Bar(int width, const std::string& fmt, bool lazy_builder_closing = true); Bar(int width, bool lazy_builder_closing = true) : Bar(width, "", lazy_builder_closing){} @@ -41,5 +40,3 @@ namespace drawtypes std::unique_ptr get_config_bar(const std::string& config_path, const std::string& bar_name = "bar", bool lazy_builder_closing = true); } - -#endif diff --git a/include/drawtypes/icon.hpp b/include/drawtypes/icon.hpp index 8cd8a287..85304cbc 100644 --- a/include/drawtypes/icon.hpp +++ b/include/drawtypes/icon.hpp @@ -1,5 +1,4 @@ -#ifndef _DRAWTYPES_ICON_HPP_ -#define _DRAWTYPES_ICON_HPP_ +#pragma once #include #include @@ -37,5 +36,3 @@ namespace drawtypes std::unique_ptr get_config_icon(const std::string& module_name, const std::string& icon_name = "icon", bool required = true, const std::string& def = ""); std::unique_ptr get_optional_config_icon(const std::string& module_name, const std::string& icon_name = "icon", const std::string& def = ""); } - -#endif diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index 129b3d31..52cd8b7c 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -1,5 +1,4 @@ -#ifndef _DRAWTYPES_LABEL_HPP_ -#define _DRAWTYPES_LABEL_HPP_ +#pragma once #include #include @@ -29,5 +28,3 @@ namespace drawtypes std::unique_ptr