X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ffs%2Fpath.h;h=9bc93f6c003eab2db5a695c2a312c9b1db1fc4c8;hb=05f7e9b4c6f804102f261517c8ecdd338e1f67d3;hp=749578a8797cf519695d0e9b321819987aa76521;hpb=7563bb650aa11207a7c128ba44468cf5ad2897c7;p=libs%2Fcore.git diff --git a/source/fs/path.h b/source/fs/path.h index 749578a..9bc93f6 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -3,6 +3,7 @@ #include #include +#include namespace Msp { namespace FS { @@ -23,38 +24,47 @@ paths always begin with a single "." component or a sequence ".." components. */ class Path { +private: + typedef std::vector PositionArray; + public: class Iterator { - friend class Path; - private: - const Path &path; - std::string::size_type start,end; + const Path *path; + PositionArray::const_iterator iter; + bool end; - Iterator(const Path &); + Iterator(const Path &, bool = false); public: - Iterator &operator++(); - Iterator &operator--(); + static Iterator at_begin(const Path &p) { return Iterator(p); } + static Iterator at_end(const Path &p) { return Iterator(p, true); } + + Iterator &operator++(); + Iterator &operator--(); std::string operator*() const; - bool operator==(const Iterator &i) const { return (start==i.start && end==i.end); } - bool operator!=(const Iterator &i) const { return !(*this==i); } + bool operator==(const Iterator &i) const { return (iter==i.iter && end==i.end); } + bool operator!=(const Iterator &i) const { return !(*this==i); } }; private: std::string path; + std::vector separators; public: Path(); Path(const std::string &); Path(const char *); +private: + void init(const std::string &); +public: const std::string &str() const { return path; } /// Returns the number of components in the path. - unsigned size() const; + unsigned size() const; - bool empty() const { return path.empty(); } + bool empty() const { return path.empty(); } /// Determines whether the path starts from the root directory bool is_absolute() const; @@ -66,18 +76,25 @@ public: Path operator/(const Path &p) const; Path &operator/=(const Path &); - /** - Extracts a single component from the path. Negative indices count from the - end of the path. - */ - std::string operator[](int) const; - - bool operator==(const Path &) const; - Iterator begin() const; - Iterator end() const; private: - void init(const std::string &); + /** Adds a component to the path. It must not contain the directory + separator character. */ void add_component(const std::string &); + +public: + /** Extracts a single component from the path. Negative indices count from + the end of the path. */ + std::string operator[](int) const; + + bool operator==(const Path &) const; + bool operator<(const Path &) const; + bool operator>(const Path &) const; + bool operator<=(const Path &other) const { return !(*this>other); } + bool operator>=(const Path &other) const { return !(*this