24#include "AstUtil/StringView.hpp"
28#include <system_error>
40#define _AST_FS _AST fs_simple::
50 using string_type = std::string;
51 using char_type = char;
57 using std::system_error::system_error;
59 const std::string& what,
60 std::error_code ec=std::make_error_code(std::errc::operation_not_supported)
61 ): std::system_error(ec, what)
71 path(
const char_type* source) : path_(source)
73 path(
const string_type& source) : path_(source)
78 std::string string()
const{
return path_;}
81 const string_type& native()
const{
return path_;}
84 const char_type* c_str()
const{
return path_.c_str();}
87 static bool is_separator(char_type c)
90 return c ==
'/' || c ==
'\\';
96 static const char_type* separators()
105 static char_type preferred_separator()
115 path filename()
const
117 auto pos = path_.find_last_of(separators());
118 if (pos == string_type::npos)
return path_;
119 return path_.substr(pos + 1);
122 path extension()
const
124 auto name = filename().native();
125 auto pos = name.find_last_of(char_type(
'.'));
126 if (pos == string_type::npos)
return string_type();
127 return name.substr(pos);
134 auto name = filename().native();
135 auto pos = name.find_last_of(char_type(
'.'));
136 if (pos == string_type::npos)
return name;
137 return name.substr(0, pos);
140 path parent_path()
const
142 auto pos = path_.find_last_of(separators());
143 if (pos == string_type::npos)
return string_type();
144 return path_.substr(0, pos);
147 bool is_absolute()
const
149 if (path_.empty())
return false;
153 if (path_.size() >= 2 && is_separator(path_[0]) && is_separator(path_[1]))
157 if (path_.size() >= 3
158 && ((path_[0] >=
'A' && path_[0] <=
'Z') || (path_[0] >=
'a' && path_[0] <=
'z'))
160 && is_separator(path_[2]))
164 if (is_separator(path_[0]))
170 return is_separator(path_[0]);
174 bool is_relative()
const
176 return !is_absolute();
182 path lexically_relative(
const path& base)
const;
186 return path_.empty();
192 if (path_.empty())
return other;
193 if (other.path_.empty())
return *
this;
196 bool needs_separator = !is_separator(path_.back()) && !is_separator(other.path_.front());
197 if (needs_separator) {
198 return path_ + preferred_separator() + other.path_;
200 return path_ + other.path_;
203 path& operator/=(
const path& other)
205 *
this = *
this / other;
209 operator string_type()
const
237 file_type type()
const
262 _AST_FS
path path_{};
292 return impl_ == other.impl_;
296 return !(*
this == other);
301 std::shared_ptr<impl> impl_;
304 void read_next_entry();
308 AST_UTIL_API
bool exists(
const path& p);
309 AST_UTIL_API
bool exists(
const path& p, std::error_code& ec)
noexcept;
310 AST_UTIL_API uintmax_t file_size(
const path& p);
311 AST_UTIL_API uintmax_t file_size(
const path& p, std::error_code& ec)
noexcept;
312 AST_UTIL_API
bool is_empty(
const path& p);
313 AST_UTIL_API
bool is_empty(
const path& p, std::error_code& ec)
noexcept;
315 AST_UTIL_API
file_status status(
const path& p, std::error_code& ec)
noexcept;
317 A_ALWAYS_INLINE
bool is_regular_file(
file_status s)
noexcept{
return s.type() == file_type::regular; }
318 A_ALWAYS_INLINE
bool is_directory(file_status s)
noexcept{
return s.type() == file_type::directory; }
319 A_ALWAYS_INLINE
bool is_directory(
const path& p)
noexcept{
return is_directory(status(p)); }
320 AST_UTIL_API
bool is_directory(
const path& p, std::error_code& ec)
noexcept;
321 A_ALWAYS_INLINE
bool is_regular_file(
const path& p)
noexcept{
return is_regular_file(status(p)); }
324 AST_UTIL_API
bool create_directory(
const path& p)
noexcept;
325 AST_UTIL_API
bool create_directory(
const path& p, std::error_code& ec)
noexcept;
326 AST_UTIL_API
bool create_directories(
const path& p)
noexcept;
327 AST_UTIL_API
bool create_directories(
const path& p, std::error_code& ec)
noexcept;
328 AST_UTIL_API
bool remove(
const path& p)
noexcept;
329 AST_UTIL_API
bool remove(
const path& p, std::error_code& ec)
noexcept;
330 AST_UTIL_API uintmax_t remove_all(
const path& p)
noexcept;
333 AST_UTIL_API
bool copy_file(
const path& from,
const path& to)
noexcept;
334 AST_UTIL_API
bool rename(
const path& old_p,
const path& new_p)
noexcept;
337 inline directory_iterator begin(
const directory_iterator& iter)
noexcept
341 inline directory_iterator end(
const directory_iterator&)
noexcept
343 return directory_iterator();
353 inline bool operator==(
const path& left,
const path& right)
355 return (left.native() == right.native());
357 inline bool operator!=(
const path& left,
const path& right)
359 return (left.native() != right.native());
361 AST_UTIL_API space_info space(
const path& p);
364 AST_UTIL_API std::time_t last_write_time(
const path& p);
367 AST_UTIL_API path current_path() noexcept(false);
368 AST_UTIL_API path current_path(std::error_code& ec) noexcept;
369 AST_UTIL_API
void current_path(const path& new_path) noexcept(false);
370 AST_UTIL_API
void current_path(const path& new_path, std::error_code& ec) noexcept;
374 AST_UTIL_API path relative(const path& p, const path& base, std::error_code& ec) noexcept;
378 AST_UTIL_API path absolute(const path& p);
379 AST_UTIL_API path absolute(const path& p, std::error_code& ec) noexcept;
383 AST_UTIL_API path temp_directory_path();
384 AST_UTIL_API path temp_directory_path(std::error_code& ec) noexcept;
定义 FileSystemSimple.hpp:248
定义 FileSystemSimple.hpp:267
定义 FileSystemSimple.hpp:230
定义 FileSystemSimple.hpp:55
定义 FileSystemSimple.hpp:67
path stem() const
获取文件名的无扩展名部分
定义 FileSystemSimple.hpp:132
Unit none
无单位
定义 Unit.cpp:451
constexpr EDimension operator/(EDimension dim1, EDimension dim2) noexcept
量纲除法运算符
定义 Dimension.hpp:232
定义 FileSystemSimple.cpp:137
定义 FileSystemSimple.hpp:348