]> git.tdb.fi Git - libs/core.git/blob - source/path.h
Add files
[libs/core.git] / source / path.h
1 #ifndef MSP_PATH_PATH_H_
2 #define MSP_PATH_PATH_H_
3
4 #include <ostream>
5 #include <string>
6
7 namespace Msp {
8 namespace Path {
9
10 enum
11 {
12 #ifdef WIN32
13         DIRCHAR='\\'
14 #else
15         DIRCHAR='/'
16 #endif
17 };
18
19 class Path
20 {
21 public:
22         class iterator
23         {
24         public:
25                 iterator    &operator++();
26                 iterator    &operator--();
27                 std::string operator*() const;
28                 bool        operator==(const iterator &i) const { return (start==i.start && end==i.end); }
29                 bool        operator!=(const iterator &i) const { return !(*this==i); }
30         private:
31                 const Path &path;
32                 unsigned   start,end;
33
34                 iterator(const Path &);
35
36                 friend class Path;
37         };
38
39         Path() { }
40         Path(const std::string &p)     { init(p); }
41         Path(const char *p)            { init(p); }
42         const std::string &str() const { return path; }
43         unsigned  size() const;
44         bool        is_absolute() const;
45         Path        subpath(unsigned, unsigned =(unsigned)-1) const;
46         Path        operator/(const Path &p) const { Path a=*this; a/=p; return a; }
47         Path        &operator/=(const Path &);
48         std::string operator[](int) const;
49         bool        operator==(const Path &) const;
50         iterator    begin() const { return iterator(*this); }
51         iterator    end() const   { iterator i(*this); i.start=i.end=std::string::npos; return i; }
52 private:
53         std::string path;
54
55         void init(const std::string &);
56 };
57
58 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }
59
60 } // namespace Path
61 } // namespace Msp
62
63 #endif