diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-10 15:33:18 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-10 15:33:18 +0200 |
commit | 49cd0e47d3783bcc31521a2425061ca7fae07363 (patch) | |
tree | 9b050bfd78b75490200cf2d4231820d104a813ff | |
parent | 02af7e788f3fef0dbba0ba49442054fb451f5bdc (diff) |
Implement path_cast(), path::simple()
-rw-r--r-- | butl/path | 25 | ||||
-rw-r--r-- | butl/path.ixx | 27 |
2 files changed, 52 insertions, 0 deletions
@@ -145,6 +145,12 @@ namespace butl template <typename C, typename K> class basic_path; + // Cast from one path kind to another without any checking or + // processing. + // + template <class P, class C, class K> P path_cast (const basic_path<C, K>&); + template <class P, class C, class K> P path_cast (basic_path<C, K>&&); + template <typename C> class path_data; @@ -278,6 +284,13 @@ namespace butl return this->path_.empty (); } + // Return true if this path doesn't have any directories. Note + // that "/foo" is not a simple path (it is "foo" in root directory) + // while "/" is (it is the root directory). + // + bool + simple () const; + bool absolute () const; @@ -497,6 +510,18 @@ namespace butl posix_string () const; private: + template <class P, class C1, class K1> + friend P butl::path_cast (const basic_path<C1, K1>&); + + template <class P, class C1, class K1> + friend P butl::path_cast (basic_path<C1, K1>&&); + + basic_path (string_type s, bool i): base_type (std::move (s)) + { + if (i) + init (); + } + void init (); }; diff --git a/butl/path.ixx b/butl/path.ixx index 0cbbeaf..3e8a9cc 100644 --- a/butl/path.ixx +++ b/butl/path.ixx @@ -25,6 +25,33 @@ namespace butl } #endif + // @@ Should only enable_if P is basic_path<C, K1>. + // + template <class P, class C, class K> + inline P + path_cast (const basic_path<C, K>& p) + { + return P (p.path_, false); + } + + template <class P, class C, class K> + inline P + path_cast (basic_path<C, K>&& p) + { + return P (std::move (p.path_), false); + } + + template <typename C, typename K> + inline bool basic_path<C, K>:: + simple () const + { + return +#ifndef _WIN32 + root () || +#endif + traits::find_separator (this->path_) == string_type::npos; + } + template <typename C, typename K> inline bool basic_path<C, K>:: absolute () const |