From 00a83b2ab6ca84776dfb5bec1679863c1896a813 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 25 Aug 2021 20:24:57 +0300 Subject: Consider repository information from ultimate dependent databases rather then from just main database --- bpkg/database.hxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'bpkg/database.hxx') 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 (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 + class database_map: + public small_vector, V>, 16> + { + public: + using value_type = pair, V>; + using base_type = small_vector; + 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 + 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 -- cgit v1.1