From 1845b41019cd73ac2c0b1720f75548e235d87e01 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 27 Jun 2016 00:35:04 +0800 Subject: [PATCH] remove filesystem_selector --- include/nana/c++defines.hpp | 2 +- include/nana/config.hpp | 2 +- include/nana/filesystem/filesystem.hpp | 71 +++++++++++++-- include/nana/filesystem/filesystem_ext.hpp | 32 ++++--- .../nana/filesystem/filesystem_selector.hpp | 87 ------------------- source/filesystem/filesystem.cpp | 11 ++- 6 files changed, 91 insertions(+), 114 deletions(-) delete mode 100644 include/nana/filesystem/filesystem_selector.hpp diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index 609f0eeb..8007666b 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -59,7 +59,7 @@ # define constexpr const //no support of constexpr until Visual C++ 2015 ? const ?? # else -# undef STD_FILESYSTEM_NOT_SUPPORTED +# undef STD_FILESYSTEM_NOT_SUPPORTED # endif #elif defined(__GNUC__) # if (__GNUC__ == 4 && __GNUC_MINOR__ < 6) diff --git a/include/nana/config.hpp b/include/nana/config.hpp index 47ab4e4a..17c5cdc2 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -49,7 +49,7 @@ //# The library maybe available in the std library in use or from Boost(almost compatible) //# http://www.boost.org/doc/libs/1_60_0/libs/filesystem/doc/index.htm //# or you can choose to use the(partial, but functional) implementation provided by nana. -//# If you include the file +//# If you include the file //# the selected option will be set by nana into std::experimental::filesystem //# By default Nana will try to use the STD.If not available will try //# to use boost if available.Nana own implementation will be use only none of them are available. diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 1a447abf..836b7778 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -8,7 +8,7 @@ * http://www.boost.org/LICENSE_1_0.txt) * * @file nana/filesystem/filesystem.hpp - * @author Jinhao, conributed: Ariel Vina-Rodriguez + * @author Ariel Vina-Rodriguez, Jinhao * @brief Mimic std::experimental::filesystem::v1 (boost v3) * and need VC2015 or a C++11 compiler. With a few correction can be compiler by VC2013 */ @@ -29,12 +29,54 @@ #ifndef NANA_FILESYSTEM_HPP #define NANA_FILESYSTEM_HPP - -//#undef NANA_USING_NANA_FILESYSTEM -#if NANA_USING_NANA_FILESYSTEM - #include +//Filesystem Selection +#include + +#if defined(NANA_USING_NANA_FILESYSTEM) || defined(NANA_USING_STD_FILESYSTEM) || defined(NANA_USING_BOOST_FILESYSTEM) +#undef NANA_USING_NANA_FILESYSTEM +#undef NANA_USING_STD_FILESYSTEM +#undef NANA_USING_BOOST_FILESYSTEM +#endif + +#define NANA_USING_NANA_FILESYSTEM 0 +#define NANA_USING_STD_FILESYSTEM 0 +#define NANA_USING_BOOST_FILESYSTEM 0 + +#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 +#define NANA_USING_NANA_FILESYSTEM 1 + +#elif (defined(BOOST_FILESYSTEM_AVAILABLE) && ( defined(BOOST_FILESYSTEM_FORCE) || ( defined(STD_FILESYSTEM_NOT_SUPPORTED) && !defined(STD_FILESYSTEM_FORCE) ) )) + +#undef NANA_USING_BOOST_FILESYSTEM +#define NANA_USING_BOOST_FILESYSTEM 1 +# include + +// add boost::filesystem into std::experimental::filesystem +namespace std { + namespace experimental { + namespace filesystem { + using namespace boost::filesystem; + } // filesystem + } // experimental +} // std + +#else + +#undef NANA_USING_STD_FILESYSTEM +#define NANA_USING_STD_FILESYSTEM 1 +# include +#endif + +#ifndef __cpp_lib_experimental_filesystem +# define __cpp_lib_experimental_filesystem 1 +#endif + +#if NANA_USING_NANA_FILESYSTEM + #include #include #include @@ -413,6 +455,21 @@ namespace nana { namespace experimental { namespace filesystem //namespace filesystem = experimental::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 +} // std + +#endif //NANA_USING_NANA_FILESYSTEM + #include -#endif -#endif +#endif //NANA_FILESYSTEM_HPP diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp index 115c3dd1..39fc4a07 100644 --- a/include/nana/filesystem/filesystem_ext.hpp +++ b/include/nana/filesystem/filesystem_ext.hpp @@ -15,10 +15,7 @@ #ifndef NANA_FILESYSTEM_EXT_HPP #define NANA_FILESYSTEM_EXT_HPP -#include -#include - -#include +#include namespace nana { @@ -45,7 +42,8 @@ inline bool is_directory(const std::experimental::filesystem::directory_entry& d //template // DI = directory_iterator from std, boost, or nana : return directory_entry class directory_only_iterator : public std::experimental::filesystem::directory_iterator { - using DI = std::experimental::filesystem::directory_iterator; + using directory_iterator = std::experimental::filesystem::directory_iterator; + directory_only_iterator& find_first() { auto end = directory_only_iterator{}; @@ -53,22 +51,22 @@ class directory_only_iterator : public std::experimental::filesystem::directory_ { if (is_directory((**this).status())) return *this; - this->DI::operator++(); + this->directory_iterator::operator++(); } return *this; } public: - directory_only_iterator(){} + directory_only_iterator() = default; - template - directory_only_iterator(Arg&&... arg ): DI(std::forward(arg)...) + template + directory_only_iterator(Arg&& arg, Args&&... args) : directory_iterator(arg, std::forward(args)...) { find_first(); } directory_only_iterator& operator++() { - this->DI::operator++(); + this->directory_iterator::operator++(); return find_first(); } }; @@ -86,25 +84,25 @@ inline directory_only_iterator end(const directory_only_iterator&) noexcept //template // DI = directory_iterator from std, boost, or nana : value_type directory_entry class regular_file_only_iterator : public std::experimental::filesystem::directory_iterator { - using DI = std::experimental::filesystem::directory_iterator; + using directory_iterator = std::experimental::filesystem::directory_iterator; regular_file_only_iterator& find_first() { - while(( (*this) != DI{}) && !is_regular_file((**this).status())) - this->DI::operator++(); + while (((*this) != directory_iterator{}) && !is_regular_file((**this).status())) + this->directory_iterator::operator++(); return (*this); } public: - regular_file_only_iterator() : DI() {} + regular_file_only_iterator() = default; - template - regular_file_only_iterator(Arg&&... arg ): DI(std::forward(arg)...) + template + regular_file_only_iterator(Arg&& arg, Args&&... args) : directory_iterator(std::forward(arg), std::forward(args)...) { find_first(); } regular_file_only_iterator& operator++() { - this->DI::operator++(); + this->directory_iterator::operator++(); return find_first(); } }; diff --git a/include/nana/filesystem/filesystem_selector.hpp b/include/nana/filesystem/filesystem_selector.hpp deleted file mode 100644 index 0d9c78dd..00000000 --- a/include/nana/filesystem/filesystem_selector.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/** -* Nana C++ Library(http://www.nanapro.org) -* Copyright(C) 2003-2016 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_selector.hpp -* @autor by Ariel Vina-Rodriguez: -* @brief A "ISO C++" filesystem Implementation selector -* -* The ISO C++ File System Technical Specification(ISO - TS, or STD) is optional. -* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf -* This is not a workaround, but an user option. -* The library maybe available in the std library in use or from Boost(almost compatible) -* http://www.boost.org/doc/libs/1_60_0/libs/filesystem/doc/index.htm -* or you can choose to use the(partial, but functional) implementation provided by nana. -* If you include the file -* the selected option will be set by nana into std::experimental::filesystem -* By default Nana will try to use the STD. If not available will try -* to use boost if available. Nana own implementation will be use only if none of them are available. -* nana Now mimic std::experimental::filesystem::v1 (boost v3) -* -*/ - -#ifndef NANA_FILESYSTEM_SELECTOR -#define NANA_FILESYSTEM_SELECTOR - -#include - -#define NANA_USING_NANA_FILESYSTEM false -#define NANA_USING_STD_FILESYSTEM false -#define NANA_USING_BOOST_FILESYSTEM false - -#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 -#define NANA_USING_NANA_FILESYSTEM true -# include - -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 -} // std - -#elif (defined(BOOST_FILESYSTEM_AVAILABLE) && ( defined(BOOST_FILESYSTEM_FORCE) || ( defined(STD_FILESYSTEM_NOT_SUPPORTED) && !defined(STD_FILESYSTEM_FORCE) ) )) - -#undef NANA_USING_BOOST_FILESYSTEM -#define NANA_USING_BOOST_FILESYSTEM true -# include - - // add boost::filesystem into std::experimental::filesystem -namespace std { - namespace experimental { - namespace filesystem { - using namespace boost::filesystem; - } // filesystem - } // experimental -} // std - -#else - -#undef NANA_USING_STD_FILESYSTEM -#define NANA_USING_STD_FILESYSTEM true -# include -#endif - -#ifndef __cpp_lib_experimental_filesystem -# define __cpp_lib_experimental_filesystem 1 -#endif - - -#endif // NANA_FILESYSTEM_SELECTOR - - - - - diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index 8a810f3a..745a52a2 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include //put_time + #if defined(NANA_WINDOWS) #include @@ -102,7 +105,13 @@ namespace nana if (ftime == ((fs::file_time_type::min)())) return{}; - std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); + //std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); + + //A workaround for VC2013 + using time_point = decltype(ftime); + + auto cftime = time_point::clock::to_time_t(ftime); + std::stringstream tm; tm << std::put_time(std::localtime(&cftime), "%Y-%m-%d, %H:%M:%S"); return tm.str();