Merge branch 'filesystem' of https://github.com/qPCR4vir/nana into qPCR4vir-filesystem
This commit is contained in:
commit
3e8858d782
@ -55,7 +55,7 @@ matrix:
|
|||||||
- llvm-toolchain-precise
|
- llvm-toolchain-precise
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- git clone --depth=50 --branch=master https://github.com/qPCR4vir/nana-demo.git nana-demo
|
- git clone --depth=50 --branch=dev_dir_it https://github.com/qPCR4vir/nana-demo.git nana-demo
|
||||||
- export PATH="$HOME/bin:$PATH"
|
- export PATH="$HOME/bin:$PATH"
|
||||||
- mkdir ~/bin
|
- mkdir ~/bin
|
||||||
- wget --no-check-certificate --no-clobber -O /tmp/tools/cmake https://cmake.org/files/v3.4/cmake-3.4.0-rc3-Linux-x86_64.sh || true
|
- wget --no-check-certificate --no-clobber -O /tmp/tools/cmake https://cmake.org/files/v3.4/cmake-3.4.0-rc3-Linux-x86_64.sh || true
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/*
|
/**
|
||||||
* A ISO C++ filesystem Implementation
|
* A ISO C++ filesystem Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
|
||||||
@ -7,17 +7,17 @@
|
|||||||
* (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.hpp
|
* @file nana/filesystem/filesystem.hpp
|
||||||
* Modiffied by Ariel Vina-Rodriguez:
|
* @author Jinhao, conributed: Ariel Vina-Rodriguez
|
||||||
* Now mimic std::experimental::filesystem::v1 (boost v3)
|
* @brief Mimic std::experimental::filesystem::v1 (boost v3)
|
||||||
* and need VC2015 or a C++11 compiler. With a few correction will be compiler by VC2013
|
* and need VC2015 or a C++11 compiler. With a few correction can be compiler by VC2013
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf --- last pdf of std draft N4100 <filesystem> 2014-07-04
|
||||||
// http://en.cppreference.com/w/cpp/experimental/fs
|
// http://en.cppreference.com/w/cpp/experimental/fs
|
||||||
// http://cpprocks.com/introduction-to-tr2-filesystem-library-in-vs2012/ --- TR2 filesystem in VS2012
|
// http://cpprocks.com/introduction-to-tr2-filesystem-library-in-vs2012/ --- TR2 filesystem in VS2012
|
||||||
// https://msdn.microsoft.com/en-us/library/hh874694%28v=vs.140%29.aspx --- C++ 14, the <filesystem> header VS2015
|
// https://msdn.microsoft.com/en-us/library/hh874694%28v=vs.140%29.aspx --- C++ 14, the <filesystem> header VS2015
|
||||||
// https://msdn.microsoft.com/en-us/library/hh874694%28v=vs.120%29.aspx --- <filesystem> header VS2013
|
// https://msdn.microsoft.com/en-us/library/hh874694%28v=vs.120%29.aspx --- <filesystem> header VS2013
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf --- last pdf of std draft N4100 2014-07-04
|
|
||||||
// http://cplusplus.github.io/filesystem-ts/working-draft.html --- in html format
|
// http://cplusplus.github.io/filesystem-ts/working-draft.html --- in html format
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4099.html --- in html format
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4099.html --- in html format
|
||||||
// http://article.gmane.org/gmane.comp.lib.boost.devel/256220 --- The filesystem TS unanimously approved by ISO.
|
// http://article.gmane.org/gmane.comp.lib.boost.devel/256220 --- The filesystem TS unanimously approved by ISO.
|
||||||
@ -47,7 +47,7 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class file_type
|
enum class file_type
|
||||||
{
|
{
|
||||||
none = 0, ///< has not been determined or an error occurred while trying to determine
|
none = 0, ///< has not been determined or an error occurred while trying to determine
|
||||||
not_found = -1, ///< Pseudo-type: file was not found. Is not considered an error
|
not_found = -1, ///< Pseudo-type: file was not found. Is not considered an error
|
||||||
@ -78,7 +78,7 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
uintmax_t available;
|
uintmax_t available;
|
||||||
};
|
};
|
||||||
|
|
||||||
using file_time_type = std::chrono::time_point<std::chrono::system_clock>;// trivial-clock> ;
|
using file_time_type = std::chrono::time_point<std::chrono::system_clock>; ///< trivial-clock> ;
|
||||||
|
|
||||||
class file_status
|
class file_status
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
public:
|
public:
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
using value_type = wchar_t;
|
using value_type = wchar_t;
|
||||||
const static value_type preferred_separator = '\\';
|
const static value_type preferred_separator = '\\'; //? L'\\' ?
|
||||||
#else
|
#else
|
||||||
using value_type = char;
|
using value_type = char;
|
||||||
const static value_type preferred_separator = '/';
|
const static value_type preferred_separator = '/';
|
||||||
@ -199,8 +199,9 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
filesystem_error(const std::string& msg, const path& path1, std::error_code err);
|
filesystem_error(const std::string& msg, const path& path1, std::error_code err);
|
||||||
filesystem_error(const std::string& msg, const path& path1, const path& path2, std::error_code err);
|
filesystem_error(const std::string& msg, const path& path1, const path& path2, std::error_code err);
|
||||||
|
|
||||||
const path& path1() const; //noexcept
|
const path& path1() const noexcept;
|
||||||
const path& path2() const; //noexcept
|
const path& path2() const noexcept;
|
||||||
|
// const char* what() const noexcept;
|
||||||
private:
|
private:
|
||||||
path path1_;
|
path path1_;
|
||||||
path path2_;
|
path path2_;
|
||||||
@ -225,33 +226,23 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
filesystem::path path_;
|
filesystem::path path_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// an iterator for a sequence of directory_entry elements representing the files in a directory, not an recursive_directory_iterator
|
/// InputIterator that iterate over the sequence of directory_entry elements representing the files in a directory, not an recursive_directory_iterator
|
||||||
//template<typename FileInfo>
|
|
||||||
class directory_iterator :public std::iterator<std::input_iterator_tag, directory_entry>
|
class directory_iterator :public std::iterator<std::input_iterator_tag, directory_entry>
|
||||||
{
|
{
|
||||||
using find_handle = void*;
|
using find_handle = void*;
|
||||||
public:
|
public:
|
||||||
using value_type = directory_entry ;
|
|
||||||
typedef ptrdiff_t difference_type;
|
|
||||||
typedef const directory_entry* pointer;
|
|
||||||
typedef const directory_entry& reference;
|
|
||||||
typedef std::input_iterator_tag iterator_category;
|
|
||||||
|
|
||||||
directory_iterator();
|
directory_iterator() noexcept;
|
||||||
directory_iterator(const path& file_path);
|
explicit directory_iterator(const path& dir);
|
||||||
|
|
||||||
const value_type& operator*() const;
|
const value_type& operator*() const;
|
||||||
const value_type* operator->() const;
|
const value_type* operator->() const;
|
||||||
|
|
||||||
directory_iterator& operator++();
|
directory_iterator& operator++();
|
||||||
directory_iterator operator++(int);
|
directory_iterator operator++(int); ///< extention
|
||||||
|
|
||||||
bool equal(const directory_iterator& x) const;
|
bool equal(const directory_iterator& x) const;
|
||||||
|
|
||||||
// enable directory_iterator range-based for statements
|
|
||||||
directory_iterator begin();
|
|
||||||
directory_iterator end();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename Char>
|
template<typename Char>
|
||||||
static bool _m_ignore(const Char * p)
|
static bool _m_ignore(const Char * p)
|
||||||
@ -271,6 +262,16 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
find_handle handle_{nullptr};
|
find_handle handle_{nullptr};
|
||||||
value_type value_;
|
value_type value_;
|
||||||
};
|
};
|
||||||
|
/// enable directory_iterator range-based for statements
|
||||||
|
inline directory_iterator begin( directory_iterator iter) noexcept
|
||||||
|
{
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline directory_iterator end( const directory_iterator&) noexcept
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//class recursive_directory_iterator;
|
//class recursive_directory_iterator;
|
||||||
@ -297,15 +298,23 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
std::uintmax_t file_size(const path& p);
|
std::uintmax_t file_size(const path& p);
|
||||||
//uintmax_t file_size(const path& p, error_code& ec) noexcept;
|
//uintmax_t file_size(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
inline bool is_directory(file_status s) { return s.type() == file_type::directory ;}
|
inline bool is_directory(file_status s) noexcept
|
||||||
|
{ return s.type() == file_type::directory ;}
|
||||||
|
|
||||||
bool is_directory(const path& p);
|
bool is_directory(const path& p);
|
||||||
inline bool is_directory(const directory_entry& d)
|
|
||||||
{
|
|
||||||
return is_directory(d.status());
|
|
||||||
}
|
|
||||||
//bool is_directory(const path& p, error_code& ec) noexcept;
|
//bool is_directory(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
//bool is_regular_file(file_status s) 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_empty(const path& p)
|
inline bool is_empty(const path& p)
|
||||||
{
|
{
|
||||||
@ -316,7 +325,7 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
|
|
||||||
return (file_size(p) == 0);
|
return (file_size(p) == 0);
|
||||||
}
|
}
|
||||||
//bool is_empty(const path& p, error_code& ec) noexcept;
|
// bool is_empty(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
|
|
||||||
bool create_directories(const path& p);
|
bool create_directories(const path& p);
|
||||||
@ -328,11 +337,11 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
|
|
||||||
bool modified_file_time(const path& p, struct tm&);
|
bool modified_file_time(const path& p, struct tm&);
|
||||||
|
|
||||||
path path_user();
|
path path_user(); ///< extention ?
|
||||||
|
|
||||||
path current_path();
|
path current_path();
|
||||||
//path current_path(error_code& ec);
|
//path current_path(error_code& ec);
|
||||||
void current_path(const path& p);
|
void current_path(const path& p); ///< chdir
|
||||||
//void current_path(const path& p, error_code& ec) noexcept;
|
//void current_path(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,8 @@
|
|||||||
#ifndef NANA_FILESYSTEM_EXT_HPP
|
#ifndef NANA_FILESYSTEM_EXT_HPP
|
||||||
#define NANA_FILESYSTEM_EXT_HPP
|
#define NANA_FILESYSTEM_EXT_HPP
|
||||||
|
|
||||||
|
#include <nana/filesystem/filesystem_selector.hpp>
|
||||||
|
|
||||||
namespace nana {namespace experimental {namespace filesystem {namespace ext {
|
namespace nana {namespace experimental {namespace filesystem {namespace ext {
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
constexpr auto def_root = "C:";
|
constexpr auto def_root = "C:";
|
||||||
@ -26,19 +28,86 @@ namespace nana {namespace experimental {namespace filesystem {namespace ext {
|
|||||||
constexpr auto def_rootname = "Root/";
|
constexpr auto def_rootname = "Root/";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// nana::experimental::filesystem::path_user()); // REPLACE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! to filesystem_ext.hhp
|
// nana::experimental::filesystem::path_user());
|
||||||
|
|
||||||
template<class DI> // DI = directory_iterator from std, boost, or nana
|
inline bool is_directory(const std::experimental::filesystem::directory_entry& dir) noexcept
|
||||||
class directory_only_iterator : public DI
|
|
||||||
{
|
{
|
||||||
// if (!this->is_directory()) continue;
|
return is_directory(dir.status());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//template<class DI> // 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;
|
||||||
|
directory_only_iterator& find_first()
|
||||||
|
{
|
||||||
|
auto end = directory_only_iterator{};
|
||||||
|
while (*this != end)
|
||||||
|
{
|
||||||
|
if (is_directory((**this).status()))
|
||||||
|
return *this;
|
||||||
|
this->DI::operator++();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
template <class... Arg>
|
||||||
|
directory_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||||
|
{
|
||||||
|
find_first();
|
||||||
|
}
|
||||||
|
directory_only_iterator( ) {}
|
||||||
|
directory_only_iterator& operator++()
|
||||||
|
{
|
||||||
|
this->DI::operator++();
|
||||||
|
return find_first();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
inline directory_only_iterator begin(directory_only_iterator iter) noexcept
|
||||||
|
{
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline directory_only_iterator end(const directory_only_iterator&) noexcept
|
||||||
|
{
|
||||||
|
return{};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//template<class DI> // 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;
|
||||||
|
regular_file_only_iterator& find_first()
|
||||||
|
{
|
||||||
|
while(( (*this) != DI{}) && !is_regular_file((**this).status()))
|
||||||
|
this->DI::operator++();
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
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& operator++()
|
||||||
|
{
|
||||||
|
this->DI::operator++();
|
||||||
|
return find_first();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class DI> // DI = directory_iterator from std, boost, or nana
|
inline regular_file_only_iterator begin(regular_file_only_iterator iter) noexcept
|
||||||
class regular_file_only_iterator : public DI
|
|
||||||
{
|
{
|
||||||
// if (this->is_directory()) continue;
|
return iter;
|
||||||
};
|
}
|
||||||
|
|
||||||
}}}}
|
inline regular_file_only_iterator end(const regular_file_only_iterator&) noexcept
|
||||||
|
{
|
||||||
|
return{};
|
||||||
|
}
|
||||||
|
|
||||||
|
}}}}
|
||||||
#endif //NANA_FILESYSTEM_EXT_HPP
|
#endif //NANA_FILESYSTEM_EXT_HPP
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <nana/config.hpp>
|
#include <nana/config.hpp>
|
||||||
|
|
||||||
#if defined(NANA_BOOST_FILESYSTEM_AVAILABLE) && ( defined(NANA_BOOST_FILESYSTEM_FORCE) || (defined(STD_FILESYSTEM_NOT_SUPPORTED) && defined(NANA_BOOST_FILESYSTEM_PREFERRED) ) )
|
#if (!defined(NANA_FILESYSTEM_FORCE) && defined(NANA_BOOST_FILESYSTEM_AVAILABLE) && ( defined(NANA_BOOST_FILESYSTEM_FORCE) || (defined(STD_FILESYSTEM_NOT_SUPPORTED) && defined(NANA_BOOST_FILESYSTEM_PREFERRED) ) ))
|
||||||
|
|
||||||
# include <boost/filesystem.hpp>
|
# include <boost/filesystem.hpp>
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ namespace std {
|
|||||||
} // std
|
} // std
|
||||||
|
|
||||||
|
|
||||||
#elif defined(STD_FILESYSTEM_NOT_SUPPORTED)
|
#elif (defined(NANA_FILESYSTEM_FORCE) || defined(STD_FILESYSTEM_NOT_SUPPORTED))
|
||||||
|
|
||||||
# include <nana/filesystem/filesystem.hpp>
|
# include <nana/filesystem/filesystem.hpp>
|
||||||
|
|
||||||
|
|||||||
@ -59,12 +59,12 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
path2_(path2)
|
path2_(path2)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const path& filesystem_error::path1() const
|
const path& filesystem_error::path1() const noexcept
|
||||||
{
|
{
|
||||||
return path1_;
|
return path1_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path&filesystem_error::path2() const
|
const path& filesystem_error::path2() const noexcept
|
||||||
{
|
{
|
||||||
return path2_;
|
return path2_;
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
directory_iterator::directory_iterator()
|
directory_iterator::directory_iterator() noexcept
|
||||||
: end_(true),
|
: end_(true),
|
||||||
handle_(nullptr)
|
handle_(nullptr)
|
||||||
{}
|
{}
|
||||||
@ -414,14 +414,10 @@ namespace nana { namespace experimental { namespace filesystem
|
|||||||
bool directory_iterator::equal(const directory_iterator& x) const
|
bool directory_iterator::equal(const directory_iterator& x) const
|
||||||
{
|
{
|
||||||
if (end_ && (end_ == x.end_)) return true;
|
if (end_ && (end_ == x.end_)) return true;
|
||||||
return (value_.path().filename() == x.value_.path().filename());
|
return (value_.path().filename() == x.value_.path().filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// enable directory_iterator range-based for statements
|
|
||||||
directory_iterator directory_iterator::begin() { return *this; }
|
|
||||||
directory_iterator directory_iterator::end() { return{}; }
|
|
||||||
|
|
||||||
void directory_iterator::_m_prepare(const path& file_path)
|
void directory_iterator::_m_prepare(const path& file_path)
|
||||||
{
|
{
|
||||||
path_ = file_path.native();
|
path_ = file_path.native();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user