libzypp  17.35.12
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  //
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  };
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
Pathname(const std::string &name_r)
Ctor from string.
Definition: Pathname.h:54
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
Definition: Pathname.h:175
const char * c_str() const
String representation.
Definition: Pathname.h:112
String related utilities and Regular expression matching.
std::string basename() const
Return the last component of this path.
Definition: Pathname.h:130
Pathname & operator+=(const Pathname &path_tv)
Concatenate and assign.
Definition: Pathname.h:89
Pathname(Pathname &&tmp) noexcept
Move Ctor.
Definition: Pathname.h:74
Pathname operator/(const Pathname &l, const Pathname &r)
Definition: Pathname.h:193
bool emptyOrRoot() const
Test for "" or "/".
Definition: Pathname.h:123
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
Pathname & operator=(Pathname rhs)
Assign.
Definition: Pathname.h:79
bool operator<(const Pathname &l, const Pathname &r)
Definition: Pathname.h:203
const std::string & asString() const
String representation.
Definition: Pathname.h:93
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Pathname(const char *name_r)
Ctor from char*.
Definition: Pathname.h:58
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:126
Pathname relativename() const
Return this path, removing a leading &#39;/&#39; if absolute.
Definition: Pathname.h:146
Pathname()
Default ctor: an empty path.
Definition: Pathname.h:50
bool absolute() const
Test for an absolute path.
Definition: Pathname.h:118
bool operator!=(const Pathname &l, const Pathname &r)
Definition: Pathname.h:189
Pathname(const Pathname &rhs)
Copy Ctor.
Definition: Pathname.h:62
zypp::Url Url
Definition: url.h:15
std::ostream & operator<<(std::ostream &str, const Pathname &obj)
Definition: Pathname.h:209
Pathname operator+(const Pathname &l, const Pathname &r)
Definition: Pathname.h:199
bool operator==(const Pathname &l, const Pathname &r)
Definition: Pathname.h:185
static Pathname relativename(const Pathname &name_r)
Definition: Pathname.h:147
Pathname absolutename() const
Return this path, adding a leading &#39;/&#39; if relative.
Definition: Pathname.h:141
friend void swap(Pathname &lhs, Pathname &rhs) noexcept
Swap.
Definition: Pathname.h:67
Pathname & operator/=(const Pathname &path_tv)
Concatenate and assign.
Definition: Pathname.h:83
static Pathname absolutename(const Pathname &name_r)
Definition: Pathname.h:142
bool relative() const
Test for a relative path.
Definition: Pathname.h:120
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Pathname cat(const Pathname &r) const
Concatenation of pathnames.
Definition: Pathname.h:167
Url manipulation class.
Definition: Url.h:91
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