]> git.tdb.fi Git - libs/core.git/blobdiff - source/path.h
Split directory and stat related functions into their own files
[libs/core.git] / source / path.h
index 511d5e02ff403ed23f7212f5497316b1278836c2..082a1bae97c1f0e4a0b7d1e3e083ea74cf0da157 100644 (file)
@@ -1,11 +1,18 @@
-#ifndef MSP_PATH_PATH_H_
-#define MSP_PATH_PATH_H_
+/* $Id$
+
+This file is part of libmspfs
+Copyright © 2006-2008  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_FS_PATH_H_
+#define MSP_FS_PATH_H_
 
 #include <ostream>
 #include <string>
 
 namespace Msp {
-namespace Path {
+namespace FS {
 
 enum
 {
@@ -19,19 +26,19 @@ enum
 class Path
 {
 public:
-       class iterator
+       class Iterator
        {
        public:
-               iterator    &operator++();
-               iterator    &operator--();
+               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 (start==i.start && end==i.end); }
+               bool        operator!=(const Iterator &i) const { return !(*this==i); }
        private:
                const Path &path;
                unsigned   start,end;
 
-               iterator(const Path &);
+               Iterator(const Path &);
 
                friend class Path;
        };
@@ -40,24 +47,26 @@ public:
        Path(const std::string &p)     { init(p); }
        Path(const char *p)            { init(p); }
        const std::string &str() const { return path; }
-       unsigned  size() const;
+       unsigned    size() const;
+       bool        empty() const { return path.empty(); }
        bool        is_absolute() const;
-       Path        subpath(unsigned, unsigned =(unsigned)-1) const;
+       Path        subpath(unsigned, unsigned =static_cast<unsigned>(-1)) const;
        Path        operator/(const Path &p) const { Path a=*this; a/=p; return a; }
        Path        &operator/=(const Path &);
        std::string operator[](int) const;
        bool        operator==(const Path &) const;
-       iterator    begin() const { return iterator(*this); }
-       iterator    end() const   { iterator i(*this); i.start=i.end=std::string::npos; return i; }
+       Iterator    begin() const { return Iterator(*this); }
+       Iterator    end() const   { Iterator i(*this); i.start=i.end=std::string::npos; return i; }
 private:
        std::string path;
 
        void init(const std::string &);
+       void add_component(const std::string &);
 };
 
 inline std::ostream &operator<<(std::ostream &o, const Path &p) { o<<p.str(); return o; }
 
-} // namespace Path
+} // namespace FS
 } // namespace Msp
 
 #endif