X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fpath.h;h=9bc93f6c003eab2db5a695c2a312c9b1db1fc4c8;hp=ed9cc7985b62d863f86a6bc19726de692791d077;hb=05f7e9b4c6f804102f261517c8ecdd338e1f67d3;hpb=e1452710edb6b1d0ebceb4b9273dae4b2f899630 diff --git a/source/fs/path.h b/source/fs/path.h index ed9cc79..9bc93f6 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -3,6 +3,7 @@ #include #include +#include namespace Msp { namespace FS { @@ -23,32 +24,41 @@ 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: + 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 (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. @@ -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. - */ +private: + /** 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; - Iterator begin() const; - Iterator end() const; -private: - void init(const std::string &); - void add_component(const std::string &); + 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