Disk ARchive  2.4.21
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 "special_alloc.hpp"
36 
37 #define FAKE_ROOT path(string("<ROOT>"), true)
38 
39 namespace libdar
40 {
41 
43 
49 
50  class path
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 
80 
82  std::string basename() const;
83 
85 
87  void reset_read() { reading = dirs.begin(); };
88 
90 
94  bool read_subdir(std::string & r);
95 
97  bool is_relative() const { return relative; };
98 
100  bool is_absolute() const { return !relative; };
101 
103  bool is_undisclosed() const { return undisclosed; };
104 
106 
112  bool pop(std::string & arg);
113 
115 
121  bool pop_front(std::string & arg);
122 
124 
128  path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; };
129 
130 
132 
135  path & operator += (const path & arg);
136 
138 
141  bool is_subdir_of(const path & p, bool case_sensit) const;
142 
144 
146  std::string display() const;
147 
151  unsigned int degre() const { return dirs.size() + (relative ? 0 : 1); };
152 
154  void explode_undisclosed() const;
155 
156 #ifdef LIBDAR_SPECIAL_ALLOC
157  USE_SPECIAL_ALLOC(path);
158 #endif
159  private :
160  std::list<std::string>::iterator reading;
161  std::list<std::string> dirs;
162  bool relative;
163  bool undisclosed;
164 
165  void reduce();
166  };
167 
168 
169 } // end of namespace
170 
171 #endif
path operator+(const path &arg) const
add a path to the current path. The added path must be a relative path
Definition: path.hpp:128
bool is_absolute() const
whether the path is absolute or relative
Definition: path.hpp:100
bool is_undisclosed() const
whether the path has an undisclosed part at the beginning
Definition: path.hpp:103
bool pop(std::string &arg)
remove and gives in argument the basename of the path
re-definition of new and delete class operatorthis is a set of macro that makes the new and delete op...
std::string basename() const
get the basename of a path
void reset_read()
reset the read_subdir operation
Definition: path.hpp:87
bool is_relative() const
whether the path is relative or absolute (= start with a /)
Definition: path.hpp:97
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
void explode_undisclosed() const
if the current object is an undisclosed path, tries to convert it back to normal 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 pop_front(std::string &arg)
remove and gives in argument the outer most member of the path
bool operator==(const path &ref) const
comparison operator
contains all the excetion class thrown by libdar
path(const char *s, bool x_undisclosed=false)
constructor from a char *
Definition: path.hpp:68
std::string display() const
convert back a path to a string
path & operator+=(const path &arg)
add a path to the current path. The added path must be a relative path
unsigned int degre() const
returns the number of member in the path
Definition: path.hpp:151
const path & operator=(const path &ref)
assignment operator
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43
the class path is here to manipulate paths in the Unix notation: using&#39;/&#39;
Definition: path.hpp:50