From 0d1db206c656119443f5e1ce3890423b24e308f0 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Tue, 21 Sep 2021 21:15:49 +0200 Subject: [PATCH] Remove factory_util unique and shared Equivalent to std::make_unique and std::make_shared --- include/utils/command.hpp | 4 ++-- include/utils/factory.hpp | 23 ++--------------------- include/utils/file.hpp | 2 +- include/utils/http.hpp | 2 +- include/utils/inotify.hpp | 5 +++-- include/utils/scope.hpp | 5 ++--- include/utils/socket.hpp | 4 ++-- src/components/bar.cpp | 2 +- src/components/command_line.cpp | 7 ++++--- src/components/controller.cpp | 2 +- src/components/ipc.cpp | 2 +- src/components/renderer.cpp | 2 +- src/components/screen.cpp | 2 +- src/components/taskqueue.cpp | 5 +++-- src/drawtypes/animation.cpp | 3 ++- src/drawtypes/label.cpp | 4 ++-- src/drawtypes/progressbar.cpp | 4 ++-- src/drawtypes/ramp.cpp | 5 +++-- src/modules/bspwm.cpp | 8 ++++---- src/modules/i3.cpp | 10 +++++----- src/modules/menu.cpp | 4 ++-- src/modules/mpd.cpp | 12 ++++++------ src/modules/network.cpp | 4 ++-- src/modules/pulseaudio.cpp | 2 +- src/modules/xkeyboard.cpp | 22 +++++++++++----------- src/modules/xworkspaces.cpp | 9 ++++----- src/tags/dispatch.cpp | 2 +- src/utils/factory.cpp | 1 - src/utils/inotify.cpp | 5 +++-- src/x11/tray_manager.cpp | 9 ++++----- tests/unit_tests/drawtypes/ramp.cpp | 11 ++++++----- 31 files changed, 83 insertions(+), 99 deletions(-) diff --git a/include/utils/command.hpp b/include/utils/command.hpp index bc3f8537..b2c668a2 100644 --- a/include/utils/command.hpp +++ b/include/utils/command.hpp @@ -77,7 +77,7 @@ class command { string m_cmd; pid_t m_forkpid{}; - int m_forkstatus = - 1; + int m_forkstatus = -1; }; template <> @@ -114,7 +114,7 @@ class command : private command unique_ptr> make_command(Args&&... args) { - return factory_util::unique>(logger::make(), forward(args)...); + return std::make_unique>(logger::make(), forward(args)...); } } // namespace command_util diff --git a/include/utils/factory.hpp b/include/utils/factory.hpp index 6e0bbacc..f9253a63 100644 --- a/include/utils/factory.hpp +++ b/include/utils/factory.hpp @@ -12,34 +12,15 @@ namespace factory_util { template void operator()(T*) const {} }; - - struct fd_deleter { - void operator()(int* fd) const { - if (fd != nullptr && *fd > 0) { - close(*fd); - } - } - }; - } + } // namespace detail extern detail::null_deleter null_deleter; - extern detail::fd_deleter fd_deleter; - - template - unique_ptr unique(Deps&&... deps) { - return make_unique(forward(deps)...); - } - - template - shared_ptr shared(Deps&&... deps) { - return make_shared(forward(deps)...); - } template shared_ptr singleton(Deps&&... deps) { static shared_ptr instance{make_shared(forward(deps)...)}; return instance; } -} +} // namespace factory_util POLYBAR_NS_END diff --git a/include/utils/file.hpp b/include/utils/file.hpp index ebbf1921..a6ebeacc 100644 --- a/include/utils/file.hpp +++ b/include/utils/file.hpp @@ -114,7 +114,7 @@ namespace file_util { template decltype(auto) make_file_descriptor(Args&&... args) { - return factory_util::unique(forward(args)...); + return std::make_unique(forward(args)...); } } // namespace file_util diff --git a/include/utils/http.hpp b/include/utils/http.hpp index e6f15c7f..15581b1b 100644 --- a/include/utils/http.hpp +++ b/include/utils/http.hpp @@ -23,7 +23,7 @@ class http_downloader { namespace http_util { template decltype(auto) make_downloader(Args&&... args) { - return factory_util::unique(forward(args)...); + return std::make_unique(forward(args)...); } } // namespace http_util diff --git a/include/utils/inotify.hpp b/include/utils/inotify.hpp index 207d7b02..576c7880 100644 --- a/include/utils/inotify.hpp +++ b/include/utils/inotify.hpp @@ -2,6 +2,7 @@ #include #include + #include #include "common.hpp" @@ -40,8 +41,8 @@ class inotify_watch { namespace inotify_util { template decltype(auto) make_watch(Args&&... args) { - return factory_util::unique(forward(args)...); + return std::make_unique(forward(args)...); } -} +} // namespace inotify_util POLYBAR_NS_END diff --git a/include/utils/scope.hpp b/include/utils/scope.hpp index 1d0a0eba..32a200fc 100644 --- a/include/utils/scope.hpp +++ b/include/utils/scope.hpp @@ -3,7 +3,6 @@ // TODO: move to functional.hpp #include "common.hpp" - #include "components/logger.hpp" #include "utils/factory.hpp" @@ -37,8 +36,8 @@ namespace scope_util { */ template , typename... Args> decltype(auto) make_exit_handler(Fn&& fn, Args&&... args) { - return factory_util::unique>(forward(fn), forward(args)...); + return std::make_unique>(forward(fn), forward(args)...); } -} +} // namespace scope_util POLYBAR_NS_END diff --git a/include/utils/socket.hpp b/include/utils/socket.hpp index 96f36a4f..938d55ea 100644 --- a/include/utils/socket.hpp +++ b/include/utils/socket.hpp @@ -41,8 +41,8 @@ namespace socket_util { * \endcode */ inline unique_ptr make_unix_connection(string&& path) { - return factory_util::unique(forward(path)); + return std::make_unique(forward(path)); } -} +} // namespace socket_util POLYBAR_NS_END diff --git a/src/components/bar.cpp b/src/components/bar.cpp index a33a9736..4244fb69 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -42,7 +42,7 @@ bar::make_type bar::make(bool only_initialize_values) { auto action_ctxt = make_unique(); // clang-format off - return factory_util::unique( + return std::make_unique( connection::make(), signal_emitter::make(), config::make(), diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index 35759a0f..296e39ce 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -1,6 +1,7 @@ +#include "components/command_line.hpp" + #include -#include "components/command_line.hpp" #include "utils/factory.hpp" POLYBAR_NS @@ -10,7 +11,7 @@ namespace command_line { * Create instance */ parser::make_type parser::make(string&& scriptname, const options&& opts) { - return factory_util::unique("Usage: " + scriptname + " [OPTION]... BAR", forward(opts)); + return std::make_unique("Usage: " + scriptname + " [OPTION]... BAR", forward(opts)); } /** @@ -199,6 +200,6 @@ namespace command_line { throw argument_error("Unrecognized option " + input); } } -} +} // namespace command_line POLYBAR_NS_END diff --git a/src/components/controller.cpp b/src/components/controller.cpp index e9f4835b..26c16dd8 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -32,7 +32,7 @@ POLYBAR_NS * Build controller instance */ controller::make_type controller::make(unique_ptr&& ipc) { - return factory_util::unique(connection::make(), signal_emitter::make(), logger::make(), config::make(), + return std::make_unique(connection::make(), signal_emitter::make(), logger::make(), config::make(), bar::make(), forward(ipc)); } diff --git a/src/components/ipc.cpp b/src/components/ipc.cpp index da2a948d..fbba93bd 100644 --- a/src/components/ipc.cpp +++ b/src/components/ipc.cpp @@ -24,7 +24,7 @@ static constexpr const char* ipc_action_prefix{"action:"}; * Create instance */ ipc::make_type ipc::make() { - return factory_util::unique(signal_emitter::make(), logger::make()); + return std::make_unique(signal_emitter::make(), logger::make()); } /** diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 34daad5a..4dd1e168 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -23,7 +23,7 @@ static constexpr double BLOCK_GAP{20.0}; */ renderer::make_type renderer::make(const bar_settings& bar, tags::action_context& action_ctxt) { // clang-format off - return factory_util::unique( + return std::make_unique( connection::make(), signal_emitter::make(), config::make(), diff --git a/src/components/screen.cpp b/src/components/screen.cpp index 1e1076b7..a349f9f5 100644 --- a/src/components/screen.cpp +++ b/src/components/screen.cpp @@ -23,7 +23,7 @@ using namespace signals::eventqueue; * Create instance */ screen::make_type screen::make() { - return factory_util::unique(connection::make(), signal_emitter::make(), logger::make(), config::make()); + return std::make_unique(connection::make(), signal_emitter::make(), logger::make(), config::make()); } /** diff --git a/src/components/taskqueue.cpp b/src/components/taskqueue.cpp index b8418797..736c9b1c 100644 --- a/src/components/taskqueue.cpp +++ b/src/components/taskqueue.cpp @@ -1,12 +1,13 @@ +#include "components/taskqueue.hpp" + #include -#include "components/taskqueue.hpp" #include "utils/factory.hpp" POLYBAR_NS taskqueue::make_type taskqueue::make() { - return factory_util::unique(); + return std::make_unique(); } taskqueue::taskqueue() { diff --git a/src/drawtypes/animation.cpp b/src/drawtypes/animation.cpp index a65fafb3..d8e32b76 100644 --- a/src/drawtypes/animation.cpp +++ b/src/drawtypes/animation.cpp @@ -1,4 +1,5 @@ #include "drawtypes/animation.hpp" + #include "drawtypes/label.hpp" #include "utils/factory.hpp" @@ -56,7 +57,7 @@ namespace drawtypes { auto framerate = conf.get(section, name + "-framerate", 1000); - return factory_util::shared(move(vec), framerate); + return std::make_shared(move(vec), framerate); } } // namespace drawtypes diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index 6a99e208..078c90cf 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -56,7 +56,7 @@ namespace drawtypes { std::back_insert_iterator back_it(tokens); std::copy(m_tokens.begin(), m_tokens.end(), back_it); } - return factory_util::shared