libzypp 17.37.10

Pathname.h
Go to the documentation of this file.
1
2/*---------------------------------------------------------------------\
3| ____ _ __ __ ___ |
4| |__ / \ / / . \ . \ |
5| / / \ V /| _/ _/ |
6| / /__ | | | | | | |
7| /_____||_| |_| |_| |
8| |
9\---------------------------------------------------------------------*/
13#ifndef ZYPP_PATHNAME_H
14#define ZYPP_PATHNAME_H
15
16#include <iosfwd>
17#include <string>
18
19#include <zypp/Globals.h>
20
22 namespace zypp
23{
24
25 class Url;
26
28 namespace filesystem
29 {
30
32 //
33 // CLASS NAME : Pathname
34 //
46 class ZYPP_API Pathname
47 {
48 public:
50 Pathname()
51 {}
52
54 Pathname( const std::string & name_r )
55 { _assign( name_r ); }
56
58 Pathname( const char * name_r )
59 { _assign( name_r ? name_r : "" ); }
60
62 Pathname( const Pathname & rhs )
63 : _name( rhs._name )
64 {}
65
67 friend void swap( Pathname & lhs, Pathname & rhs ) noexcept
68 {
69 using std::swap;
70 swap( lhs._name, rhs._name );
71 }
72
74 Pathname( Pathname && tmp ) noexcept
75 : _name( std::move( tmp._name ) )
76 {}
77
79 Pathname & operator=( Pathname rhs )
80 { swap( *this, rhs ); return *this; }
81
83 Pathname & operator/=( const Pathname & path_tv )
84 { return( *this = cat( *this, path_tv ) ); }
85
89 Pathname & operator+=( const Pathname & path_tv )
90 { return( *this = cat( *this, path_tv ) ); }
91
93 const std::string & asString() const
94 { return _name; }
95
97 static std::string showRoot( const Pathname & root_r, const Pathname & path_r );
98
100 static std::string showRootIf( const Pathname & root_r, const Pathname & path_r );
101
103 Url asUrl( const std::string & scheme_r ) const;
105 Url asUrl() const;
107 Url asDirUrl() const;
109 Url asFileUrl() const;
110
112 const char * c_str() const
113 { return _name.c_str(); }
114
116 bool empty() const { return _name.empty(); }
118 bool absolute() const { return *_name.c_str() == '/'; }
120 bool relative() const { return !( absolute() || empty() ); }
121
123 bool emptyOrRoot() const { return( _name.empty() || _name == "/" ); }
124
126 Pathname dirname() const { return dirname( *this ); }
127 static Pathname dirname( const Pathname & name_r );
128
130 std::string basename() const { return basename( *this ); }
131 static std::string basename( const Pathname & name_r );
132
137 std::string extension() const { return extension( *this ); }
138 static std::string extension( const Pathname & name_r );
139
141 Pathname absolutename() const { return absolutename( *this ); }
142 static Pathname absolutename( const Pathname & name_r )
143 { return name_r.relative() ? cat( "/", name_r ) : name_r; }
144
146 Pathname relativename() const { return relativename( *this ); }
147 static Pathname relativename( const Pathname & name_r )
148 { return name_r.absolute() ? cat( ".", name_r ) : name_r; }
149
151 Pathname realpath() const;
152
154 static Pathname assertprefix( const Pathname & root_r, const Pathname & path_r );
155
157 static Pathname stripprefix( const Pathname & root_r, const Pathname & path_r );
158
167 Pathname cat( const Pathname & r ) const { return cat( *this, r ); }
168 static Pathname cat( const Pathname & l, const Pathname & r );
169
175 Pathname extend( const std::string & r ) const { return extend( *this, r ); }
176 static Pathname extend( const Pathname & l, const std::string & r );
177
178 private:
179 std::string _name;
180 void _assign( const std::string & name_r );
181 };
182
183
185 inline bool operator==( const Pathname & l, const Pathname & r )
186 { return l.asString() == r.asString(); }
187
189 inline bool operator!=( const Pathname & l, const Pathname & r )
190 { return l.asString() != r.asString(); }
191
193 inline Pathname operator/( const Pathname & l, const Pathname & r )
194 { return Pathname::cat( l, r ); }
195
199 inline Pathname operator+( const Pathname & l, const Pathname & r )
200 { return Pathname::cat( l, r ); }
201
203 inline bool operator<( const Pathname & l, const Pathname & r )
204 { return l.asString() < r.asString(); }
205
207
209 inline std::ostream & operator<<( std::ostream & str, const Pathname & obj )
210 { return str << obj.asString(); }
211
213 } // namespace filesystem
215
217 using filesystem::Pathname;
218
220} // namespace zypp
222#endif // ZYPP_PATHNAME_H
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::relativename
Pathname relativename() const
Return this path, removing a leading '/' if absolute.
Definition Pathname.h:146
zypp::filesystem::Pathname::extend
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
Definition Pathname.h:175
zypp::filesystem::Pathname::extend
static Pathname extend(const Pathname &l, const std::string &r)
zypp::filesystem::Pathname::Pathname
Pathname(const Pathname &rhs)
Copy Ctor.
Definition Pathname.h:62
zypp::filesystem::Pathname::operator<<
std::ostream & operator<<(std::ostream &str, const Pathname &obj)
Stream output.
Definition Pathname.h:209
zypp::filesystem::Pathname::operator/=
Pathname & operator/=(const Pathname &path_tv)
Concatenate and assign.
Definition Pathname.h:83
zypp::filesystem::Pathname::swap
friend void swap(Pathname &lhs, Pathname &rhs) noexcept
Swap.
Definition Pathname.h:67
zypp::filesystem::Pathname::Pathname
Pathname(Pathname &&tmp) noexcept
Move Ctor.
Definition Pathname.h:74
zypp::filesystem::Pathname::absolutename
static Pathname absolutename(const Pathname &name_r)
Definition Pathname.h:142
zypp::filesystem::Pathname::operator+=
Pathname & operator+=(const Pathname &path_tv)
Concatenate and assign.
Definition Pathname.h:89
zypp::filesystem::Pathname::dirname
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
zypp::filesystem::Pathname::emptyOrRoot
bool emptyOrRoot() const
Test for "" or "/".
Definition Pathname.h:123
zypp::filesystem::Pathname::absolute
bool absolute() const
Test for an absolute path.
Definition Pathname.h:118
zypp::filesystem::Pathname::operator+
Pathname operator+(const Pathname &l, const Pathname &r)
Concatenate two Pathname.
Definition Pathname.h:199
zypp::filesystem::Pathname::operator!=
bool operator!=(const Pathname &l, const Pathname &r)
Definition Pathname.h:189
zypp::filesystem::Pathname::cat
Pathname cat(const Pathname &r) const
Concatenation of pathnames.
Definition Pathname.h:167
zypp::filesystem::Pathname::Pathname
Pathname()
Default ctor: an empty path.
Definition Pathname.h:50
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition Pathname.h:112
zypp::filesystem::Pathname::Pathname
Pathname(const char *name_r)
Ctor from char*.
Definition Pathname.h:58
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition Pathname.h:93
zypp::filesystem::Pathname::basename
std::string basename() const
Return the last component of this path.
Definition Pathname.h:130
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:116
zypp::filesystem::Pathname::operator==
bool operator==(const Pathname &l, const Pathname &r)
Definition Pathname.h:185
zypp::filesystem::Pathname::_assign
void _assign(const std::string &name_r)
Definition Pathname.cc:33
zypp::filesystem::Pathname::operator=
Pathname & operator=(Pathname rhs)
Assign.
Definition Pathname.h:79
zypp::filesystem::Pathname::absolutename
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Definition Pathname.h:141
zypp::filesystem::Pathname::Pathname
Pathname(const std::string &name_r)
Ctor from string.
Definition Pathname.h:54
zypp::filesystem::Pathname::operator<
bool operator<(const Pathname &l, const Pathname &r)
Definition Pathname.h:203
zypp::filesystem::Pathname::operator/
Pathname operator/(const Pathname &l, const Pathname &r)
Concatenate two Pathname.
Definition Pathname.h:193
zypp::filesystem::Pathname::relativename
static Pathname relativename(const Pathname &name_r)
Definition Pathname.h:147
zypp::filesystem::Pathname::extension
std::string extension() const
Return all of the characters in name after and including the last dot in the last element of name.
Definition Pathname.h:137
zypp::filesystem::Pathname::_name
std::string _name
Definition Pathname.h:179
zypp::filesystem::Pathname::relative
bool relative() const
Test for a relative path.
Definition Pathname.h:120
str
String related utilities and Regular expression matching.
zypp::filesystem
Types and functions for filesystem operations.
Definition Glob.cc:24
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
Globals.h