Webdar 1.0.0
Web user interface to libdar
chemin.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef CHEMIN_HPP
25#define CHEMIN_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <string>
36#include <deque>
37
38 // webdar headers
39#include "exceptions.hpp"
40
41
43
49
50class chemin
51{
52public:
54 chemin() { members.clear(); index = 0; };
55 chemin(const std::string & path);
56 chemin(const chemin & ref) = default;
57 chemin(chemin && ref) noexcept = default;
58 chemin & operator = (const chemin & ref) = default;
59 chemin & operator = (chemin && ref) noexcept = default;
60 ~chemin() = default;
61
62
64
66
68
69
71 void clear() { members.clear(); index = 0; };
72
74 bool operator == (const chemin & ref) const { return members == ref.members; };
75 bool operator != (const chemin & ref) const { return !((*this) == ref); };
76
78 bool is_the_beginning_of(const chemin & ref) const;
79
81 void operator += (const chemin & ref);
82
84 chemin operator + (const chemin & ref) const { chemin ret = *this; ret += ref; return ret; };
85
87 void push_back(const std::string & x);
88
90
92 std::string front() const { if(empty()) throw exception_range("cannot get front() from an empty chemin"); return members.front(); };
93
95
97 std::string back() const { if(empty()) throw exception_range("cannot get back() from an empty chemin"); return members.back(); };
98
102 void pop_front();
103
105 void pop_back();
106
108 unsigned int size() const { return members.size(); };
109
111 bool empty() const { return members.empty(); };
112
113
119 unsigned int get_index() const { return index; };
120
122 void increase_index() const { if(index < size() - 1) ++(const_cast<chemin *>(this)->index); };
123
125 void decrease_index() const { if(index > 0) --(const_cast<chemin *>(this)->index); };
126
128 void set_index(unsigned int val) const;
129
131 std::string display(bool relative = false) const;
132
136 std::string namify() const;
137
143 const std::string & operator[] (unsigned int x) const;
144
145private:
146 std::deque<std::string> members;
147 unsigned int index;
148};
149
150
151#endif
class chemin definition
Definition: chemin.hpp:51
void clear()
default copy constructor is OK
Definition: chemin.hpp:71
std::string back() const
get the last member of the path
Definition: chemin.hpp:97
std::string front() const
get the first member of the path
Definition: chemin.hpp:92
const std::string & operator[](unsigned int x) const
Definition: chemin.cpp:161
void decrease_index() const
set the index to the previous member. If the member is the first of the path, this call does nothing
Definition: chemin.hpp:125
void push_back(const std::string &x)
add a member at the end of the path
Definition: chemin.cpp:72
void pop_front()
Definition: chemin.cpp:92
bool empty() const
return true if the path is an empty path (having no members)
Definition: chemin.hpp:111
void operator+=(const chemin &ref)
concatenate a path to this object
Definition: chemin.cpp:81
chemin()
constucts an empty path
Definition: chemin.hpp:54
std::string namify() const
Definition: chemin.cpp:140
bool operator==(const chemin &ref) const
compaires two path
Definition: chemin.hpp:74
void increase_index() const
set the index to the next member. If the member is the last of the path this call does nothing
Definition: chemin.hpp:122
std::string display(bool relative=false) const
return a string corresponding to the expected value of an absolute path
Definition: chemin.cpp:119
bool is_the_beginning_of(const chemin &ref) const
return true if 'this' is the beginning of ref
Definition: chemin.cpp:58
chemin operator+(const chemin &ref) const
concatenate a path with us another
Definition: chemin.hpp:84
unsigned int size() const
returns the size of the path in number of members
Definition: chemin.hpp:108
void set_index(unsigned int val) const
set the index to an arbitrary value. An exception is thrown if the given value is greater or equal th...
Definition: chemin.cpp:112
unsigned int get_index() const
Definition: chemin.hpp:119
void pop_back()
removes the last member of the path from this object
Definition: chemin.cpp:102
exception used to report out or range value or argument
Definition: exceptions.hpp:109