Disk ARchive  2.7.14
Full featured and portable backup and archiving tool
path.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2024 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author, see the AUTHOR file
20 /*********************************************************************/
21 
27 
28 #ifndef PATH_HPP
29 #define PATH_HPP
30 
31 #include "../my_config.h"
32 #include <list>
33 #include <string>
34 #include "integers.hpp"
35 #include "erreurs.hpp"
36 
37 namespace libdar
38 {
41 
43 
50  class path
51  {
52  public :
54 
62  path(const std::string & s, bool x_undisclosed = false);
63 
65  path(const path & ref);
66 
68  path(path && ref) noexcept = default;
69 
71  path & operator = (const path & ref);
72 
74  path & operator = (path && ref) noexcept = default;
75 
77  ~path() = default;
78 
80  bool operator == (const path & ref) const;
81  bool operator != (const path & ref) const { return !(*this == ref); };
82 
84 
86  std::string basename() const;
87 
89 
91  void reset_read() const { reading = dirs.begin(); };
92 
94 
98  bool read_subdir(std::string & r) const;
99 
101  bool is_relative() const { return relative; };
102 
104  bool is_absolute() const { return !relative; };
105 
107  bool is_undisclosed() const { return undisclosed; };
108 
110 
116  bool pop(std::string & arg);
117 
119 
125  bool pop_front(std::string & arg);
126 
128 
132  path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; };
133 
135  path append(const std::string & sub) const { path tmp = *this; if(sub.find_first_of("/") != std::string::npos) throw SRC_BUG; tmp += sub; return tmp; };
136 
138 
141  path & operator += (const path & arg);
142 
144  path & operator += (const std::string & sub);
145 
147 
150  bool is_subdir_of(const path & p, bool case_sensit) const;
151 
153 
155  std::string display() const;
156 
158 
161  std::string display_without_root() const;
162 
164 
166  U_I degre() const { return dirs.size() + (relative ? 0 : 1); };
167 
169  void explode_undisclosed() const;
170 
171  private :
172  mutable std::list<std::string>::const_iterator reading;
173  std::list<std::string> dirs;
174  bool relative;
175  bool undisclosed;
176 
177  void reduce();
178  void init(const std::string & chem, bool x_undisclosed);
179  };
180 
182  extern const std::string PSEUDO_ROOT;
183 
185  extern const path FAKE_ROOT;
186 
188 
189 } // end of namespace
190 
191 #endif
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
void explode_undisclosed() const
if the current object is an undisclosed path, tries to convert it back to normal path
bool read_subdir(std::string &r) const
sequentially read the elements that compose the path
bool pop(std::string &arg)
remove and gives in argument the basename of the path
bool is_subdir_of(const path &p, bool case_sensit) const
test whether the current object is a subdir of the method's argument
~path()=default
destructor
path(path &&ref) noexcept=default
move constructor
path & operator+=(const path &arg)
add a path to the current path. The added path must be a relative path
void reset_read() const
reset the read_subdir operation
Definition: path.hpp:91
bool operator==(const path &ref) const
comparison operator
U_I degre() const
returns the number of member in the path
Definition: path.hpp:166
bool is_absolute() const
whether the path is absolute or relative
Definition: path.hpp:104
path(const std::string &s, bool x_undisclosed=false)
constructor from a string
bool pop_front(std::string &arg)
remove and gives in argument the outer most member of the path
std::string display() const
convert back a path to a string
path & operator=(const path &ref)
assignment operator
std::string display_without_root() const
display the path as a string but without the first member of the path
path operator+(const path &arg) const
add a path to the current path. The added path must be a relative path
Definition: path.hpp:132
path append(const std::string &sub) const
add a single sub-directory to the path
Definition: path.hpp:135
bool is_undisclosed() const
whether the path has an undisclosed part at the beginning
Definition: path.hpp:107
path(const path &ref)
copy constructor
bool is_relative() const
whether the path is relative or absolute (= start with a /)
Definition: path.hpp:101
std::string basename() const
get the basename of a path
contains all the excetion class thrown by libdar
const std::string PSEUDO_ROOT
root name to use when archive operation does not use filesystem (archive testing for example)
const path FAKE_ROOT
root path object based on PSEUDO_ROOT
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47