Mercurial > irccd
changeset 717:fff3ee62d0fc
Common: use more C++17
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 09 Jul 2018 21:02:00 +0200 |
parents | 16e83b636cb8 |
children | d615af5e505b |
files | libirccd-core/irccd/config.cpp libirccd-core/irccd/config.hpp libirccd-core/irccd/system.cpp libirccd-core/irccd/system.hpp |
diffstat | 4 files changed, 27 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libirccd-core/irccd/config.cpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/config.cpp Mon Jul 09 21:02:00 2018 +0200 @@ -18,13 +18,12 @@ #include <boost/filesystem.hpp> -#include <irccd/system.hpp> - #include "config.hpp" +#include "system.hpp" namespace irccd { -boost::optional<config> config::search(const std::string& name) +auto config::search(std::string_view name) -> std::optional<config> { for (const auto& path : sys::config_filenames(name)) { boost::system::error_code ec; @@ -33,7 +32,18 @@ return config(path); } - return boost::optional<config>(); + return std::nullopt; +} + +config::config(std::string path) + : document(path.empty() ? ini::document() : ini::read_file(path)) + , path_(std::move(path)) +{ +} + +auto config::get_path() const noexcept -> const std::string& +{ + return path_; } } // !irccd
--- a/libirccd-core/irccd/config.hpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/config.hpp Mon Jul 09 21:02:00 2018 +0200 @@ -24,7 +24,8 @@ * \brief Read .ini configuration file for irccd */ -#include <boost/optional.hpp> +#include <optional> +#include <string_view> #include "ini.hpp" @@ -44,28 +45,21 @@ * \param name the file name * \return the config or empty if not found */ - static boost::optional<config> search(const std::string& name); + static auto search(std::string_view name) -> std::optional<config>; /** * Load the configuration from the specified path. * * \param path the path */ - inline config(std::string path = "") - : document(path.empty() ? ini::document() : ini::read_file(path)) - , path_(std::move(path)) - { - } + config(std::string path = ""); /** * Get the path to the configuration file. * * \return the path */ - inline const std::string& get_path() const noexcept - { - return path_; - } + auto get_path() const noexcept -> const std::string&; }; } // !irccd
--- a/libirccd-core/irccd/system.cpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/system.cpp Mon Jul 09 21:02:00 2018 +0200 @@ -468,11 +468,14 @@ // {{{ config_filenames -std::vector<std::string> config_filenames(std::string file) +std::vector<std::string> config_filenames(std::string_view file) { + // TODO: remove this once we can use std::filesystem. + const std::string filename(file); + return { - (user_config_directory() / file).string(), - (sysconfdir() / file).string() + (user_config_directory() / filename).string(), + (sysconfdir() / filename).string() }; }
--- a/libirccd-core/irccd/system.hpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/system.hpp Mon Jul 09 21:02:00 2018 +0200 @@ -26,6 +26,7 @@ #include <cstdint> #include <string> +#include <string_view> #include <vector> #include <boost/filesystem.hpp> @@ -148,7 +149,7 @@ * \param file the filename to append for convenience * \return the list of paths to check in order */ -std::vector<std::string> config_filenames(std::string file); +std::vector<std::string> config_filenames(std::string_view file); /** * Construct a list of paths for reading plugins.