std.exp.filesystem for vc2013
This commit is contained in:
parent
705fca5232
commit
d04776216b
@ -43,14 +43,19 @@
|
|||||||
|
|
||||||
//C++ language
|
//C++ language
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
|
||||||
# if (_MSC_VER < 1900)
|
# if (_MSC_VER < 1900)
|
||||||
|
# //About std.experimental.filesystem.
|
||||||
|
# //Through VC2013 has provided <filesystem>, but all the names are given in namespace std. It's hard to alias these names into std::experimental,
|
||||||
|
# //So Nana use nana.filesystem implement instead for VC2013
|
||||||
|
#
|
||||||
# //Nana defines some macros for lack of support of keywords
|
# //Nana defines some macros for lack of support of keywords
|
||||||
# define _ALLOW_KEYWORD_MACROS
|
# define _ALLOW_KEYWORD_MACROS
|
||||||
#
|
#
|
||||||
# define CXX_NO_INLINE_NAMESPACE //no support of C++11 inline namespace until Visual C++ 2015
|
# define CXX_NO_INLINE_NAMESPACE //no support of C++11 inline namespace until Visual C++ 2015
|
||||||
# define noexcept //no support of noexcept until Visual C++ 2015
|
# define noexcept //no support of noexcept until Visual C++ 2015
|
||||||
# define constexpr //no support of constexpr until Visual C++ 2015
|
# define constexpr //no support of constexpr until Visual C++ 2015
|
||||||
|
# else
|
||||||
|
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
||||||
# endif
|
# endif
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
||||||
|
@ -42,29 +42,32 @@ class directory_only_iterator : public std::experimental::filesystem::directory_
|
|||||||
{
|
{
|
||||||
using DI = std::experimental::filesystem::directory_iterator;
|
using DI = std::experimental::filesystem::directory_iterator;
|
||||||
directory_only_iterator& find_first()
|
directory_only_iterator& find_first()
|
||||||
{
|
{
|
||||||
auto end = directory_only_iterator{};
|
auto end = directory_only_iterator{};
|
||||||
while (*this != end)
|
while (*this != end)
|
||||||
{
|
{
|
||||||
if (is_directory((**this).status()))
|
if (is_directory((**this).status()))
|
||||||
return *this;
|
return *this;
|
||||||
this->DI::operator++();
|
this->DI::operator++();
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
template <class... Arg>
|
directory_only_iterator(){}
|
||||||
directory_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
|
||||||
{
|
template <class... Arg>
|
||||||
find_first();
|
directory_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||||
}
|
{
|
||||||
directory_only_iterator( ) {}
|
find_first();
|
||||||
|
}
|
||||||
|
|
||||||
directory_only_iterator& operator++()
|
directory_only_iterator& operator++()
|
||||||
{
|
{
|
||||||
this->DI::operator++();
|
this->DI::operator++();
|
||||||
return find_first();
|
return find_first();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline directory_only_iterator begin(directory_only_iterator iter) noexcept
|
inline directory_only_iterator begin(directory_only_iterator iter) noexcept
|
||||||
{
|
{
|
||||||
return iter;
|
return iter;
|
||||||
@ -81,23 +84,25 @@ class regular_file_only_iterator : public std::experimental::filesystem::directo
|
|||||||
{
|
{
|
||||||
using DI = std::experimental::filesystem::directory_iterator;
|
using DI = std::experimental::filesystem::directory_iterator;
|
||||||
regular_file_only_iterator& find_first()
|
regular_file_only_iterator& find_first()
|
||||||
{
|
{
|
||||||
while(( (*this) != DI{}) && !is_regular_file((**this).status()))
|
while(( (*this) != DI{}) && !is_regular_file((**this).status()))
|
||||||
this->DI::operator++();
|
this->DI::operator++();
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
template <class... Arg>
|
|
||||||
regular_file_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
|
||||||
{
|
|
||||||
find_first();
|
|
||||||
}
|
|
||||||
regular_file_only_iterator() : DI() {}
|
regular_file_only_iterator() : DI() {}
|
||||||
regular_file_only_iterator& operator++()
|
|
||||||
{
|
template <class... Arg>
|
||||||
this->DI::operator++();
|
regular_file_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||||
return find_first();
|
{
|
||||||
}
|
find_first();
|
||||||
|
}
|
||||||
|
|
||||||
|
regular_file_only_iterator& operator++()
|
||||||
|
{
|
||||||
|
this->DI::operator++();
|
||||||
|
return find_first();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline regular_file_only_iterator begin(regular_file_only_iterator iter) noexcept
|
inline regular_file_only_iterator begin(regular_file_only_iterator iter) noexcept
|
||||||
@ -113,7 +118,7 @@ inline regular_file_only_iterator end(const regular_file_only_iterator&) noexcep
|
|||||||
inline std::string pretty_file_size(const std::experimental::filesystem::path& path) // todo: move to .cpp
|
inline std::string pretty_file_size(const std::experimental::filesystem::path& path) // todo: move to .cpp
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::size_t bytes = std::experimental::filesystem::file_size ( path );
|
auto bytes = std::experimental::filesystem::file_size ( path );
|
||||||
const char * ustr[] = { " KB", " MB", " GB", " TB" };
|
const char * ustr[] = { " KB", " MB", " GB", " TB" };
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
if (bytes < 1024)
|
if (bytes < 1024)
|
||||||
|
@ -61,7 +61,7 @@ namespace std {
|
|||||||
} // std
|
} // std
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# include <experimental/filesystem>
|
# include <experimental/filesystem>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __cpp_lib_experimental_filesystem
|
#ifndef __cpp_lib_experimental_filesystem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user