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.
24 As a special case, calling the constructor with no arguments or with an empty
25 string will construct an empty path; this can be usedful as an invalid value.
27 A path can also be treated as an array of components, supporting indexing,
28 iteration and slicing. In this context the root directory is treated as a
34 typedef std::vector<std::string::size_type> PositionArray;
41 PositionArray::const_iterator iter;
44 Iterator(const Path &, bool = false);
46 static Iterator at_begin(const Path &p) { return Iterator(p); }
47 static Iterator at_end(const Path &p) { return Iterator(p, true); }
49 Iterator &operator++();
50 Iterator &operator--();
51 std::string operator*() const;
52 bool operator==(const Iterator &i) const { return (iter==i.iter && end==i.end); }
53 bool operator!=(const Iterator &i) const { return !(*this==i); }
58 std::vector<std::string::size_type> separators;
62 Path(const std::string &);
65 void init(const std::string &);
68 /// Returns the path as a string.
69 const std::string &str() const { return path; }
71 /// Returns the number of components in the path.
72 unsigned size() const;
74 /** Indicates whether the path is empty. This really means empty; a path
75 pointing to the current directory is not empty. */
76 bool empty() const { return path.empty(); }
78 /// Determines whether the path starts from the root directory.
79 bool is_absolute() const;
81 /// Extracts a range of components from the path.
82 Path subpath(unsigned start, unsigned count = static_cast<unsigned>(-1)) const;
84 /// Concatenates this path with another one, with usual filesystem semantics.
85 Path operator/(const Path &p) const;
86 Path &operator/=(const Path &);
89 /** Adds a component to the path. It must not contain the directory
90 separator character. */
91 void add_component(const std::string &);
94 /** Extracts a single component from the path. Negative indices count from
95 the end of the path. */
96 std::string operator[](int) const;
98 bool operator==(const Path &) const;
99 bool operator<(const Path &) const;
100 bool operator>(const Path &) const;
101 bool operator<=(const Path &other) const { return !(*this>other); }
102 bool operator>=(const Path &other) const { return !(*this<other); }
103 bool operator!=(const Path &other) const { return !(*this==other); }
105 Iterator begin() const { return Iterator::at_begin(*this); }
106 Iterator end() const { return Iterator::at_end(*this); }
109 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }