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;
40 typedef PositionArray::difference_type difference_type;
41 typedef const std::string value_type;
42 typedef const std::string *pointer;
43 typedef const std::string &reference;
44 typedef std::input_iterator_tag iterator_category;
48 PositionArray::const_iterator iter;
52 Iterator(const Path &, bool = false);
54 static Iterator at_begin(const Path &p) { return Iterator(p); }
55 static Iterator at_end(const Path &p) { return Iterator(p, true); }
57 Iterator &operator++();
58 Iterator operator++(int) { Iterator i = *this; ++*this; return i; }
59 Iterator &operator--();
60 const std::string &operator*() const { return current; }
61 const std::string *operator->() const { return ¤t; }
62 bool operator==(const Iterator &i) const { return (iter==i.iter && end==i.end); }
63 bool operator!=(const Iterator &i) const { return !(*this==i); }
70 std::vector<std::string::size_type> separators;
74 Path(const std::string &);
77 void init(const std::string &);
80 /// Returns the path as a string.
81 const std::string &str() const { return path; }
83 /// Returns the path as a pointer to a null-terminated string.
84 const char *c_str() const { return path.c_str(); }
86 /// Returns the number of components in the path.
87 unsigned size() const;
89 /** Indicates whether the path is empty. This really means empty; a path
90 pointing to the current directory is not empty. */
91 bool empty() const { return path.empty(); }
93 /// Determines whether the path starts from the root directory.
94 bool is_absolute() const;
96 /// Extracts a range of components from the path.
97 Path subpath(unsigned start, unsigned count = static_cast<unsigned>(-1)) const;
99 /// Concatenates this path with another one, with usual filesystem semantics.
100 Path operator/(const Path &p) const;
101 Path &operator/=(const Path &);
104 /** Adds a component to the path. It must not contain the directory
105 separator character. */
106 void add_component(const std::string &);
109 /** Extracts a single component from the path. Negative indices count from
110 the end of the path. */
111 std::string operator[](int) const;
113 bool operator==(const Path &) const;
114 bool operator<(const Path &) const;
115 bool operator>(const Path &) const;
116 bool operator<=(const Path &other) const { return !(*this>other); }
117 bool operator>=(const Path &other) const { return !(*this<other); }
118 bool operator!=(const Path &other) const { return !(*this==other); }
120 Iterator begin() const { return Iterator::at_begin(*this); }
121 Iterator end() const { return Iterator::at_end(*this); }
124 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }