# HG changeset patch # User David Demelier # Date 1531914596 -7200 # Node ID 2496ebc42b078b868c3b8119a0f38ee7010d854a # Parent e08bfc940c54cfe50edcbb1cea7a947ed31967e1 Core: various style changes diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/CMakeLists.txt --- a/libirccd-core/CMakeLists.txt Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/CMakeLists.txt Wed Jul 18 13:49:56 2018 +0200 @@ -45,6 +45,7 @@ set( SOURCES ${libirccd-core_SOURCE_DIR}/irccd/config.cpp + ${libirccd-core_SOURCE_DIR}/irccd/fs_util.cpp ${libirccd-core_SOURCE_DIR}/irccd/ini.cpp ${libirccd-core_SOURCE_DIR}/irccd/options.cpp ${libirccd-core_SOURCE_DIR}/irccd/string_util.cpp diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/fs_util.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libirccd-core/irccd/fs_util.cpp Wed Jul 18 13:49:56 2018 +0200 @@ -0,0 +1,59 @@ +/* + * fs_util.cpp -- filesystem utilities + * + * Copyright (c) 2013-2018 David Demelier + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fs_util.hpp" + +namespace irccd::fs_util { + +// {{{ base_name + +auto base_name(const std::string& path) -> std::string +{ + return boost::filesystem::path(path).filename().string(); +} + +// }}} + +// {{{ dir_name + +auto dir_name(const std::string& path) -> std::string +{ + return boost::filesystem::path(path).parent_path().string(); +} + +// }}} + +// {{{ find + +auto find(const std::string& base, const std::string& name, bool recursive) -> std::string +{ + return find_if(base, recursive, [&] (const auto& entry) { + return entry.path().filename().string() == name; + }); +} + +auto find(const std::string& base, const std::regex& regex, bool recursive) -> std::string +{ + return find_if(base, recursive, [&] (const auto& entry) { + return std::regex_match(entry.path().filename().string(), regex); + }); +} + +// }}} + +} // !irccd::fs_util diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/fs_util.hpp --- a/libirccd-core/irccd/fs_util.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/fs_util.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -44,10 +44,7 @@ * \param path the path * \return the base name */ -inline std::string base_name(const std::string& path) -{ - return boost::filesystem::path(path).filename().string(); -} +auto base_name(const std::string& path) -> std::string; // }}} @@ -61,10 +58,7 @@ * \param path the path * \return the parent directory */ -inline std::string dir_name(const std::string& path) -{ - return boost::filesystem::path(path).parent_path().string(); -} +auto dir_name(const std::string& path) -> std::string; // }}} @@ -87,7 +81,7 @@ * \throw boost::system::system_error on errors */ template -std::string find_if(const std::string& base, bool recursive, Predicate&& predicate) +auto find_if(const std::string& base, bool recursive, Predicate&& predicate) -> std::string { const auto find = [&] (auto it) -> std::string { for (const auto& entry : it) @@ -115,12 +109,7 @@ * \return the full path name to the file or empty string if never found * \throw boost::system::system_error on errors */ -inline std::string find(const std::string& base, const std::string& name, bool recursive = false) -{ - return find_if(base, recursive, [&] (const auto& entry) { - return entry.path().filename().string() == name; - }); -} +auto find(const std::string& base, const std::string& name, bool recursive = false) -> std::string; /** * Overload by regular expression. @@ -131,12 +120,7 @@ * \return the full path name to the file or empty string if never found * \throw boost::system::system_error on errors */ -inline std::string find(const std::string& base, const std::regex& regex, bool recursive = false) -{ - return find_if(base, recursive, [&] (const auto& entry) { - return std::regex_match(entry.path().filename().string(), regex); - }); -} +auto find(const std::string& base, const std::regex& regex, bool recursive = false) -> std::string; // }}} diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/socket_acceptor.hpp --- a/libirccd-core/irccd/socket_acceptor.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/socket_acceptor.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -77,7 +77,7 @@ * \pre acceptor must be ready (is_open() returns true) * \param acceptor the Boost.Asio acceptor */ - inline socket_acceptor(acceptor acceptor) noexcept + socket_acceptor(acceptor acceptor) noexcept : acceptor_(std::move(acceptor)) { assert(acceptor_.is_open()); @@ -88,7 +88,7 @@ * * \return the acceptor */ - inline const acceptor& get_acceptor() const noexcept + auto get_acceptor() const noexcept -> const acceptor& { return acceptor_; } @@ -98,7 +98,7 @@ * * \return the acceptor */ - inline acceptor& get_acceptor() noexcept + auto get_acceptor() noexcept -> acceptor& { return acceptor_; } diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/socket_connector.hpp --- a/libirccd-core/irccd/socket_connector.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/socket_connector.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -75,7 +75,7 @@ * \param service the service * \param endpoint the unique endpoint */ - inline socket_connector(boost::asio::io_service& service, endpoint endpoint) noexcept + socket_connector(boost::asio::io_service& service, endpoint endpoint) noexcept : service_(service) , endpoints_{std::move(endpoint)} { @@ -87,7 +87,7 @@ * \param service the service * \param eps the endpoints */ - inline socket_connector(boost::asio::io_service& service, std::vector eps) noexcept + socket_connector(boost::asio::io_service& service, std::vector eps) noexcept : service_(service) , endpoints_(std::move(eps)) { @@ -98,7 +98,7 @@ * * \return the I/O service */ - inline const boost::asio::io_service& get_io_service() const noexcept + auto get_io_service() const noexcept -> const boost::asio::io_service& { return service_; } @@ -108,7 +108,7 @@ * * \return the I/O service */ - inline boost::asio::io_service& get_io_service() noexcept + auto get_io_service() noexcept -> boost::asio::io_service& { return service_; } diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/socket_stream.hpp --- a/libirccd-core/irccd/socket_stream.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/socket_stream.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -50,7 +50,7 @@ * \param code the error code * \return the std::error_code */ -inline std::error_code convert(boost::system::error_code code) noexcept +inline auto convert(boost::system::error_code code) noexcept -> std::error_code { return std::error_code(code.value(), std::system_category()); } @@ -89,7 +89,7 @@ * \param args the Socket constructor arguments */ template - inline socket_stream(Args&&... args) + socket_stream(Args&&... args) : socket_(std::forward(args)...) { } @@ -99,7 +99,7 @@ * * \return the socket */ - inline const Socket& get_socket() const noexcept + auto get_socket() const noexcept -> const Socket& { return socket_; } @@ -109,7 +109,7 @@ * * \return the socket */ - inline Socket& get_socket() noexcept + auto get_socket() noexcept -> Socket& { return socket_; } diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/system.cpp --- a/libirccd-core/irccd/system.cpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/system.cpp Wed Jul 18 13:49:56 2018 +0200 @@ -75,7 +75,7 @@ * * Otherwise, use the installation prefix. */ -boost::filesystem::path base_directory() +auto base_directory() -> boost::filesystem::path { static const boost::filesystem::path bindir(CMAKE_INSTALL_BINDIR); static const boost::filesystem::path prefix(CMAKE_INSTALL_PREFIX); @@ -117,7 +117,7 @@ * - sysconfigdir, * - plugindir. */ -boost::filesystem::path system_directory(const std::string& component) +auto system_directory(const std::string& component) -> boost::filesystem::path { boost::filesystem::path path(component); @@ -142,7 +142,7 @@ * - Windows: * - */ -boost::filesystem::path user_config_directory() +auto user_config_directory() -> boost::filesystem::path { boost::filesystem::path path; @@ -183,7 +183,7 @@ * * Like add user_config_directory but for plugins. */ -boost::filesystem::path user_plugin_directory() +auto user_plugin_directory() -> boost::filesystem::path { boost::filesystem::path path; @@ -229,7 +229,7 @@ // {{{ name -std::string name() +auto name() -> std::string { #if BOOST_OS_LINUX return "Linux"; @@ -271,7 +271,7 @@ * - Others: * - */ -std::string version() +auto version() -> std::string { #if BOOST_OS_WINDOWS const auto version = GetVersion(); @@ -305,7 +305,7 @@ * - Others: * - */ -std::uint64_t uptime() +auto uptime() -> std::uint64_t { #if BOOST_OS_WINDOWS return ::GetTickCount64() / 1000; @@ -348,7 +348,7 @@ * - Others: * - */ -std::uint64_t ticks() +auto ticks() -> std::uint64_t { #if BOOST_OS_WINDOWS _timeb tp; @@ -374,7 +374,7 @@ * - Windows: * - */ -std::string home() +auto home() -> std::string { #if BOOST_OS_WINDOWS char path[MAX_PATH]; @@ -396,7 +396,7 @@ * Requires: * - */ -std::string env(const std::string& var) +auto env(const std::string& var) -> std::string { const auto value = std::getenv(var.c_str()); @@ -410,7 +410,7 @@ // {{{ cachedir -boost::filesystem::path cachedir() +auto cachedir() -> boost::filesystem::path { return system_directory(CMAKE_INSTALL_LOCALSTATEDIR) / "cache/irccd"; } @@ -419,7 +419,7 @@ // {{{ datadir -boost::filesystem::path datadir() +auto datadir() -> boost::filesystem::path { return system_directory(CMAKE_INSTALL_DATADIR); } @@ -428,7 +428,7 @@ // {{{ sysconfdir -boost::filesystem::path sysconfdir() +auto sysconfdir() -> boost::filesystem::path { return system_directory(CMAKE_INSTALL_SYSCONFDIR) / "irccd"; } @@ -437,7 +437,7 @@ // {{{ plugindir -boost::filesystem::path plugindir() +auto plugindir() -> boost::filesystem::path { return system_directory(CMAKE_INSTALL_LIBDIR) / "irccd"; } @@ -450,7 +450,7 @@ * Requires: * - */ -std::string username() +auto username() -> std::string { #if defined(HAVE_GETLOGIN) auto v = getlogin(); @@ -466,7 +466,7 @@ // {{{ config_filenames -std::vector config_filenames(std::string_view file) +auto config_filenames(std::string_view file) -> std::vector { // TODO: remove this once we can use std::filesystem. const std::string filename(file); @@ -481,8 +481,8 @@ // {{{ plugin_filenames -std::vector plugin_filenames(const std::string& name, - const std::vector& extensions) +auto plugin_filenames(const std::string& name, + const std::vector& extensions) -> std::vector { assert(!extensions.empty()); diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/system.hpp --- a/libirccd-core/irccd/system.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/system.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -50,21 +50,21 @@ * * \return the name */ -std::string name(); +auto name() -> std::string; /** * Get the system version. * * \return the version */ -std::string version(); +auto version() -> std::string; /** * Get the number of seconds elapsed since the boottime. * * \return the number of seconds */ -std::uint64_t uptime(); +auto uptime() -> std::uint64_t; /** * Get the milliseconds elapsed since the application @@ -72,21 +72,21 @@ * * \return the milliseconds */ -std::uint64_t ticks(); +auto ticks() -> std::uint64_t; /** * Get an environment variable. * * \return the value or empty string */ -std::string env(const std::string& var); +auto env(const std::string& var) -> std::string; /** * Get home directory usually /home/foo * * \return the home directory */ -std::string home(); +auto home() -> std::string; /** * Get the cache directory as specified as compile time option @@ -99,7 +99,7 @@ * \see datadir * \see configdir */ -boost::filesystem::path cachedir(); +auto cachedir() -> boost::filesystem::path; /** * Like cachedir but for CMAKE_INSTALL_DATADIR. @@ -108,7 +108,7 @@ * \see cachedir * \see datadir */ -boost::filesystem::path datadir(); +auto datadir() -> boost::filesystem::path; /** * Like cachedir but for CMAKE_INSTALL_SYSCONFDIR. @@ -118,7 +118,7 @@ * \see datadir * \note use config_filenames for irccd.conf, irccdctl.conf files */ - boost::filesystem::path sysconfdir(); +auto sysconfdir() -> boost::filesystem::path; /** * Like cachedir but for CMAKE_INSTALL_LIBDIR. @@ -127,14 +127,14 @@ * \see cachedir * \see datadir */ -boost::filesystem::path plugindir(); +auto plugindir() -> boost::filesystem::path; /** * Get user account login or empty if not available. * * \return the user account name */ -std::string username(); +auto username() -> std::string; /** * Construct a list of paths to read configuration files from. @@ -147,7 +147,7 @@ * \param file the filename to append for convenience * \return the list of paths to check in order */ -std::vector config_filenames(std::string_view file); +auto config_filenames(std::string_view file) -> std::vector; /** * Construct a list of paths for reading plugins. @@ -155,8 +155,8 @@ * \param name the plugin id (without extension) * \param extensions the list of extensions supported */ -std::vector plugin_filenames(const std::string& name, - const std::vector& extensions); +auto plugin_filenames(const std::string& name, + const std::vector& extensions) -> std::vector; } // !irccd::sys diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/tls_acceptor.hpp --- a/libirccd-core/irccd/tls_acceptor.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/tls_acceptor.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -52,7 +52,7 @@ * \param args the socket_acceptor arguments */ template - inline tls_acceptor(boost::asio::ssl::context context, Args&&... args) + tls_acceptor(boost::asio::ssl::context context, Args&&... args) : socket_acceptor(std::forward(args)...) , context_(std::move(context)) { diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/tls_connector.hpp --- a/libirccd-core/irccd/tls_connector.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/tls_connector.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -50,7 +50,7 @@ * \param args the arguments to socket_connector constructor */ template - inline tls_connector(boost::asio::ssl::context context, Args&&... args) + tls_connector(boost::asio::ssl::context context, Args&&... args) : socket_connector(std::forward(args)...) , context_(std::move(context)) { diff -r e08bfc940c54 -r 2496ebc42b07 libirccd-core/irccd/tls_stream.hpp --- a/libirccd-core/irccd/tls_stream.hpp Wed Jul 18 13:09:22 2018 +0200 +++ b/libirccd-core/irccd/tls_stream.hpp Wed Jul 18 13:49:56 2018 +0200 @@ -47,7 +47,7 @@ * \param args the arguments to boost::asio::ssl::stream */ template - inline tls_stream(Args&&... args) + tls_stream(Args&&... args) : socket_stream>(std::forward(args)...) { }