limal
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 LIMAL_PATH_PATHNAME_HPP
41 #define LIMAL_PATH_PATHNAME_HPP
42 
43 #include <limal/config.h>
44 #include <blocxx/String.hpp>
45 #include <blocxx/List.hpp>
46 #include <iosfwd>
47 
48 
49 // -------------------------------------------------------------------
50 namespace LIMAL_NAMESPACE
51 {
52 namespace path
53 {
54 
55 // -------------------------------------------------------------------
63 class PathName
64 {
65 public:
66  typedef blocxx::List<blocxx::String> List;
67 
72  PathName();
73 
78  PathName(const PathName &path);
79 
87  PathName(const PathName::List &list);
88 
95  PathName(const blocxx::String &name);
102  PathName(const char *name);
103 
107  virtual ~PathName();
108 
116  PathName & operator= (const PathName &path);
117 
126  PathName & operator+=(const PathName &path);
127 
133  blocxx::String toString() const;
134 
146  PathName::List toList() const;
147 
157  blocxx::String prefix() const;
158 
164  bool empty() const;
165 
172  bool absolute() const;
173 
180  bool relative() const;
181 
195  PathName dirName() const;
196 
211  static PathName dirName(const PathName &path);
212 
224  blocxx::String baseName() const;
225 
240  static blocxx::String baseName(const PathName &path);
241 
252  PathName absoluteName() const;
253 
264  static PathName absoluteName(const PathName &path);
265 
276  PathName relativeName() const;
277 
288  static PathName relativeName(const PathName &path);
289 
308  PathName cat(const PathName &add) const;
309 
328  static PathName cat(const PathName &path,
329  const PathName &add);
349  PathName extend(const blocxx::String &ext) const;
350 
371  static PathName extend(const PathName &path,
372  const blocxx::String &ext);
373 
382  bool equal(const PathName &rpath) const;
383 
391  static bool equal(const PathName &lpath,
392  const PathName &rpath);
393 
394 protected:
406  void assign(const blocxx::String &path);
407 
418  void assign(const PathName::List &list);
419 
420 private:
425  size_t m_prefix;
426  blocxx::String m_name;
427 };
428 
429 
430 // -------------------------------------------------------------------
431 inline bool
432 operator==(const PathName &lname, const PathName &rname)
433 {
434  return PathName::equal( lname, rname);
435 }
436 
437 
438 // -------------------------------------------------------------------
439 inline bool
440 operator!=(const PathName &lname, const PathName &rname)
441 {
442  return !PathName::equal( lname, rname);
443 }
444 
445 
446 // -------------------------------------------------------------------
447 inline PathName
448 operator+ (const PathName &lname, const PathName &rname)
449 {
450  return PathName::cat( lname, rname);
451 }
452 
453 
454 // -------------------------------------------------------------------
455 extern std::ostream &
456 operator<<(std::ostream &ostr, const PathName &path);
457 
458 
459 // -------------------------------------------------------------------
460 } // End of namespace path
461 } // End of namespace LIMAL_NAMESPACE
462 
463 #endif // LIMAL_PATH_PATHNAME_HPP
464 // vim: set ts=8 sts=4 sw=4 ai et: