BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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;
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;
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)) {}
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:
227  temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
228  };
229 
230 }
231 
fc::temp_file_base::path
const fc::path & path() const
Definition: filesystem.cpp:418
fc::copy
void copy(const path &from, const path &to)
Definition: filesystem.cpp:241
fc::remove_all
void remove_all(const path &p)
Definition: filesystem.cpp:240
fc::recursive_directory_iterator::recursive_directory_iterator
recursive_directory_iterator()
Definition: filesystem.cpp:191
fc::path::wstring
std::wstring wstring() const
Definition: filesystem.cpp:104
fc::temp_directory::temp_directory
temp_directory(temp_directory &&other)
Definition: filesystem.cpp:403
fc::path::extension
fc::path extension() const
Definition: filesystem.cpp:157
fc::unique_path
path unique_path()
Definition: filesystem.cpp:342
fc::recursive_directory_iterator::operator==
friend bool operator==(const recursive_directory_iterator &, const recursive_directory_iterator &)
Definition: filesystem.cpp:201
fc::path::~path
~path()
Definition: filesystem.cpp:48
fc::path::preferred_wstring
std::wstring preferred_wstring() const
Definition: filesystem.cpp:114
fwd.hpp
fc
Definition: api.hpp:15
fc::temp_file_base
Definition: filesystem.hpp:192
fc::recursive_directory_iterator::~recursive_directory_iterator
~recursive_directory_iterator()
Definition: filesystem.cpp:192
fc::directory_iterator::operator==
friend bool operator==(const directory_iterator &, const directory_iterator &)
Definition: filesystem.cpp:180
fc::chmod
void chmod(const path &p, int perm)
Definition: filesystem.cpp:278
fc::directory_iterator::directory_iterator
directory_iterator()
Definition: filesystem.cpp:172
fc::create_hard_link
void create_hard_link(const path &from, const path &to)
Definition: filesystem.cpp:319
fc::temp_file_base::operator!
bool operator!() const
Definition: filesystem.hpp:197
fc::is_directory
bool is_directory(const path &p)
Definition: filesystem.cpp:217
fc::path::operator/=
path & operator/=(const fc::path &)
Definition: filesystem.cpp:79
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::detail::path_wrapper::path_wrapper
path_wrapper(path p)
Definition: filesystem.hpp:99
fc::directory_iterator
Definition: filesystem.hpp:112
fc::path::string
std::string string() const
Definition: filesystem.cpp:148
fc::directory_iterator::~directory_iterator
~directory_iterator()
Definition: filesystem.cpp:173
fc::make_relative
path make_relative(const path &from, const path &to)
Definition: filesystem.cpp:346
fc::path::stem
fc::path stem() const
Definition: filesystem.cpp:160
fc::app_path
const path & app_path()
Definition: filesystem.cpp:480
fc::path::operator=
path & operator=(const path &)
Definition: filesystem.cpp:66
fc::path::replace_extension
void replace_extension(const fc::path &e)
Definition: filesystem.cpp:154
fc::path::is_absolute
bool is_absolute() const
Definition: filesystem.cpp:167
fc::directory_iterator::operator++
directory_iterator & operator++()
Definition: filesystem.cpp:178
fc::recursive_directory_iterator::operator++
recursive_directory_iterator & operator++()
Definition: filesystem.cpp:196
fc::remove
bool remove(const path &p)
Definition: filesystem.cpp:327
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
fc::optional::valid
bool valid() const
Definition: optional.hpp:186
fc::path::operator/
friend path operator/(const fc::path &p, const fc::path &)
Definition: filesystem.cpp:83
fc::temp_directory
Definition: filesystem.hpp:222
fc::recursive_directory_iterator::operator*
fc::path operator*() const
Definition: filesystem.cpp:194
fc::get_typename
Definition: typename.hpp:20
fc::get_typename< path >::name
static const char * name()
Definition: filesystem.hpp:187
fc::current_path
const fc::path & current_path()
Definition: filesystem.cpp:498
fc::path::windows_string
std::string windows_string() const
replaces '/' with '\' in the result of generic_string()
Definition: filesystem.cpp:142
fc::path::path
path()
Definition: filesystem.cpp:47
fc::recursive_directory_iterator
Definition: filesystem.hpp:128
fc::recursive_directory_iterator::level
int level()
Definition: filesystem.cpp:199
fc::path::to_native_ansi_path
std::string to_native_ansi_path() const
Definition: filesystem.cpp:119
fc::temp_file::temp_file
temp_file(temp_file &&other)
Definition: filesystem.cpp:378
fc::temp_directory::operator=
temp_directory & operator=(temp_directory &&other)
Definition: filesystem.cpp:408
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::temp_file::operator=
temp_file & operator=(temp_file &&other)
Definition: filesystem.cpp:383
fc::temp_file_base::~temp_file_base
~temp_file_base()
Definition: filesystem.hpp:195
fc::path::generic_string
std::string generic_string() const
Definition: filesystem.cpp:95
fc::recursive_directory_iterator::pop
void pop()
Definition: filesystem.cpp:198
fc::detail::path_wrapper::operator->
const path * operator->() const
Definition: filesystem.hpp:103
fc::temp_directory_path
path temp_directory_path()
Definition: filesystem.cpp:343
fc::resize_file
void resize_file(const path &file, size_t s)
Definition: filesystem.cpp:258
fc::absolute
path absolute(const path &p)
Definition: filesystem.cpp:341
fc::home_path
const path & home_path()
Definition: filesystem.cpp:448
fc::recursive_directory_iterator::operator!=
friend bool operator!=(const recursive_directory_iterator &, const recursive_directory_iterator &)
Definition: filesystem.cpp:204
fc::directory_iterator::operator*
fc::path operator*() const
Definition: filesystem.cpp:175
fc::path::operator!=
friend bool operator!=(const fc::path &p, const fc::path &)
Definition: filesystem.cpp:77
fc::canonical
path canonical(const path &p)
Definition: filesystem.cpp:334
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
fc::temp_file_base::release
void release()
Definition: filesystem.cpp:443
fc::directory_iterator::operator->
detail::path_wrapper operator->() const
Definition: filesystem.cpp:176
std
Definition: zeroed_array.hpp:76
fc::path::parent_path
fc::path parent_path() const
Definition: filesystem.cpp:163
fc::path::is_relative
bool is_relative() const
Definition: filesystem.cpp:166
fc::file_size
uint64_t file_size(const path &p)
Definition: filesystem.cpp:219
fc::temp_file
Definition: filesystem.hpp:211
fc::create_directories
void create_directories(const path &p)
Definition: filesystem.cpp:210
fc::path::generic_wstring
std::wstring generic_wstring() const
Definition: filesystem.cpp:109
fc::optional< fc::path >
fc::path::operator<
friend bool operator<(const fc::path &p, const fc::path &)
Definition: filesystem.cpp:75
fc::is_regular_file
bool is_regular_file(const path &p)
Definition: filesystem.cpp:218
fc::temp_file_base::remove
void remove()
Definition: filesystem.cpp:427
fc::path::operator==
friend bool operator==(const fc::path &p, const fc::path &)
Definition: filesystem.cpp:76
fc::temp_file_base::_path
path_t _path
Definition: filesystem.hpp:205
fc::detail::path_wrapper
Definition: filesystem.hpp:96
fc::temp_file_base::temp_file_base
temp_file_base(path_t &&path)
Definition: filesystem.hpp:204
typename.hpp
fc::path::preferred_string
std::string preferred_string() const
Definition: filesystem.cpp:99
fc::temp_file_base::temp_file_base
temp_file_base(const path_t &path)
Definition: filesystem.hpp:203
fc::path::filename
fc::path filename() const
Definition: filesystem.cpp:151
fc::rename
void rename(const path &from, const path &to)
Definition: filesystem.cpp:302
fc::fwd
Used to forward declare value types.
Definition: fwd.hpp:10
fc::exists
bool exists(const path &p)
Definition: filesystem.cpp:209
fc::temp_file_base::path_t
fc::optional< fc::path > path_t
Definition: filesystem.hpp:202
fc::directory_iterator::operator!=
friend bool operator!=(const directory_iterator &, const directory_iterator &)
Definition: filesystem.cpp:183
fc::directory_size
uint64_t directory_size(const path &p)
Definition: filesystem.cpp:221
fc::path::separator_char
static char separator_char
Definition: filesystem.hpp:84
optional.hpp