inline nana::filesystem

This commit is contained in:
qPCR4vir 2019-11-05 19:43:01 +01:00
parent 597f6c05cd
commit 3eee1f76b9
3 changed files with 66 additions and 79 deletions

View File

@ -38,6 +38,8 @@
#define NANA_USING_STD_FILESYSTEM 0 #define NANA_USING_STD_FILESYSTEM 0
#define NANA_USING_BOOST_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)) ) ) #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 #undef NANA_USING_NANA_FILESYSTEM
@ -132,12 +134,8 @@ namespace std {
#include <nana/deploy.hpp> #include <nana/deploy.hpp>
namespace nana { namespace experimental { namespace filesystem namespace nana {
{ namespace filesystem {
#ifndef CXX_NO_INLINE_NAMESPACE
inline namespace v1
{
#endif
enum class file_type enum class file_type
{ {
@ -264,17 +262,21 @@ namespace nana { namespace experimental { namespace filesystem
const string_type& native() const; const string_type& native() const;
operator string_type() const; operator string_type() const;
std::string string() const; std::string string() const;
std::wstring wstring() const;
std::string u8string() const;
// std::u16string u16string() const;
// std::u32string u32string() const;
std::string generic_string() const ; std::wstring wstring() const;
std::wstring generic_wstring() const;
std::string generic_u8string() const; // std::string u8string() const;
// std::u16string generic_u16string() const; // std::u16string u16string() const;
// std::u32string generic_u32string() 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; 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);
bool is_directory(const path& p, std::error_code& ec) noexcept; bool is_directory(const path& p, std::error_code& ec) noexcept;
inline bool is_regular_file(file_status s) noexcept inline bool is_regular_file(file_status s) noexcept
{ {
return s.type() == file_type::regular; return s.type() == file_type::regular;
} }
inline bool is_regular_file(const path& p)
{ inline bool is_regular_file(const path &p)
return is_regular_file(status(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. // 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) 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<CharType>(); return index ? path.substr(0, index + 1) : std::basic_string<CharType>();
} }
#ifndef CXX_NO_INLINE_NAMESPACE
} //end namespace v1
#endif
} //end namespace filesystem
} //end namespace experimental
//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 } //end namespace nana
namespace std
namespace std { {
namespace experimental { namespace filesystem
namespace filesystem { {
inline namespace nana_filesystem
# ifdef CXX_NO_INLINE_NAMESPACE {
using namespace nana::experimental::filesystem; using namespace ::nana::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);
path canonical(const path& p); path canonical(const path& p);
path canonical(const path& p, std::error_code& err); path canonical(const path& p, std::error_code& err);

View File

@ -1,13 +1,13 @@
/** /**
* Nana C++ Library(http://www.nanapro.org) * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
* *
* @file nana\filesystem\filesystem_ext.hpp * @file nana\filesystem\filesystem_ext.hpp
* @autor by Ariel Vina-Rodriguez: * @autor Ariel Vina-Rodriguez:
* @brief Some convenient extensions to the filesystem library. * @brief Some convenient extensions to the filesystem library.
* *
*/ */
@ -35,16 +35,6 @@ namespace filesystem_ext
std::filesystem::path path_user(); ///< extention ? 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 inline bool is_directory(const std::filesystem::directory_entry& dir) noexcept
{ {
return is_directory(dir.status()); return is_directory(dir.status());
@ -57,10 +47,10 @@ class directory_only_iterator : public std::filesystem::directory_iterator
directory_only_iterator& find_first() directory_only_iterator& find_first()
{ {
auto end = directory_only_iterator{}; directory_only_iterator end{};
while (*this != end) while (*this != end)
{ {
if (is_directory((**this).status())) if (is_directory((*(*this)).status()))
return *this; return *this;
this->directory_iterator::operator++(); this->directory_iterator::operator++();
} }

View File

@ -1,4 +1,4 @@
/* /**
* A ISO C++ FileSystem Implementation * A ISO C++ FileSystem Implementation
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
* *
@ -14,6 +14,7 @@
#include <nana/filesystem/filesystem_ext.hpp> #include <nana/filesystem/filesystem_ext.hpp>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <string>
#include <nana/config.hpp> #include <nana/config.hpp>
#ifdef _nana_std_put_time #ifdef _nana_std_put_time
@ -150,14 +151,11 @@ namespace nana
#if NANA_USING_NANA_FILESYSTEM #if NANA_USING_NANA_FILESYSTEM
namespace nana_fs = nana::experimental::filesystem; namespace nana_fs = nana::filesystem;
namespace nana
namespace nana { namespace experimental { namespace filesystem {
{ namespace filesystem
#ifndef CXX_NO_INLINE_NAMESPACE {
inline namespace v1 {
#endif
//class filesystem_error //class filesystem_error
filesystem_error::filesystem_error(const std::string& msg, std::error_code err) filesystem_error::filesystem_error(const std::string& msg, std::error_code err)
: std::system_error(err, msg) : std::system_error(err, msg)
@ -667,7 +665,7 @@ namespace nana { namespace experimental { namespace filesystem
} }
//class directory_entry //class directory_entry
directory_entry::directory_entry(const nana_fs::path& p) directory_entry::directory_entry(const filesystem::path& p)
:path_{ p } :path_{ p }
{} {}