aboutsummaryrefslogtreecommitdiff
path: root/bpkg/database.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r--bpkg/database.hxx38
1 files changed, 32 insertions, 6 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx
index cfd2645..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;
@@ -501,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
@@ -534,7 +538,7 @@ namespace bpkg
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;
@@ -714,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;
@@ -731,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)
{
@@ -740,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;
+ }
};
}