Disk ARchive  2.5.18
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-2052 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 "erreurs.hpp"
35 #include "on_pool.hpp"
36 
37 #define FAKE_ROOT path(string("<ROOT>"), true)
38 
39 namespace libdar
40 {
41 
43 
49 
50  class path : public on_pool
51  {
52  public :
54 
62  path(const std::string & s, bool x_undisclosed = false);
63 
65 
68  path(const char *s, bool x_undisclosed = false) { *this = path(std::string(s), x_undisclosed); };
69 
71  path(const path & ref);
72 
74  const path & operator = (const path & ref);
75 
77  bool operator == (const path & ref) const;
78  bool operator != (const path & ref) const { return !(*this == ref); };
79 
81 
83  std::string basename() const;
84 
86 
88  void reset_read() { reading = dirs.begin(); };
89 
91 
95  bool read_subdir(std::string & r);
96 
98  bool is_relative() const { return relative; };
99 
101  bool is_absolute() const { return !relative; };
102 
104  bool is_undisclosed() const { return undisclosed; };
105 
107 
113  bool pop(std::string & arg);
114 
116 
122  bool pop_front(std::string & arg);
123 
125 
129  path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; };
130 
131 
133 
136  path & operator += (const path & arg);
137 
139 
142  bool is_subdir_of(const path & p, bool case_sensit) const;
143 
145 
147  std::string display() const;
148 
152  unsigned int degre() const { return dirs.size() + (relative ? 0 : 1); };
153 
155  void explode_undisclosed() const;
156 
157  private :
158  std::list<std::string>::iterator reading;
159  std::list<std::string> dirs;
160  bool relative;
161  bool undisclosed;
162 
163  void reduce();
164  };
165 
166 
167 } // end of namespace
168 
169 #endif
bool is_relative() const
whether the path is relative or absolute (= start with a /)
Definition: path.hpp:98
unsigned int degre() const
returns the number of member in the path
Definition: path.hpp:152
void explode_undisclosed() const
if the current object is an undisclosed path, tries to convert it back to normal path ...
bool pop(std::string &arg)
remove and gives in argument the basename of the path
void reset_read()
reset the read_subdir operation
Definition: path.hpp:88
path(const std::string &s, bool x_undisclosed=false)
constructor from a string
bool read_subdir(std::string &r)
sequentially read the elements that compose the path
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
bool operator==(const path &ref) const
comparison operator
contains all the excetion class thrown by libdar
bool is_absolute() const
whether the path is absolute or relative
Definition: path.hpp:101
path(const char *s, bool x_undisclosed=false)
constructor from a char *
Definition: path.hpp:68
this is the base class of object that can be allocated on a memory pool
path operator+(const path &arg) const
add a path to the current path. The added path must be a relative path
Definition: path.hpp:129
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:104
const path & operator=(const path &ref)
assignment operator
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
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:50