BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
filesystem.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <utility>
3 #include <memory>
4 
6 #include <fc/optional.hpp>
7 #include <fc/fwd.hpp>
8 
9 namespace boost {
10  namespace filesystem {
11  class path;
12  class directory_iterator;
13  class recursive_directory_iterator;
14  }
15 }
16 
17 
18 namespace fc {
28  class path {
29  public:
30  path();
31  ~path();
32  path( const boost::filesystem::path& );
33  path( const std::string& p );
35  path(const std::wstring& p);
36  path( const char* );
37  path( const path& p );
38  path( path&& p );
39  path& operator =( const path& );
40  path& operator =( path&& );
41 
42  path& operator /=( const fc::path& );
43  friend path operator /( const fc::path& p, const fc::path& );
44  friend bool operator ==( const fc::path& p, const fc::path& );
45  friend bool operator !=( const fc::path& p, const fc::path& );
46  friend bool operator < ( const fc::path& p, const fc::path& );
47 
48  operator boost::filesystem::path& ();
49  operator const boost::filesystem::path& ()const;
50 
51  void replace_extension( const fc::path& e );
52  fc::path stem()const;
53  fc::path extension()const;
54  fc::path filename()const;
55  fc::path parent_path()const;
56  std::string string()const;
57  std::string generic_string()const;
61  std::string preferred_string() const;
62 
63  std::wstring wstring() const;
64  std::wstring generic_wstring() const;
65  std::wstring preferred_wstring() const;
66 
72  std::string to_native_ansi_path() const;
73 
79  std::string windows_string()const;
80 
81  bool is_relative()const;
82  bool is_absolute()const;
83 
84  static char separator_char;
85 
86  private:
87  #ifdef _WIN64
89  #else
91  #endif
92  };
93 
94  namespace detail
95  {
97  {
98  public:
100  _path(p)
101  {
102  }
103  const path* operator->() const
104  {
105  return &_path;
106  }
107  private:
108  path _path;
109  };
110  }
111 
113  public:
114  directory_iterator( const fc::path& p );
117 
118  fc::path operator*()const;
119  detail::path_wrapper operator->() const;
120  directory_iterator& operator++(int);
121  directory_iterator& operator++();
122 
123  friend bool operator==( const directory_iterator&, const directory_iterator& );
124  friend bool operator!=( const directory_iterator&, const directory_iterator& );
125  private:
127  };
129  public:
133 
134  fc::path operator*()const;
135  recursive_directory_iterator& operator++(int);
136  recursive_directory_iterator& operator++();
137  void pop();
138  int level();
139 
140 
143  private:
145  };
146 
147  bool exists( const path& p );
148  bool is_directory( const path& p );
149  bool is_regular_file( const path& p );
150  void create_directories( const path& p );
151  void remove_all( const path& p );
152  path absolute( const path& p );
153  path make_relative(const path& from, const path& to);
154  path canonical( const path& p );
155  uint64_t file_size( const path& p );
156  uint64_t directory_size( const path& p );
157  bool remove( const path& p );
158  void copy( const path& from, const path& to );
159  void rename( const path& from, const path& to );
160  void resize_file( const path& file, size_t s );
161 
162  // setuid, setgid not implemented.
163  // translates octal permission like 0755 to S_ stuff defined in sys/stat.h
164  // no-op on Windows.
165  void chmod( const path& p, int perm );
166 
167  void create_hard_link( const path& from, const path& to );
168 
169  path unique_path();
171 
173  const path& home_path();
174 
178  const path& app_path();
179 
181  const fc::path& current_path();
182 
183  class variant;
184  void to_variant( const fc::path&, fc::variant&, uint32_t max_depth = 1 );
185  void from_variant( const fc::variant&, fc::path&, uint32_t max_depth = 1 );
186 
187  template<> struct get_typename<path> { static const char* name() { return "path"; } };
188 
193  {
194  public:
195  inline ~temp_file_base() { remove(); }
196  inline operator bool() const { return _path.valid(); }
197  inline bool operator!() const { return !_path; }
198  const fc::path& path() const;
199  void remove();
200  void release();
201  protected:
203  inline temp_file_base(const path_t& path) : _path(path) {}
204  inline temp_file_base(path_t&& path) : _path(std::move(path)) {}
205  path_t _path;
206  };
207 
211  class temp_file : public temp_file_base
212  {
213  public:
214  temp_file(temp_file&& other);
215  temp_file& operator=(temp_file&& other);
216  temp_file(const fc::path& tempFolder = fc::temp_directory_path(), bool create = false);
217  };
218 
223  {
224  public:
226  temp_directory& operator=(temp_directory&& other);
227  temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
228  };
229 
230 }
231 
Used to forward declare value types.
Definition: fwd.hpp:10
bool exists(const path &p)
Definition: filesystem.cpp:209
static char separator_char
Definition: filesystem.hpp:84
bool is_regular_file(const path &p)
Definition: filesystem.cpp:218
void from_variant(const fc::variant &, fc::path &, uint32_t max_depth=1)
Definition: filesystem.cpp:37
void to_variant(const fc::path &, fc::variant &, uint32_t max_depth=1)
Definition: filesystem.cpp:29
void chmod(const path &p, int perm)
Definition: filesystem.cpp:278
temp_file_base(path_t &&path)
Definition: filesystem.hpp:204
price & operator/=(price &p, const ratio_type &r)
Definition: asset.hpp:157
bool operator!() const
Definition: filesystem.hpp:197
void rename(const path &from, const path &to)
Definition: filesystem.cpp:302
uint64_t directory_size(const path &p)
Definition: filesystem.cpp:221
void create_directories(const path &p)
Definition: filesystem.cpp:210
void remove_all(const path &p)
Definition: filesystem.cpp:240
void create_hard_link(const path &from, const path &to)
Definition: filesystem.cpp:319
bool operator!=(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:253
bool is_relative(object_id_type o)
Definition: types.hpp:240
const path & app_path()
Definition: filesystem.cpp:480
bool operator==(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:245
path make_relative(const path &from, const path &to)
Definition: filesystem.cpp:346
fc::optional< fc::path > path_t
Definition: filesystem.hpp:202
temp_file_base(const path_t &path)
Definition: filesystem.hpp:203
const path * operator->() const
Definition: filesystem.hpp:103
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
uint64_t file_size(const path &p)
Definition: filesystem.cpp:219
path canonical(const path &p)
Definition: filesystem.cpp:334
bool is_directory(const path &p)
Definition: filesystem.cpp:217
variant operator/(const variant &a, const variant &b)
Definition: variant.cpp:840
path unique_path()
Definition: filesystem.cpp:342
const fc::path & current_path()
Definition: filesystem.cpp:498
path temp_directory_path()
Definition: filesystem.cpp:343
Definition: api.hpp:15
const path & home_path()
Definition: filesystem.cpp:448
bool operator<(const variant &a, const variant &b)
Definition: variant.cpp:734
static const char * name()
Definition: filesystem.hpp:187
void copy(const path &from, const path &to)
Definition: filesystem.cpp:241
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
variant operator*(const variant &a, const variant &b)
Definition: variant.cpp:815
path absolute(const path &p)
Definition: filesystem.cpp:341
void resize_file(const path &file, size_t s)
Definition: filesystem.cpp:258