From 3eee1f76b90124267b2e4129bc866e7164ed156f Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Tue, 5 Nov 2019 19:43:01 +0100 Subject: [PATCH] inline nana::filesystem --- include/nana/filesystem/filesystem.hpp | 109 ++++++++++----------- include/nana/filesystem/filesystem_ext.hpp | 18 +--- source/filesystem/filesystem.cpp | 18 ++-- 3 files changed, 66 insertions(+), 79 deletions(-) diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 872bcb50..4a080b77 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -38,6 +38,8 @@ #define NANA_USING_STD_FILESYSTEM 0 #define NANA_USING_BOOST_FILESYSTEM 0 +#define NANA_FILESYSTEM_FORCE 1 + #if (defined(NANA_FILESYSTEM_FORCE) || ( (defined(STD_FILESYSTEM_NOT_SUPPORTED) && !defined(BOOST_FILESYSTEM_AVAILABLE)) && !(defined(BOOST_FILESYSTEM_FORCE) || defined(STD_FILESYSTEM_FORCE)) ) ) #undef NANA_USING_NANA_FILESYSTEM @@ -132,12 +134,8 @@ namespace std { #include -namespace nana { namespace experimental { namespace filesystem -{ -#ifndef CXX_NO_INLINE_NAMESPACE - inline namespace v1 - { -#endif +namespace nana { + namespace filesystem { enum class file_type { @@ -264,17 +262,21 @@ namespace nana { namespace experimental { namespace filesystem const string_type& native() const; operator string_type() const; - std::string string() const; - std::wstring wstring() const; - std::string u8string() const; - // std::u16string u16string() const; - // std::u32string u32string() const; + std::string string() const; - std::string generic_string() const ; - std::wstring generic_wstring() const; - std::string generic_u8string() const; - // std::u16string generic_u16string() const; - // std::u32string generic_u32string() const; + std::wstring wstring() const; + + // std::string u8string() const; + // std::u16string u16string() const; + // std::u32string u32string() const; + + std::string generic_string() const; + + std::wstring generic_wstring() const; + + // std::string generic_u8string() const; + // std::u16string generic_u16string() const; + // std::u32string generic_u32string() const; path lexically_normal() const; @@ -424,16 +426,17 @@ namespace nana { namespace experimental { namespace filesystem bool is_directory(const path& p); bool is_directory(const path& p, std::error_code& ec) noexcept; - inline bool is_regular_file(file_status s) noexcept - { - return s.type() == file_type::regular; - } - inline bool is_regular_file(const path& p) - { - return is_regular_file(status(p)); - } - // bool is_regular_file(const path& p, error_code& ec) noexcept; - // Returns: is_regular_file(status(p, ec)).Returns false if an error occurs. + inline bool is_regular_file(file_status s) noexcept + { + return s.type() == file_type::regular; + } + + inline bool is_regular_file(const path &p) + { + return is_regular_file(status(p)); + } + // bool is_regular_file(const path& p, error_code& ec) noexcept; // todo: + // Returns: is_regular_file(status(p, ec)).Returns false if an error occurs. // todo: inline bool is_empty(const path& p) { @@ -497,38 +500,34 @@ namespace nana { namespace experimental { namespace filesystem } } - return index ? path.substr(0, index + 1) : std::basic_string(); - } -#ifndef CXX_NO_INLINE_NAMESPACE -} //end namespace v1 -#endif -} //end namespace filesystem -} //end namespace experimental + return index ? path.substr(0, index + 1) : std::basic_string(); + } - //namespace filesystem = experimental::filesystem; + path absolute(const path& p); + path absolute(const path& p, std::error_code& err); + + path canonical(const path& p); + path canonical(const path& p, std::error_code& err); + + path weakly_canonical(const path& p); + path weakly_canonical(const path& p, std::error_code& err); + + bool exists( file_status s ) noexcept; + bool exists( const path& p ); + bool exists( const path& p, std::error_code& ec ) noexcept; + } //end namespace filesystem } //end namespace nana - -namespace std { - namespace experimental { - namespace filesystem { - -# ifdef CXX_NO_INLINE_NAMESPACE - using namespace nana::experimental::filesystem; -# else - using namespace nana::experimental::filesystem::v1; -# endif - - } // filesystem - } // experimental - - namespace filesystem { - using namespace std::experimental::filesystem; - -#if defined(NANA_FILESYSTEM_FORCE) || \ - (defined(_MSC_VER) && ((!defined(_MSVC_LANG)) || (_MSVC_LANG < 201703))) - path absolute(const path& p); - path absolute(const path& p, std::error_code& err); +namespace std +{ + namespace filesystem + { + inline namespace nana_filesystem + { + using namespace ::nana::filesystem; + } + } +} path canonical(const path& p); path canonical(const path& p, std::error_code& err); diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp index 7bc69f0c..b31ff0e2 100644 --- a/include/nana/filesystem/filesystem_ext.hpp +++ b/include/nana/filesystem/filesystem_ext.hpp @@ -1,13 +1,13 @@ /** * Nana C++ Library(http://www.nanapro.org) -* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) +* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file nana\filesystem\filesystem_ext.hpp -* @autor by Ariel Vina-Rodriguez: +* @autor Ariel Vina-Rodriguez: * @brief Some convenient extensions to the filesystem library. * */ @@ -35,16 +35,6 @@ namespace filesystem_ext std::filesystem::path path_user(); ///< extention ? - /// workaround Boost not having path.generic_u8string() - a good point for http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0251r0.pdf -inline std::string generic_u8string(const std::filesystem::path& p) -{ -#if NANA_USING_BOOST_FILESYSTEM - return nana::to_utf8(p.generic_wstring()); -#else - return p.generic_u8string(); -#endif -} - inline bool is_directory(const std::filesystem::directory_entry& dir) noexcept { return is_directory(dir.status()); @@ -57,10 +47,10 @@ class directory_only_iterator : public std::filesystem::directory_iterator directory_only_iterator& find_first() { - auto end = directory_only_iterator{}; + directory_only_iterator end{}; while (*this != end) { - if (is_directory((**this).status())) + if (is_directory((*(*this)).status())) return *this; this->directory_iterator::operator++(); } diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index bcd5957c..2ef50604 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -1,4 +1,4 @@ -/* +/** * A ISO C++ FileSystem Implementation * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * @@ -14,6 +14,7 @@ #include #include #include +#include #include #ifdef _nana_std_put_time @@ -150,14 +151,11 @@ namespace nana #if NANA_USING_NANA_FILESYSTEM -namespace nana_fs = nana::experimental::filesystem; - -namespace nana { namespace experimental { namespace filesystem - { -#ifndef CXX_NO_INLINE_NAMESPACE - inline namespace v1 { -#endif - +namespace nana_fs = nana::filesystem; +namespace nana +{ +namespace filesystem +{ //class filesystem_error filesystem_error::filesystem_error(const std::string& msg, std::error_code err) : std::system_error(err, msg) @@ -667,7 +665,7 @@ namespace nana { namespace experimental { namespace filesystem } //class directory_entry - directory_entry::directory_entry(const nana_fs::path& p) + directory_entry::directory_entry(const filesystem::path& p) :path_{ p } {}