Disk ARchive
2.4.5
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id$ 00022 // 00023 /*********************************************************************/ 00024 00025 #ifndef PATH_HPP 00026 #define PATH_HPP 00027 00028 #pragma interface 00029 00030 #include <list> 00031 #include <string> 00032 #include "erreurs.hpp" 00033 00034 using namespace std; 00035 00036 class path 00037 { 00038 public : 00039 path(string s); // empty string is not a valid string (exception thrown) 00040 path(const char *s) { *this = path(string(s)); }; 00041 path(const path & ref); 00042 path & operator = (const path & ref); 00043 bool operator == (const path & ref) const; 00044 00045 string basename() const; // name of the innermost directory/file of the path 00046 void reset_read() { reading = dirs.begin(); }; // reset for read_subdir. next call to read_subdir is the most global 00047 // directory 00048 bool read_subdir(string & r); // return the name of the next directory part of the path to basename(), starting at root 00049 bool is_relative() const { return relative; }; 00050 bool pop(string & arg); // remove and return in argument the basename of the path, return false if not possible (no sub-directory) 00051 bool pop_front(string & arg); // removes and returns the first directory of the path, 00052 // when just the basename is present returns false, if the path is absolute, 00053 // the first call change it to relative (except if equal to "/" then return false) 00054 00055 path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; }; 00056 // add arg as a subdir of the object, arg can be a string also, which is converted to a path on the fly 00057 path & operator += (const path & arg); 00058 bool is_subdir_of(const path & p) const; 00059 string display() const; 00060 unsigned int degre() const { return dirs.size() + (relative ? 0 : 1); }; 00061 00062 private : 00063 list<string>::iterator reading; 00064 list<string> dirs; 00065 bool relative; 00066 00067 void reduce(); 00068 }; 00069 00070 #endif