21 Stores a filesystem path. Paths are always stored in a normalized form; there
22 are never any "." or ".." components in the middle of the path, and relative
23 paths always begin with a single "." component or a sequence ".." components.
28 typedef std::vector<std::string::size_type> PositionArray;
35 PositionArray::const_iterator iter;
38 Iterator(const Path &, bool = false);
40 static Iterator at_begin(const Path &p) { return Iterator(p); }
41 static Iterator at_end(const Path &p) { return Iterator(p, true); }
43 Iterator &operator++();
44 Iterator &operator--();
45 std::string operator*() const;
46 bool operator==(const Iterator &i) const { return (iter==i.iter && end==i.end); }
47 bool operator!=(const Iterator &i) const { return !(*this==i); }
52 std::vector<std::string::size_type> separators;
56 Path(const std::string &);
59 void init(const std::string &);
62 const std::string &str() const { return path; }
64 /// Returns the number of components in the path.
65 unsigned size() const;
67 bool empty() const { return path.empty(); }
69 /// Determines whether the path starts from the root directory
70 bool is_absolute() const;
72 /// Extracts a range of components from the path.
73 Path subpath(unsigned start, unsigned count = static_cast<unsigned>(-1)) const;
75 /// Concatenates this path with another one, with usual filesystem semantics
76 Path operator/(const Path &p) const;
77 Path &operator/=(const Path &);
80 /** Adds a component to the path. It must not contain the directory
81 separator character. */
82 void add_component(const std::string &);
85 /** Extracts a single component from the path. Negative indices count from
86 the end of the path. */
87 std::string operator[](int) const;
89 bool operator==(const Path &) const;
90 bool operator<(const Path &) const;
91 bool operator>(const Path &) const;
92 bool operator<=(const Path &other) const { return !(*this>other); }
93 bool operator>=(const Path &other) const { return !(*this<other); }
94 bool operator!=(const Path &other) const { return !(*this==other); }
96 Iterator begin() const { return Iterator::at_begin(*this); }
97 Iterator end() const { return Iterator::at_end(*this); }
100 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }