diff options
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r-- | bpkg/database.hxx | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx index 889f8a0..035ff60 100644 --- a/bpkg/database.hxx +++ b/bpkg/database.hxx @@ -158,6 +158,9 @@ namespace bpkg // Move-constructible but not move-assignable. // + // Note: noexcept is not specified since + // odb::sqlite::database(odb::sqlite::database&&) can throw. + // database (database&&); database& operator= (database&&) = delete; @@ -214,7 +217,7 @@ namespace bpkg // // Note that we skip dangling links without any warning since they can be // quite common. Think of a shared host configuration with a bunch of - // implicitly linked configurations, which are removed and potentially + // implicitly linked configurations which are removed and potentially // recreated later during the host configuration lifetime. Note however, // that we remove the dangling implicit links during migration (see // migrate() on details). @@ -297,6 +300,12 @@ namespace bpkg linked_databases dependent_configs (bool sys_rep = false); + // Return configurations of the linked cluster which the current + // configuration belongs to. + // + linked_databases + cluster_configs (bool sys_rep = false); + // The following find_*() functions assume that the main database has been // created with the pre_attach flag set to true. // @@ -495,8 +504,9 @@ namespace bpkg linked_databases implicit_links_; }; - // NOTE: remember to update config_package comparison operators and - // compare_lazy_ptr if changing the database comparison operators. + // NOTE: remember to update package_key and package_version_key comparison + // operators and compare_lazy_ptr if changing the database comparison + // operators. // // Note that here we use the database address as the database identity since // we don't suppose two database instances for the same configuration to @@ -518,16 +528,17 @@ namespace bpkg inline bool operator< (const database& x, const database& y) { - // Note that if we ever need the ordering to be consistent across runs, - // then we can compare the config paths or uuids. + // Note that we used to compare the database addresses here (as for the + // equality operator) until we needed the database ordering to be + // consistent across runs (to support --rebuild-checksum, etc). // - return &x < &y; + return x.config < y.config; } inline ostream& operator<< (ostream& os, const database& db) { - const string& s (const_cast<database&> (db).string); + const string& s (db.string); if (!s.empty ()) os << ' ' << s; @@ -707,9 +718,10 @@ namespace bpkg 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 value_type = pair<reference_wrapper<database>, V>; + using base_type = small_vector<value_type, 16>; + using iterator = typename base_type::iterator; + using const_iterator = typename base_type::const_iterator; using base_type::begin; using base_type::end; @@ -724,6 +736,16 @@ namespace bpkg }); } + const_iterator + find (database& db) const + { + return find_if (begin (), end (), + [&db] (const value_type& i) -> bool + { + return i.first == db; + }); + } + pair<iterator, bool> insert (database& db, V&& v) { @@ -733,6 +755,17 @@ namespace bpkg return make_pair (base_type::emplace (end (), db, move (v)), true); } + + V& + operator[] (database& db) + { + iterator i (find (db)); + + if (i == end ()) + i = base_type::emplace (end (), db, V ()); + + return i->second; + } }; } |