diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2021-04-22 21:57:13 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-07-01 11:19:12 +0300 |
commit | d77ca8720df495017139a24a59c502f53c07df9f (patch) | |
tree | 5093b9700607e0db35d6260ad766e7f171e2bf8f /bpkg/types.hxx | |
parent | aee787bce2b94a057ad8e6fd42e2cd901776e348 (diff) |
Add support for associated configurations
Diffstat (limited to 'bpkg/types.hxx')
-rw-r--r-- | bpkg/types.hxx | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/bpkg/types.hxx b/bpkg/types.hxx index 65dba60..7d8740f 100644 --- a/bpkg/types.hxx +++ b/bpkg/types.hxx @@ -23,6 +23,8 @@ #include <libbutl/url.mxx> #include <libbutl/path.mxx> +#include <libbutl/uuid.hxx> +#include <libbutl/uuid-io.hxx> #include <libbutl/process.mxx> #include <libbutl/utility.mxx> // 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; - // <libbutl/path.mxx> // using butl::path; @@ -92,6 +89,10 @@ namespace bpkg using butl::basic_path; using butl::invalid_path; + // <libbutl/uuid.mxx> + // + using butl::uuid; + using butl::path_cast; using paths = std::vector<path>; @@ -123,6 +124,60 @@ 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 T> + class lazy_shared_ptr: public odb::lazy_shared_ptr<T> + { + public: + using base_type = odb::lazy_shared_ptr<T>; + + 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 T> + class lazy_weak_ptr: public odb::lazy_weak_ptr<T> + { + public: + using base_type = odb::lazy_weak_ptr<T>; + + using base_type::base_type; + + bpkg::database& + database () const; + + lazy_shared_ptr<T> + lock () const + { + return lazy_shared_ptr<T> (base_type::lock ()); + } + }; + + // Compare two lazy pointers via the pointed-to object ids. + // + struct compare_lazy_ptr + { + template <typename P> + 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 |