X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffs%2Fpath.h;h=1b15047cc528ece01f9d2061fcd0fd3740dedfef;hb=5d3a5019399f97af0371f4fd6dc415d36de6ac3a;hp=210b5d93d14c88bf136d07f25a5ddc78c7fc89e2;hpb=6c958cd2d8806063580f836e4c3d486832af9635;p=libs%2Fcore.git diff --git a/source/fs/path.h b/source/fs/path.h index 210b5d9..1b15047 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -4,13 +4,14 @@ #include #include #include +#include namespace Msp { namespace FS { enum { -#ifdef WIN32 +#ifdef _WIN32 DIRSEP = '\\' #else DIRSEP = '/' @@ -28,18 +29,26 @@ 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 +class MSPCORE_API Path { private: typedef std::vector PositionArray; public: - class Iterator + class MSPCORE_API Iterator { + public: + typedef PositionArray::difference_type difference_type; + typedef const std::string value_type; + typedef const std::string *pointer; + typedef const std::string &reference; + typedef std::input_iterator_tag iterator_category; + private: const Path *path; PositionArray::const_iterator iter; bool end; + std::string current; Iterator(const Path &, bool = false); public: @@ -47,27 +56,31 @@ public: static Iterator at_end(const Path &p) { return Iterator(p, true); } Iterator &operator++(); + Iterator operator++(int) { Iterator i = *this; ++*this; return i; } Iterator &operator--(); - std::string operator*() const; + const std::string &operator*() const { return current; } + const std::string *operator->() const { return ¤t; } bool operator==(const Iterator &i) const { return (iter==i.iter && end==i.end); } bool operator!=(const Iterator &i) const { return !(*this==i); } + private: + void update(); }; private: std::string path; - std::vector separators; + PositionArray separators; public: - Path(); + Path() = default; Path(const std::string &); - Path(const char *); -private: - void init(const std::string &); + Path(const char *p): Path(std::string(p)) { } -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;