more standard features for filesystem
This commit is contained in:
		
							parent
							
								
									d8a06989f3
								
							
						
					
					
						commit
						9f430f7220
					
				@ -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.
 | 
				
			||||||
@ -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;
 | 
				
			||||||
@ -304,6 +305,17 @@ namespace nana  { namespace experimental { namespace filesystem
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    //bool is_directory(const path& p, error_code& ec) noexcept;
 | 
					    //bool is_directory(const path& p, 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_empty(const path& p)
 | 
						inline bool is_empty(const path& p)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
		auto fs = status(p);
 | 
							auto fs = status(p);
 | 
				
			||||||
@ -313,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);
 | 
				
			||||||
@ -325,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;    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
				{}
 | 
									{}
 | 
				
			||||||
@ -418,10 +418,6 @@ namespace nana {	namespace experimental {	namespace filesystem
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// 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