yast2-core
Pathname.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12 
13  File: Pathname.h
14 
15  Author: Michael Andres <ma@suse.de>
16  Maintainer: Michael Andres <ma@suse.de>
17 
18 /-*/
19 #ifndef Pathname_h
20 #define Pathname_h
21 
22 #include <iosfwd>
23 #include <string>
24 
26 //
27 // CLASS NAME : Pathname
28 //
29 // DESCRIPTION :
30 //
31 class Pathname {
32 
33  private:
34 
35  std::string::size_type prfx_i;
36  std::string name_t;
37 
38  protected:
39 
40  void _assign( const std::string & name_tv );
41 
42  public:
43 
44  virtual ~Pathname() {}
45 
47  prfx_i = 0;
48  name_t = "";
49  }
50  Pathname( const Pathname & path_tv ) {
51  prfx_i = path_tv.prfx_i;
52  name_t = path_tv.name_t;
53  }
54  Pathname( const std::string & name_tv ) {
55  _assign( name_tv );
56  }
57  Pathname( const char * name_tv ) {
58  _assign( name_tv ? name_tv : "" );
59  }
60 
61  Pathname & operator= ( const Pathname & path_tv );
62  Pathname & operator+=( const Pathname & path_tv );
63 
64  const std::string & asString() const { return name_t; }
65 
66  bool empty() const { return !name_t.size(); }
67  bool absolute() const { return !empty() && name_t[prfx_i] == '/'; }
68  bool relative() const { return !empty() && name_t[prfx_i] != '/'; }
69 
70  Pathname dirname() const { return dirname( *this ); }
71  std::string basename() const { return basename( *this ); }
72  Pathname absolutename() const { return absolutename( *this ); }
73  Pathname relativename() const { return relativename( *this ); }
74 
75  static Pathname dirname ( const Pathname & name_tv );
76  static std::string basename ( const Pathname & name_tv );
77  static Pathname absolutename( const Pathname & name_tv ) { return name_tv.relative() ? cat( "/", name_tv ) : name_tv; }
78  static Pathname relativename( const Pathname & name_tv ) { return name_tv.absolute() ? cat( ".", name_tv ) : name_tv; }
79 
80  Pathname cat( const Pathname & r ) const { return cat( *this, r ); }
81  static Pathname cat( const Pathname & l, const Pathname & r );
82 
83  Pathname extend( const std::string & r ) const { return extend( *this, r ); }
84  static Pathname extend( const Pathname & l, const std::string & r );
85 
86  bool equal( const Pathname & r ) const { return equal( *this, r ); }
87  static bool equal( const Pathname & l, const Pathname & r );
88 };
89 
91 
92 inline bool operator==( const Pathname & l, const Pathname & r ) {
93  return Pathname::equal( l, r );
94 }
95 
96 inline bool operator!=( const Pathname & l, const Pathname & r ) {
97  return !Pathname::equal( l, r );
98 }
99 
100 inline Pathname operator+( const Pathname & l, const Pathname & r ) {
101  return Pathname::cat( l, r );
102 }
103 
104 inline Pathname & Pathname::operator=( const Pathname & path_tv ) {
105  if ( &path_tv != this ) {
106  prfx_i = path_tv.prfx_i;
107  name_t = path_tv.name_t;
108  }
109  return *this;
110 }
111 
112 inline Pathname & Pathname::operator+=( const Pathname & path_tv ) {
113  return( *this = *this + path_tv );
114 }
115 
117 
118 extern std::ostream & operator<<( std::ostream & str, const Pathname & obj );
119 
121 
122 #endif // Pathname_h
Pathname dirname() const
Definition: Pathname.h:70
static Pathname absolutename(const Pathname &name_tv)
Definition: Pathname.h:77
Pathname cat(const Pathname &r) const
Definition: Pathname.h:80
std::string basename() const
Definition: Pathname.h:71
std::ostream & operator<<(std::ostream &str, const Pathname &obj)
Definition: Pathname.cc:290
#define str
Definition: scanner.cc:997
Pathname & operator=(const Pathname &path_tv)
Definition: Pathname.h:104
Pathname extend(const std::string &r) const
Definition: Pathname.h:83
std::string name_t
Definition: Pathname.h:36
Definition: Pathname.h:31
bool operator==(const Pathname &l, const Pathname &r)
Definition: Pathname.h:92
Pathname()
Definition: Pathname.h:46
bool relative() const
Definition: Pathname.h:68
Pathname(const Pathname &path_tv)
Definition: Pathname.h:50
bool empty() const
Definition: Pathname.h:66
Pathname & operator+=(const Pathname &path_tv)
Definition: Pathname.h:112
std::string::size_type prfx_i
Definition: Pathname.h:35
Pathname absolutename() const
Definition: Pathname.h:72
Pathname(const std::string &name_tv)
Definition: Pathname.h:54
Pathname operator+(const Pathname &l, const Pathname &r)
Definition: Pathname.h:100
bool equal(const Pathname &r) const
Definition: Pathname.h:86
Pathname relativename() const
Definition: Pathname.h:73
Pathname(const char *name_tv)
Definition: Pathname.h:57
bool absolute() const
Definition: Pathname.h:67
void _assign(const std::string &name_tv)
Definition: Pathname.cc:128
virtual ~Pathname()
Definition: Pathname.h:44
static Pathname relativename(const Pathname &name_tv)
Definition: Pathname.h:78
bool operator!=(const Pathname &l, const Pathname &r)
Definition: Pathname.h:96
const std::string & asString() const
Definition: Pathname.h:64

Generated on a sunny day for yast2-core by doxygen 1.8.8