libcamgm
PathName.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | _ _ _ _ __ _ |
4 | | | | | | \_/ | / \ | | |
5 | | | | | | |_| | / /\ \ | | |
6 | | |__ | | | | | | / ____ \ | |__ |
7 | |____||_| |_| |_|/ / \ \|____| |
8 | |
9 | core library |
10 | |
11 | (C) SUSE Linux Products GmbH |
12 \----------------------------------------------------------------------/
13 
14  File: PathName.hpp
15 
16  Maintainer: Michael Calmer
17 
18 /----------------------------------------------------------------------\
19 | |
20 | __ __ ____ _____ ____ |
21 | \ \ / /_ _/ ___|_ _|___ \ |
22 | \ V / _` \___ \ | | __) | |
23 | | | (_| |___) || | / __/ |
24 | |_|\__,_|____/ |_| |_____| |
25 | |
26 | core system |
27 | (C) SuSE GmbH |
28 \----------------------------------------------------------------------/
29 
30  File: Pathname.h
31 
32  Author: Michael Andres <ma@suse.de>
33  Maintainer: Michael Andres <ma@suse.de>
34 
35 /-*/
40 #ifndef CA_MGM_PATH_PATHNAME_HPP
41 #define CA_MGM_PATH_PATHNAME_HPP
42 
43 #include <ca-mgm/config.h>
44 #include <ca-mgm/String.hpp>
45 #include <list>
46 #include <iosfwd>
47 
48 #define FILENAME_SEPARATOR "/"
49 #define FILENAME_SEPARATOR_C '/'
50 
51 // -------------------------------------------------------------------
52 namespace CA_MGM_NAMESPACE
53 {
54 namespace path
55 {
56 
57 // -------------------------------------------------------------------
65 class PathName
66 {
67 public:
68  typedef std::list<std::string> List;
69 
74  PathName();
75 
80  PathName(const PathName &path);
81 
89  PathName(const PathName::List &list);
90 
97  PathName(const std::string &name);
104  PathName(const char *name);
105 
109  virtual ~PathName();
110 
118  PathName & operator= (const PathName &path);
119 
128  PathName & operator+=(const PathName &path);
129 
135  std::string toString() const;
136  std::string asString() const { return toString(); }
137 
149  PathName::List toList() const;
150 
160  std::string prefix() const;
161 
167  bool empty() const;
168 
175  bool absolute() const;
176 
183  bool relative() const;
184 
198  PathName dirName() const;
199 
214  static PathName dirName(const PathName &path);
215 
227  std::string baseName() const;
228 
243  static std::string baseName(const PathName &path);
244 
255  PathName absoluteName() const;
256 
267  static PathName absoluteName(const PathName &path);
268 
279  PathName relativeName() const;
280 
291  static PathName relativeName(const PathName &path);
292 
311  PathName cat(const PathName &add) const;
312 
331  static PathName cat(const PathName &path,
332  const PathName &add);
352  PathName extend(const std::string &ext) const;
353 
374  static PathName extend(const PathName &path,
375  const std::string &ext);
376 
385  bool equal(const PathName &rpath) const;
386 
394  static bool equal(const PathName &lpath,
395  const PathName &rpath);
396 
397 protected:
409  void assign(const std::string &path);
410 
421  void assign(const PathName::List &list);
422 
423 private:
428  size_t m_prefix;
429  std::string m_name;
430 };
431 
432 
433 // -------------------------------------------------------------------
434 inline bool
435 operator==(const PathName &lname, const PathName &rname)
436 {
437  return PathName::equal( lname, rname);
438 }
439 
440 
441 // -------------------------------------------------------------------
442 inline bool
443 operator!=(const PathName &lname, const PathName &rname)
444 {
445  return !PathName::equal( lname, rname);
446 }
447 
448 
449 // -------------------------------------------------------------------
450 inline PathName
451 operator+ (const PathName &lname, const PathName &rname)
452 {
453  return PathName::cat( lname, rname);
454 }
455 
456 
457 // -------------------------------------------------------------------
458 extern std::ostream &
459 operator<<(std::ostream &ostr, const PathName &path);
460 
461 
462 // -------------------------------------------------------------------
463 } // End of namespace path
464 } // End of namespace CA_MGM_NAMESPACE
465 
466 #endif // CA_MGM_PATH_PATHNAME_HPP
467 // vim: set ts=8 sts=4 sw=4 ai et:
PathName operator+(const PathName &lname, const PathName &rname)
Definition: PathName.hpp:451
PathName manipulation class.
Definition: PathName.hpp:65
bool operator!=(const PathName &lname, const PathName &rname)
Definition: PathName.hpp:443
std::string toString(bool b)
Definition: String.hpp:125
size_t m_prefix
holds index of first character in the path string after an (optional) drive letter.
Definition: PathName.hpp:428
std::string asString() const
Definition: PathName.hpp:136
std::ostream & operator<<(std::ostream &ostr, const PathName &path)
std::list< std::string > List
Definition: PathName.hpp:68
std::string m_name
Definition: PathName.hpp:429
bool operator==(const PathName &lname, const PathName &rname)
Definition: PathName.hpp:435