Disk ARchive  2.6.0
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-2018 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
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 
36 namespace libdar
37 {
40 
42 
49  class path
50  {
51  public :
53 
61  path(const std::string & s, bool x_undisclosed = false);
62 
64  path(const path & ref);
65 
67  path(path && ref) noexcept = default;
68 
70  path & operator = (const path & ref);
71 
73  path & operator = (path && ref) noexcept = default;
74 
76  ~path() = default;
77 
79  bool operator == (const path & ref) const;
80  bool operator != (const path & ref) const { return !(*this == ref); };
81 
83 
85  std::string basename() const;
86 
88 
90  void reset_read() const { reading = dirs.begin(); };
91 
93 
97  bool read_subdir(std::string & r) const;
98 
100  bool is_relative() const { return relative; };
101 
103  bool is_absolute() const { return !relative; };
104 
106  bool is_undisclosed() const { return undisclosed; };
107 
109 
115  bool pop(std::string & arg);
116 
118 
124  bool pop_front(std::string & arg);
125 
127 
131  path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; };
132 
134  path operator + (const std::string & sub) const { path tmp = *this; tmp += sub; return tmp; };
135 
137 
140  path & operator += (const path & arg);
141 
143  path & operator += (const std::string & sub);
144 
146 
149  bool is_subdir_of(const path & p, bool case_sensit) const;
150 
152 
154  std::string display() const;
155 
157 
160  std::string display_without_root() const;
161 
163 
165  U_I degre() const { return dirs.size() + (relative ? 0 : 1); };
166 
168  void explode_undisclosed() const;
169 
170  private :
171  mutable std::list<std::string>::const_iterator reading;
172  std::list<std::string> dirs;
173  bool relative;
174  bool undisclosed;
175 
176  void reduce();
177  void init(const std::string & chem, bool x_undisclosed);
178  };
179 
181  extern const std::string PSEUDO_ROOT;
182 
184  extern const path FAKE_ROOT;
185 
187 
188 } // end of namespace
189 
190 #endif
are defined here basic integer types that tend to be portable
bool is_relative() const
whether the path is relative or absolute (= start with a /)
Definition: path.hpp:100
const std::string PSEUDO_ROOT
root name to use when archive operation does not use filesystem (archive testing for example) ...
U_I degre() const
returns the number of member in the path
Definition: path.hpp:165
void explode_undisclosed() const
if the current object is an undisclosed path, tries to convert it back to normal path ...
path & operator=(const path &ref)
assignment operator
bool pop(std::string &arg)
remove and gives in argument the basename of the path
void reset_read() const
reset the read_subdir operation
Definition: path.hpp:90
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 basename() const
get the basename of a path
~path()=default
destructor
bool operator==(const path &ref) const
comparison operator
std::string display_without_root() const
display the path as a string but without the first member of the path
const path FAKE_ROOT
root path object based on PSEUDO_ROOT
bool is_absolute() const
whether the path is absolute or relative
Definition: path.hpp:103
path operator+(const path &arg) const
add a path to the current path. The added path must be a relative path
Definition: path.hpp:131
path & operator+=(const path &arg)
add a path to the current path. The added path must be a relative path
bool is_subdir_of(const path &p, bool case_sensit) const
test whether the current object is a subdir of the method&#39;s argument
bool is_undisclosed() const
whether the path has an undisclosed part at the beginning
Definition: path.hpp:106
bool read_subdir(std::string &r) const
sequentially read the elements that compose the path
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46
std::string display() const
convert back a path to a string
the class path is here to manipulate paths in the Unix notation: using&#39;/&#39;
Definition: path.hpp:49