diff --git a/include/bitcoin/system/boost.hpp b/include/bitcoin/system/boost.hpp index 7b862baea3..88d123deb8 100644 --- a/include/bitcoin/system/boost.hpp +++ b/include/bitcoin/system/boost.hpp @@ -47,8 +47,7 @@ // Include boost in cpp files only from here, so exception disable works. // Avoid use in header includes due to warning repetition (boost/format.hpp). #include -#include -#include +////#include #include #include #include diff --git a/include/bitcoin/system/config/parser.hpp b/include/bitcoin/system/config/parser.hpp index 18036e3421..97f486602b 100644 --- a/include/bitcoin/system/config/parser.hpp +++ b/include/bitcoin/system/config/parser.hpp @@ -19,8 +19,8 @@ #ifndef LIBBITCOIN_SYSTEM_CONFIG_PARSER_HPP #define LIBBITCOIN_SYSTEM_CONFIG_PARSER_HPP +#include #include -#include #include #include @@ -49,7 +49,7 @@ class BC_API parser const std::string& message) noexcept; static bool get_option(variables_map& variables, const std::string& name) noexcept; - static boost::filesystem::path get_config_option(variables_map& variables, + static std::filesystem::path get_config_option(variables_map& variables, const std::string& name) noexcept; virtual ~parser() noexcept; diff --git a/include/bitcoin/system/config/printer.hpp b/include/bitcoin/system/config/printer.hpp index 7954649140..72ba090b55 100644 --- a/include/bitcoin/system/config/printer.hpp +++ b/include/bitcoin/system/config/printer.hpp @@ -67,8 +67,13 @@ class BC_API printer const std::string& application, const std::string& description="", const std::string& command="") noexcept; - /// Destructor. - virtual ~printer() noexcept; + + /// Defaults. + printer(printer&&) = default; + printer(const printer&) = default; + printer& operator=(printer&&) = default; + printer& operator=(const printer&) = default; + virtual ~printer() = default; /// Convert a paragraph of text into a column. /// This formats to 80 char width as: [ 23 | ' ' | 55 | '\n' ]. diff --git a/include/bitcoin/system/unicode/utf8_everywhere/environment.hpp b/include/bitcoin/system/unicode/utf8_everywhere/environment.hpp index 92a49da6da..cf54ddf37c 100644 --- a/include/bitcoin/system/unicode/utf8_everywhere/environment.hpp +++ b/include/bitcoin/system/unicode/utf8_everywhere/environment.hpp @@ -20,9 +20,9 @@ #define LIBBITCOIN_SYSTEM_UNICODE_UTF8_EVERYWHERE_ENVIRONMENT_HPP #include +#include #include #include -#include #include namespace libbitcoin { @@ -58,8 +58,8 @@ BC_API void set_binary_stdout() noexcept(false); // ---------------------------------------------------------------------------- /// Get the default configuration file path with subdirectory. -BC_API boost::filesystem::path default_config_path( - const boost::filesystem::path& subdirectory) noexcept; +BC_API std::filesystem::path default_config_path( + const std::filesystem::path& subdirectory) noexcept; // BC_USE_LIBBITCOIN_MAIN dependencies. // ---------------------------------------------------------------------------- @@ -91,10 +91,10 @@ BC_API int call_utf8_main(int argc, wchar_t* argv[], #ifdef _MSC_VER // Not thread safe. BC_API std::wstring to_extended_path( - const boost::filesystem::path& path) noexcept; + const std::filesystem::path& path) noexcept; #else BC_API std::string to_extended_path( - const boost::filesystem::path& path) noexcept; + const std::filesystem::path& path) noexcept; #endif } // namespace system diff --git a/include/bitcoin/system/unicode/utf8_everywhere/ifstream.hpp b/include/bitcoin/system/unicode/utf8_everywhere/ifstream.hpp index 2c0157319e..7a65a3bdb3 100644 --- a/include/bitcoin/system/unicode/utf8_everywhere/ifstream.hpp +++ b/include/bitcoin/system/unicode/utf8_everywhere/ifstream.hpp @@ -19,8 +19,8 @@ #ifndef LIBBITCOIN_SYSTEM_UNICODE_UTF8_EVERYWHERE_IFSTREAM_HPP #define LIBBITCOIN_SYSTEM_UNICODE_UTF8_EVERYWHERE_IFSTREAM_HPP +#include #include -#include #include namespace libbitcoin { @@ -33,7 +33,7 @@ class BC_API ifstream { public: /// This also opens the file. - ifstream(const boost::filesystem::path& path, + ifstream(const std::filesystem::path& path, std::ifstream::openmode mode=std::ifstream::in) noexcept(false); }; diff --git a/include/bitcoin/system/unicode/utf8_everywhere/ofstream.hpp b/include/bitcoin/system/unicode/utf8_everywhere/ofstream.hpp index 4235530ba1..0295992318 100644 --- a/include/bitcoin/system/unicode/utf8_everywhere/ofstream.hpp +++ b/include/bitcoin/system/unicode/utf8_everywhere/ofstream.hpp @@ -19,8 +19,8 @@ #ifndef LIBBITCOIN_SYSTEM_UNICODE_UTF8_EVERYWHERE_OFSTREAM_HPP #define LIBBITCOIN_SYSTEM_UNICODE_UTF8_EVERYWHERE_OFSTREAM_HPP +#include #include -#include #include namespace libbitcoin { @@ -33,7 +33,7 @@ class BC_API ofstream { public: /// This also opens the file. - ofstream(const boost::filesystem::path& path, + ofstream(const std::filesystem::path& path, std::ofstream::openmode mode=std::ofstream::out) noexcept(false); }; diff --git a/include/bitcoin/system/unicode/utf8_everywhere/utf8_everywhere.hpp b/include/bitcoin/system/unicode/utf8_everywhere/utf8_everywhere.hpp index b4c1424e9b..8357e6848b 100644 --- a/include/bitcoin/system/unicode/utf8_everywhere/utf8_everywhere.hpp +++ b/include/bitcoin/system/unicode/utf8_everywhere/utf8_everywhere.hpp @@ -58,13 +58,15 @@ // const auto utf16 = L"acción.кошка.日本国"; // std::wcout << utf16; -// Regarding Boost: +// Regarding std lib (or boost) paths: // // When working with boost and utf8 narrow characters on Win32 the thread must -// be configured for utf8. Also when working with boost::filesystem::path the -// static path object must be imbued with the utf8 locale or paths will be -// incorrectly translated. These changes are automatically configured by +// be configured for utf8 (std::locale::global). This is configured by // BC_USE_LIBBITCOIN_MAIN. +// When working with boost::filesystem::path the static path object must be +// imbued with the utf8 locale or paths will be incorrectly translated. +// When using std::filesystem::path this is handled by std::locale::global. +// en.cppreference.com/w/cpp/filesystem/path/string // Regarding console applications: // diff --git a/src/config/parser.cpp b/src/config/parser.cpp index 55ea6a3969..385acd094e 100644 --- a/src/config/parser.cpp +++ b/src/config/parser.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -28,7 +29,7 @@ namespace libbitcoin { namespace system { namespace config { -using namespace boost::filesystem; +using namespace std::filesystem; using namespace boost::program_options; using namespace boost::system; diff --git a/src/config/printer.cpp b/src/config/printer.cpp index a4f2a40738..50a9f405a2 100644 --- a/src/config/printer.cpp +++ b/src/config/printer.cpp @@ -18,8 +18,10 @@ */ #include +////#include #include #include +#include #include #include #include @@ -83,13 +85,10 @@ printer::printer(const po::options_description& settings, { } -printer::~printer() noexcept -{ -} - -/* Formatters */ +// Formatters +// ---------------------------------------------------------------------------- -static void enqueue_fragment(std::string& fragment, +static void enqueue_fragment(const std::string& fragment, std::vector& column) noexcept { if (!fragment.empty()) @@ -386,7 +385,7 @@ std::string printer::format_usage_parameters() noexcept return trim_copy(usage.str()); } -/* Initialization */ +// Initialization static void enqueue_name(int count, std::string& name, argument_list& names) noexcept @@ -477,7 +476,8 @@ void printer::initialize() noexcept generate_parameters(); } -/* Printers */ +// Printers +// ---------------------------------------------------------------------------- void printer::commandline(std::ostream& output) noexcept { diff --git a/src/unicode/utf8_everywhere/environment.cpp b/src/unicode/utf8_everywhere/environment.cpp index d49a6393a2..5c66fd7f6e 100644 --- a/src/unicode/utf8_everywhere/environment.cpp +++ b/src/unicode/utf8_everywhere/environment.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -268,8 +269,8 @@ static std::string windows_config_directory() noexcept } #endif -boost::filesystem::path default_config_path( - const boost::filesystem::path& subdirectory) noexcept +std::filesystem::path default_config_path( + const std::filesystem::path& subdirectory) noexcept { static const std::string directory = #ifdef _MSC_VER @@ -278,7 +279,7 @@ boost::filesystem::path default_config_path( SYSCONFDIR; #endif - return boost::filesystem::path{ directory } / subdirectory; + return std::filesystem::path{ directory } / subdirectory; } // BC_USE_LIBBITCOIN_MAIN @@ -353,15 +354,10 @@ char** allocate_environment(wchar_t* environment[]) noexcept int call_utf8_main(int argc, wchar_t* argv[], int(*main)(int argc, char* argv[])) noexcept { - // C++17: use std::filesystem. - // When working with boost and utf8 narrow characters on Win32 the thread - // must be configured for utf8. When working with boost::filesystem::path - // the static path object must be imbued with the utf8 locale or paths will - // be incorrectly translated. + // TODO: verify std::filesystem::path is inbued as it was with boost. constexpr auto utf8_locale_name = "en_US.UTF8"; boost::locale::generator locale; std::locale::global(locale(utf8_locale_name)); - boost::filesystem::path::imbue(std::locale()); auto backup = environ; auto environment = allocate_environment(_wenviron); @@ -388,10 +384,9 @@ int call_utf8_main(int argc, wchar_t* argv[], return result; } -// C++17: use std::filesystem. // docs.microsoft.com/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew std::wstring to_fully_qualified_path( - const boost::filesystem::path& path) noexcept + const std::filesystem::path& path) noexcept { const auto replace_all = [](std::string text, char from, char to) noexcept { @@ -431,7 +426,7 @@ std::wstring to_fully_qualified_path( #endif // _MSC_VER #ifdef _MSC_VER -// C++17: use std::filesystem. +// TODO: update comments for std::filesystem conversion. // Use to_extended_path with APIs that compile to wide with _MSC_VER defined // and to UTF8 with _MSC_VER undefined. This includes some boost APIs - such as // filesystem::remove, remove_all, and create_directories, as well as some @@ -439,7 +434,7 @@ std::wstring to_fully_qualified_path( // Otherwise use in any Win32 (W) APIs with _MSC_VER defined, such as we do in // interprocess_lock::open_file -> CreateFileW, since the boost wrapper only // calls CreateFileA. The length extension prefix requires Win32 (W) APIs. -std::wstring to_extended_path(const boost::filesystem::path& path) noexcept +std::wstring to_extended_path(const std::filesystem::path& path) noexcept { // The length extension prefix works only with a fully-qualified path. // However this includes "considered relative" paths (with ".." segments). @@ -448,7 +443,7 @@ std::wstring to_extended_path(const boost::filesystem::path& path) noexcept return (full.length() > MAX_PATH) ? L"\\\\?\\" + full : full; } #else -std::string to_extended_path(const boost::filesystem::path& path) noexcept +std::string to_extended_path(const std::filesystem::path& path) noexcept { return path.string(); } diff --git a/src/unicode/utf8_everywhere/ifstream.cpp b/src/unicode/utf8_everywhere/ifstream.cpp index 1c6e73c3a3..3d5bd363b5 100644 --- a/src/unicode/utf8_everywhere/ifstream.cpp +++ b/src/unicode/utf8_everywhere/ifstream.cpp @@ -18,16 +18,16 @@ */ #include +#include #include #include #include namespace libbitcoin { namespace system { - -// C++17: use std::filesystem. + // VC++ EXTENSION: "construct with wide-named file". -ifstream::ifstream(const boost::filesystem::path& path, +ifstream::ifstream(const std::filesystem::path& path, std::ifstream::openmode mode) noexcept(false) : std::ifstream(to_extended_path(path), mode) { diff --git a/src/unicode/utf8_everywhere/ofstream.cpp b/src/unicode/utf8_everywhere/ofstream.cpp index a7c9e86fdc..e740bb38c0 100644 --- a/src/unicode/utf8_everywhere/ofstream.cpp +++ b/src/unicode/utf8_everywhere/ofstream.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -25,9 +26,8 @@ namespace libbitcoin { namespace system { -// C++17: use std::filesystem. // VC++ EXTENSION: "construct with wide-named file". -ofstream::ofstream(const boost::filesystem::path& path, +ofstream::ofstream(const std::filesystem::path& path, std::ofstream::openmode mode) noexcept(false) : std::ofstream(to_extended_path(path), mode) { diff --git a/test/config/parameter.cpp b/test/config/parameter.cpp index cc49709c07..fbbdde14e5 100644 --- a/test/config/parameter.cpp +++ b/test/config/parameter.cpp @@ -17,6 +17,7 @@ * along with this program. If not, see . */ #include "../test.hpp" +#include #include #include #include @@ -42,7 +43,7 @@ enum opt static void load_test_options(po::options_description& options) { - using namespace boost::filesystem; + using namespace std::filesystem; using namespace boost::program_options; options.add_options() ("short_long,s", "Long and short name.") diff --git a/test/config/printer.cpp b/test/config/printer.cpp index 0e14dffe51..1f40373ea3 100644 --- a/test/config/printer.cpp +++ b/test/config/printer.cpp @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(printer__format_usage_parameters__unsorted_two_options_one_ BOOST_AUTO_TEST_CASE(printer__format_usage_parameters__unsorted_multiple_parameters__sorted_parameters) { - using namespace boost::filesystem; + using namespace std::filesystem; using namespace boost::program_options; CONFIG_PRINTER_SETUP_ARGUMENTS(options.add_options() ("short_long,s", "Long and short name.") diff --git a/test/test.cpp b/test/test.cpp index 4a3b3c3e56..89db09fe20 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -19,7 +19,7 @@ #include "test.hpp" #include -#include +#include #include namespace std { @@ -41,21 +41,18 @@ namespace test { const std::string directory = "tests"; -// C++17: use std::filesystem. -bool clear(const boost::filesystem::path& file_directory) noexcept +bool clear(const std::filesystem::path& file_directory) noexcept { - // C++17: use std::filesystem. // remove_all returns count removed, and error code if fails. // create_directories returns true if path exists or created. // used for setup, with no expectations of file/directory existence. const auto path = to_extended_path(file_directory); - boost::system::error_code ec; - boost::filesystem::remove_all(path, ec); - return !ec && boost::filesystem::create_directories(path, ec); + code ec; + std::filesystem::remove_all(path, ec); + return !ec && std::filesystem::create_directories(path, ec); } -// C++17: use std::filesystem. -bool create(const boost::filesystem::path& file_path) noexcept +bool create(const std::filesystem::path& file_path) noexcept { // Creates and returns true if file already existed (and no error). BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) @@ -64,8 +61,7 @@ bool create(const boost::filesystem::path& file_path) noexcept BC_POP_WARNING() } -// C++17: use std::filesystem. -bool exists(const boost::filesystem::path& file_path) noexcept +bool exists(const std::filesystem::path& file_path) noexcept { // Returns true only if file existed. BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) @@ -74,13 +70,11 @@ bool exists(const boost::filesystem::path& file_path) noexcept BC_POP_WARNING() } -// C++17: use std::filesystem. -bool remove(const boost::filesystem::path& file_path) noexcept +bool remove(const std::filesystem::path& file_path) noexcept { - // C++17: use std::filesystem. // Deletes and returns false if file did not exist (or error). - boost::system::error_code ec; - return boost::filesystem::remove(to_extended_path(file_path), ec); + code ec; + return std::filesystem::remove(to_extended_path(file_path), ec); } } // namespace test \ No newline at end of file diff --git a/test/test.hpp b/test/test.hpp index a6c2c5496f..bee5b7eca4 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #define TEST_NAME \ @@ -89,10 +90,10 @@ namespace test { // Total path length cannot exceed MAX_PATH in _MSC_VER builds. extern const std::string directory; -bool clear(const boost::filesystem::path& directory) noexcept; -bool create(const boost::filesystem::path& file_path) noexcept; -bool exists(const boost::filesystem::path& file_path) noexcept; -bool remove(const boost::filesystem::path& file_path) noexcept; +bool clear(const std::filesystem::path& directory) noexcept; +bool create(const std::filesystem::path& file_path) noexcept; +bool exists(const std::filesystem::path& file_path) noexcept; +bool remove(const std::filesystem::path& file_path) noexcept; } // namespace test