diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2021-08-25 20:24:57 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-08-30 15:57:58 +0300 |
commit | 00a83b2ab6ca84776dfb5bec1679863c1896a813 (patch) | |
tree | 5d0e1a96fb5ab5ba1bb32620c1eb265fc519d122 /bpkg/database.hxx | |
parent | e30e71dee35d8e7b1a1c4759bc839533521033e8 (diff) |
Consider repository information from ultimate dependent databases rather then from just main database
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r-- | bpkg/database.hxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx index c7f059d..bc3ac08 100644 --- a/bpkg/database.hxx +++ b/bpkg/database.hxx @@ -662,6 +662,45 @@ namespace bpkg { return static_cast<bpkg::database&> (base_type::database ()); } + + // Map databases to values of arbitrary types. + // + // Note that keys are stored as non-constant references (since they are + // normally passed around as such), but they should never be changed + // directly. + // + template <typename V> + class database_map: + public small_vector<pair<reference_wrapper<database>, V>, 16> + { + public: + using value_type = pair<reference_wrapper<database>, V>; + using base_type = small_vector<value_type, 16>; + using iterator = typename base_type::iterator; + + using base_type::begin; + using base_type::end; + + iterator + find (database& db) + { + return find_if (begin (), end (), + [&db] (const value_type& i) -> bool + { + return i.first == db; + }); + } + + pair<iterator, bool> + insert (database& db, V&& v) + { + iterator i (find (db)); + if (i != end ()) + return make_pair (i, false); + + return make_pair (base_type::emplace (end (), db, move (v)), true); + } + }; } #endif // BPKG_DATABASE_HXX |