Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 // $Id: path.hpp,v 1.18.2.1 2012/02/19 17:25:09 edrusb Rel $
22 //
23 /*********************************************************************/
24 
30 
31 #ifndef PATH_HPP
32 #define PATH_HPP
33 
34 #include "../my_config.h"
35 #include <list>
36 #include <string>
37 #include "erreurs.hpp"
38 #include "special_alloc.hpp"
39 
40 #define FAKE_ROOT path(string("<ROOT>"), true)
41 
42 namespace libdar
43 {
44 
46 
52 
53  class path
54  {
55  public :
57 
65  path(const std::string & s, bool x_undisclosed = false);
66 
68 
71  path(const char *s, bool x_undisclosed = false) { *this = path(std::string(s), x_undisclosed); };
72 
74  path(const path & ref);
75 
77  const path & operator = (const path & ref);
78 
80  bool operator == (const path & ref) const;
81 
83 
85  std::string basename() const;
86 
88 
90  void reset_read() { reading = dirs.begin(); };
91 
93 
97  bool read_subdir(std::string & r);
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 
133 
135 
138  path & operator += (const path & arg);
139 
141 
144  bool is_subdir_of(const path & p, bool case_sensit) const;
145 
147 
149  std::string display() const;
150 
154  unsigned int degre() const { return dirs.size() + (relative ? 0 : 1); };
155 
157  void explode_undisclosed() const;
158 
159 #ifdef LIBDAR_SPECIAL_ALLOC
160  USE_SPECIAL_ALLOC(path);
161 #endif
162  private :
163  std::list<std::string>::iterator reading;
164  std::list<std::string> dirs;
165  bool relative;
166  bool undisclosed;
167 
168  void reduce();
169  };
170 
171 
172 } // end of namespace
173 
174 #endif