X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffs%2Fpath.h;h=5d0a5d353d4d465954b11ed9f7ff57a36aca5a5a;hb=7818b5ecb0a83126374896d7e678ca8aff9a1599;hp=9bc93f6c003eab2db5a695c2a312c9b1db1fc4c8;hpb=05f7e9b4c6f804102f261517c8ecdd338e1f67d3;p=libs%2Fcore.git diff --git a/source/fs/path.h b/source/fs/path.h index 9bc93f6..5d0a5d3 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -21,6 +21,12 @@ enum Stores a filesystem path. Paths are always stored in a normalized form; there are never any "." or ".." components in the middle of the path, and relative paths always begin with a single "." component or a sequence ".." components. +As a special case, calling the constructor with no arguments or with an empty +string will construct an empty path; this can be usedful as an invalid value. + +A path can also be treated as an array of components, supporting indexing, +iteration and slicing. In this context the root directory is treated as a +component of its own. */ class Path { @@ -59,20 +65,26 @@ private: void init(const std::string &); public: + /// Returns the path as a string. const std::string &str() const { return path; } + /// Returns the path as a pointer to a null-terminated string. + const char *c_str() const { return path.c_str(); } + /// Returns the number of components in the path. unsigned size() const; + /** Indicates whether the path is empty. This really means empty; a path + pointing to the current directory is not empty. */ bool empty() const { return path.empty(); } - /// Determines whether the path starts from the root directory + /// Determines whether the path starts from the root directory. bool is_absolute() const; /// Extracts a range of components from the path. Path subpath(unsigned start, unsigned count = static_cast(-1)) const; - /// Concatenates this path with another one, with usual filesystem semantics + /// Concatenates this path with another one, with usual filesystem semantics. Path operator/(const Path &p) const; Path &operator/=(const Path &);