From 5d513688ae07d96910dd1eef83bdad4e9d780373 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 22 Apr 2021 21:57:13 +0300 Subject: Add support for linked configurations --- bpkg/types.hxx | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'bpkg/types.hxx') diff --git a/bpkg/types.hxx b/bpkg/types.hxx index 65dba60..1c6e89b 100644 --- a/bpkg/types.hxx +++ b/bpkg/types.hxx @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include // icase_compare_string, // compare_reference_target @@ -80,11 +82,6 @@ namespace bpkg using butl::optional; using butl::nullopt; - // ODB smart pointers. - // - using odb::lazy_shared_ptr; - using odb::lazy_weak_ptr; - // // using butl::path; @@ -92,6 +89,10 @@ namespace bpkg using butl::basic_path; using butl::invalid_path; + // + // + using butl::uuid; + using butl::path_cast; using paths = std::vector; @@ -123,6 +124,75 @@ namespace bpkg using butl::default_options_files; using butl::default_options_entry; using butl::default_options; + + // Derive from ODB smart pointers to return derived database (note that the + // database() functions are defined in database.hxx). + // + class database; + + template + class lazy_shared_ptr: public odb::lazy_shared_ptr + { + public: + using base_type = odb::lazy_shared_ptr; + + using base_type::base_type; + + explicit + lazy_shared_ptr (base_type&& p): base_type (move (p)) {} + + lazy_shared_ptr () = default; + + bpkg::database& + database () const; + }; + + template + class lazy_weak_ptr: public odb::lazy_weak_ptr + { + public: + using base_type = odb::lazy_weak_ptr; + + using base_type::base_type; + + bpkg::database& + database () const; + + lazy_shared_ptr + lock () const + { + return lazy_shared_ptr (base_type::lock ()); + } + }; + + struct compare_lazy_ptr + { + template + bool + operator() (const P& x, const P& y) const + { + // See operator==(database, database). + // + return x.object_id () != y.object_id () + ? (x.object_id () < y.object_id ()) + : (&static_cast (x).database () < + &static_cast (y).database ()); + } + }; + + // Compare two lazy pointers via the pointed-to object ids. + // + struct compare_lazy_ptr_id + { + template + bool + operator() (const P& x, const P& y) const + { + // Note: ignoring database is intentional. + // + return x.object_id () < y.object_id (); + } + }; } // In order to be found (via ADL) these have to be either in std:: or in -- cgit v1.1