]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/path.h
Store an array of separators alongside with the path string
[libs/core.git] / source / fs / path.h
index d515d7817031c1df3f98d0ad459c92a597b0dbcc..9bc93f6c003eab2db5a695c2a312c9b1db1fc4c8 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <ostream>
 #include <string>
+#include <vector>
 
 namespace Msp {
 namespace FS {
@@ -23,26 +24,32 @@ paths always begin with a single "." component or a sequence ".." components.
 */
 class Path
 {
+private:
+       typedef std::vector<std::string::size_type> PositionArray;
+
 public:
        class Iterator
        {
-               friend class Path;
-
        private:
                const Path *path;
-               std::string::size_type start, end;
+               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<std::string::size_type> separators;
 
 public:
        Path();
@@ -86,8 +93,8 @@ public:
        bool operator>=(const Path &other) const { return !(*this<other); }
        bool operator!=(const Path &other) const { return !(*this==other); }
 
-       Iterator begin() const;
-       Iterator end() const;
+       Iterator begin() const { return Iterator::at_begin(*this); }
+       Iterator end() const { return Iterator::at_end(*this); }
 };
 
 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }