From fa313152767ae60941987450268f9562e1d59d42 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 8 Nov 2019 00:17:11 +0300 Subject: Add path_name_value struct --- libbutl/path.mxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'libbutl/path.mxx') 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 struct basic_path_name; using path_name = basic_path_name; using dir_path_name = basic_path_name; + // The copying version of the above that derives from the view (and thus can + // be passed down as a view). + // + template + struct basic_path_name_value; + + using path_name_value = basic_path_name_value; + using dir_name_value = basic_path_name_value; + // 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 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 + struct basic_path_name_value: basic_path_name

+ { + using base = basic_path_name

; + + using path_type = typename base::path_type; + using string_type = typename base::string_type; + + explicit + basic_path_name_value (path_type p, optional 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 + inline bool + operator< (const basic_path_name_value

& x, + const basic_path_name_value

& y) + { + return x.compare (y) < 0; + } } LIBBUTL_MODEXPORT namespace std -- cgit v1.1