omega_h
Reliable mesh adaptation
Omega_h_filesystem.hpp
1 #ifndef OMEGA_H_FILESYSTEM_HPP
2 #define OMEGA_H_FILESYSTEM_HPP
3 
4 #include <cstdint>
5 #include <iosfwd>
6 #include <string>
7 #include <system_error>
8 
9 // our own tiny subset of std::filesystem while we wait for C++17
10 
11 namespace Omega_h {
12 
13 namespace filesystem {
14 
15 class filesystem_error : public std::system_error {
16  public:
17  filesystem_error(filesystem_error const&) = default;
18  virtual ~filesystem_error() override;
19  filesystem_error(int ev, const char* what_arg);
20 };
21 
22 class path {
23  public:
24  using value_type = char;
25 #ifdef _MSC_VER
26  static constexpr value_type preferred_separator = '\\';
27 #else
28  static constexpr value_type preferred_separator = '/';
29 #endif
30  using string_type = std::basic_string<value_type>;
31  path() = default;
32  path(value_type const* source);
33  path(string_type const& source);
34  value_type const* c_str() const noexcept;
35  const string_type& native() const noexcept;
36  std::string string() const;
37  path filename() const;
38  path extension() const;
39  path stem() const;
40  path parent_path() const;
41  path& operator/=(path const&);
42  path& operator/=(std::string const&);
43  path& operator/=(char const*);
44  path& operator+=(path const&);
45  path& operator+=(std::string const&);
46  path& operator+=(char const*);
47  path& operator+=(char);
48 
49  public:
50  string_type impl;
51 };
52 
53 path operator/(path const& a, path const& b);
54 std::ostream& operator<<(std::ostream& os, path const& p);
55 
56 bool create_directory(path const& p);
57 path current_path();
58 bool remove(path const& p);
59 std::uintmax_t remove_all(path const& p);
60 bool exists(path const& p);
61 
62 enum class file_type {
63  none,
64  not_found,
65  regular,
66  directory,
67  symlink,
68  block,
69  character,
70  fifo,
71  socket,
72  unknown
73 };
74 
75 class file_status {
76  public:
77  file_status(file_type const& type_in);
78  file_type type() const noexcept;
79 
80  private:
81  file_type type_variable;
82 };
83 
84 file_status status(path const& p);
85 
87  public:
88  directory_entry() = default;
90  const filesystem::path& path() const noexcept { return path_variable; }
91  bool is_regular_file() const;
92  bool is_directory() const;
93  bool is_symlink() const;
94 
95  private:
96  filesystem::path path_variable;
97 };
98 
99 struct IteratorImpl;
100 
102  public:
105  directory_iterator(path const& p);
107  directory_iterator& operator++();
108  const directory_entry& operator*() const;
109  const directory_entry* operator->() const;
110  bool operator==(directory_iterator const& other) const;
111  // hassle to implement, not needed
112  directory_iterator(directory_iterator const& other) = delete;
113 
114  private:
115  IteratorImpl* impl;
116  directory_entry entry;
117 };
118 
119 inline bool operator!=(
120  directory_iterator const& a, directory_iterator const& b) {
121  return !(a == b);
122 }
123 
124 } // namespace filesystem
125 
126 } // namespace Omega_h
127 
128 #endif
Definition: Omega_h_filesystem.hpp:86
Definition: Omega_h_filesystem.hpp:101
Definition: Omega_h_filesystem.hpp:75
Definition: Omega_h_filesystem.hpp:15
Definition: Omega_h_filesystem.hpp:22
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_filesystem.cpp:163