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 PositionArray separators;
74 Path(const std::string &);
75 Path(const char *p): Path(std::string(p)) { }
77 /// Returns the path as a string.
78 const std::string &str() const { return path; }
80 /// Returns the path as a pointer to a null-terminated string.
81 const char *c_str() const { return path.c_str(); }
83 /// Returns the number of components in the path.
84 unsigned size() const;
86 /** Indicates whether the path is empty. This really means empty; a path
87 pointing to the current directory is not empty. */
88 bool empty() const { return path.empty(); }
90 /// Determines whether the path starts from the root directory.
91 bool is_absolute() const;
93 /// Extracts a range of components from the path.
94 Path subpath(unsigned start, unsigned count = static_cast<unsigned>(-1)) const;
96 /// Concatenates this path with another one, with usual filesystem semantics.
97 Path operator/(const Path &p) const;
98 Path &operator/=(const Path &);
101 /** Adds a component to the path. It must not contain the directory
102 separator character. */
103 void add_component(const std::string &);
106 /** Extracts a single component from the path. Negative indices count from
107 the end of the path. */
108 std::string operator[](int) const;
110 bool operator==(const Path &) const;
111 bool operator<(const Path &) const;
112 bool operator>(const Path &) const;
113 bool operator<=(const Path &other) const { return !(*this>other); }
114 bool operator>=(const Path &other) const { return !(*this<other); }
115 bool operator!=(const Path &other) const { return !(*this==other); }
117 Iterator begin() const { return Iterator::at_begin(*this); }
118 Iterator end() const { return Iterator::at_end(*this); }
121 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }