path.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef PATH_HPP
#define PATH_HPP
#include "../my_config.h"
#include <list>
#include <string>
#include "integers.hpp"
#include "erreurs.hpp"
namespace libdar
{
class path
{
public :
path(const std::string & s, bool x_undisclosed = false);
path(const path & ref);
path(path && ref) noexcept = default;
path & operator = (const path & ref);
path & operator = (path && ref) noexcept = default;
~path() = default;
bool operator == (const path & ref) const;
bool operator != (const path & ref) const { return !(*this == ref); };
std::string basename() const;
void reset_read() const { reading = dirs.begin(); };
bool read_subdir(std::string & r) const;
bool is_relative() const { return relative; };
bool is_absolute() const { return !relative; };
bool is_undisclosed() const { return undisclosed; };
bool pop(std::string & arg);
bool pop_front(std::string & arg);
path operator + (const path & arg) const { path tmp = *this; tmp += arg; return tmp; };
path append(const std::string & sub) const { path tmp = *this; if(sub.find_first_of("/") != std::string::npos) throw SRC_BUG; tmp += sub; return tmp; };
path & operator += (const path & arg);
path & operator += (const std::string & sub);
bool is_subdir_of(const path & p, bool case_sensit) const;
std::string display() const;
std::string display_without_root() const;
U_I degre() const { return dirs.size() + (relative ? 0 : 1); };
void explode_undisclosed() const;
private :
mutable std::list<std::string>::const_iterator reading;
std::list<std::string> dirs;
bool relative;
bool undisclosed;
void reduce();
void init(const std::string & chem, bool x_undisclosed);
};
extern const std::string PSEUDO_ROOT;
extern const path FAKE_ROOT;
} // end of namespace
#endif
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
libdar::path::explode_undisclosed
void explode_undisclosed() const
if the current object is an undisclosed path, tries to convert it back to normal path
libdar::path::read_subdir
bool read_subdir(std::string &r) const
sequentially read the elements that compose the path
libdar::path::pop
bool pop(std::string &arg)
remove and gives in argument the basename of the path
libdar::path::is_subdir_of
bool is_subdir_of(const path &p, bool case_sensit) const
test whether the current object is a subdir of the method's argument
libdar::path::~path
~path()=default
destructor
libdar::path::path
path(path &&ref) noexcept=default
move constructor
libdar::path::reset_read
void reset_read() const
reset the read_subdir operation
Definition: path.hpp:91
libdar::path::operator==
bool operator==(const path &ref) const
comparison operator
libdar::path::degre
U_I degre() const
returns the number of member in the path
Definition: path.hpp:166
libdar::path::is_absolute
bool is_absolute() const
whether the path is absolute or relative
Definition: path.hpp:104
libdar::path::path
path(const std::string &s, bool x_undisclosed=false)
constructor from a string
libdar::path::pop_front
bool pop_front(std::string &arg)
remove and gives in argument the outer most member of the path
libdar::path::display
std::string display() const
convert back a path to a string
libdar::path::operator=
path & operator=(const path &ref)
assignment operator
libdar::path::display_without_root
std::string display_without_root() const
display the path as a string but without the first member of the path
libdar::path::operator+=
path & operator+=(const path &arg)
add a path to the current path. The added path must be a relative path
libdar::path::operator+
path operator+(const path &arg) const
add a path to the current path. The added path must be a relative path
Definition: path.hpp:132
libdar::path::append
path append(const std::string &sub) const
add a single sub-directory to the path
Definition: path.hpp:135
libdar::path::is_undisclosed
bool is_undisclosed() const
whether the path has an undisclosed part at the beginning
Definition: path.hpp:107
libdar::path::path
path(const path &ref)
copy constructor
libdar::path::is_relative
bool is_relative() const
whether the path is relative or absolute (= start with a /)
Definition: path.hpp:101
libdar::path::basename
std::string basename() const
get the basename of a path
erreurs.hpp
contains all the excetion class thrown by libdar
libdar::PSEUDO_ROOT
const std::string PSEUDO_ROOT
root name to use when archive operation does not use filesystem (archive testing for example)
libdar::FAKE_ROOT
const path FAKE_ROOT
root path object based on PSEUDO_ROOT
integers.hpp
are defined here basic integer types that tend to be portable
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47