libzypp 17.37.17
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
22namespace zypp
23{
24
25 class Url;
26
28 namespace filesystem
29 {
30
32 //
33 // CLASS NAME : Pathname
34 //
47 {
48 public:
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
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
218
220} // namespace zypp
222#endif // ZYPP_PATHNAME_H
Url manipulation class.
Definition Url.h:93
Pathname relativename() const
Return this path, removing a leading '/' if absolute.
Definition Pathname.h:146
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
Definition Pathname.h:175
static Pathname extend(const Pathname &l, const std::string &r)
Pathname(const Pathname &rhs)
Copy Ctor.
Definition Pathname.h:62
std::ostream & operator<<(std::ostream &str, const Pathname &obj)
Stream output.
Definition Pathname.h:209
Pathname & operator/=(const Pathname &path_tv)
Concatenate and assign.
Definition Pathname.h:83
friend void swap(Pathname &lhs, Pathname &rhs) noexcept
Swap.
Definition Pathname.h:67
Pathname(Pathname &&tmp) noexcept
Move Ctor.
Definition Pathname.h:74
static Pathname absolutename(const Pathname &name_r)
Definition Pathname.h:142
Pathname & operator+=(const Pathname &path_tv)
Concatenate and assign.
Definition Pathname.h:89
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
bool emptyOrRoot() const
Test for "" or "/".
Definition Pathname.h:123
bool absolute() const
Test for an absolute path.
Definition Pathname.h:118
Pathname operator+(const Pathname &l, const Pathname &r)
Concatenate two Pathname.
Definition Pathname.h:199
bool operator!=(const Pathname &l, const Pathname &r)
Definition Pathname.h:189
Pathname cat(const Pathname &r) const
Concatenation of pathnames.
Definition Pathname.h:167
Pathname()
Default ctor: an empty path.
Definition Pathname.h:50
const char * c_str() const
String representation.
Definition Pathname.h:112
Pathname(const char *name_r)
Ctor from char*.
Definition Pathname.h:58
const std::string & asString() const
String representation.
Definition Pathname.h:93
std::string basename() const
Return the last component of this path.
Definition Pathname.h:130
bool empty() const
Test for an empty path.
Definition Pathname.h:116
bool operator==(const Pathname &l, const Pathname &r)
Definition Pathname.h:185
void _assign(const std::string &name_r)
Definition Pathname.cc:33
Pathname & operator=(Pathname rhs)
Assign.
Definition Pathname.h:79
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Definition Pathname.h:141
Pathname(const std::string &name_r)
Ctor from string.
Definition Pathname.h:54
bool operator<(const Pathname &l, const Pathname &r)
Definition Pathname.h:203
Pathname operator/(const Pathname &l, const Pathname &r)
Concatenate two Pathname.
Definition Pathname.h:193
static Pathname relativename(const Pathname &name_r)
Definition Pathname.h:147
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
bool relative() const
Test for a relative path.
Definition Pathname.h:120
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
Definition Glob.cc:24
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247