aboutsummaryrefslogtreecommitdiff
path: root/libbutl/path.mxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-11-08 00:17:11 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-11-11 17:39:25 +0300
commitfa313152767ae60941987450268f9562e1d59d42 (patch)
treebebc5c315c8c394f064f47067915812b177e4d7d /libbutl/path.mxx
parent23d4deb111bfff9c282c20989573c4b0775e4c16 (diff)
Add path_name_value struct
Diffstat (limited to 'libbutl/path.mxx')
-rw-r--r--libbutl/path.mxx55
1 files changed, 52 insertions, 3 deletions
diff --git a/libbutl/path.mxx b/libbutl/path.mxx
index 1d0ada9..2374fb5 100644
--- a/libbutl/path.mxx
+++ b/libbutl/path.mxx
@@ -536,15 +536,21 @@ LIBBUTL_MODEXPORT namespace butl
// that this is a view-like type with the original path shallow-referenced
// rather than copied.
//
- // Note: we could also have a copying version that derives from the view
- // (and thus can be passed down as a view).
- //
template <typename P>
struct basic_path_name;
using path_name = basic_path_name<path>;
using dir_path_name = basic_path_name<dir_path>;
+ // The copying version of the above that derives from the view (and thus can
+ // be passed down as a view).
+ //
+ template <typename P>
+ struct basic_path_name_value;
+
+ using path_name_value = basic_path_name_value<path>;
+ using dir_name_value = basic_path_name_value<dir_path>;
+
// Low-level path data storage. It is also used by the implementation to
// pass around initialized/valid paths.
//
@@ -1359,9 +1365,52 @@ LIBBUTL_MODEXPORT namespace butl
explicit
basic_path_name (const path_type* p, optional<string_type> n = nullopt)
: path (p), name (std::move (n)) {}
+
+ basic_path_name (): path (nullptr) {} // Create empty/NULL path name.
+
+ bool
+ empty () const {return path == nullptr && !name;}
};
// For operator<< (ostream) see the path-io header.
+
+ template <typename P>
+ struct basic_path_name_value: basic_path_name<P>
+ {
+ using base = basic_path_name<P>;
+
+ using path_type = typename base::path_type;
+ using string_type = typename base::string_type;
+
+ explicit
+ basic_path_name_value (path_type p, optional<string_type> n = nullopt)
+ : base (&path_, std::move (n)), path_ (std::move (p)) {}
+
+ int
+ compare (const basic_path_name_value& x) const
+ {
+ if (int r = path_.compare (x.path_))
+ return r;
+
+ return this->name < x.name ? -1 : this->name > x.name ? 1 : 0;
+ }
+
+ basic_path_name_value (basic_path_name_value&&);
+ basic_path_name_value (const basic_path_name_value&);
+ basic_path_name_value& operator= (basic_path_name_value&&);
+ basic_path_name_value& operator= (const basic_path_name_value&);
+
+ private:
+ P path_;
+ };
+
+ template <typename P>
+ inline bool
+ operator< (const basic_path_name_value<P>& x,
+ const basic_path_name_value<P>& y)
+ {
+ return x.compare (y) < 0;
+ }
}
LIBBUTL_MODEXPORT namespace std