aboutsummaryrefslogtreecommitdiff
path: root/bpkg/database.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-08-11 20:17:12 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-08-13 11:55:24 +0300
commitd1fa0047be1db658b165514dc429ce494517b39c (patch)
treebe114b36341ee49b3d835687291974a0ac3661ed /bpkg/database.hxx
parentaac298fcef914b99cf28d9cf1f4f58cc6714fb92 (diff)
Add support for cfg-unlink
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r--bpkg/database.hxx82
1 files changed, 74 insertions, 8 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx
index 32169bb..1961272 100644
--- a/bpkg/database.hxx
+++ b/bpkg/database.hxx
@@ -35,15 +35,60 @@ namespace bpkg
};
// Used for the immediate explicit links which are normally not many (one
- // entry for the self-link).
+ // entry for the self-link, which normally comes first).
//
- using linked_configs = small_vector<linked_config, 2>;
+ class linked_configs: public small_vector<linked_config, 2>
+ {
+ public:
+ using base_type = small_vector<linked_config, 2>;
+
+ using base_type::base_type;
- // In particular, is used for implicit links which can potentially be many.
- // Think of a dependency in a shared configuration with dependents in
- // multiple implicitly linked configurations.
+ // Skip the self-link.
+ //
+ const_iterator
+ begin_linked () const
+ {
+ assert (!empty ());
+ return begin () + 1;
+ }
+
+ iterator
+ begin_linked ()
+ {
+ assert (!empty ());
+ return begin () + 1;
+ }
+ };
+
+ // In particular, is used for implicit links which can potentially be many
+ // (with the self-link which normally comes first). Think of a dependency in
+ // a shared configuration with dependents in multiple implicitly linked
+ // configurations.
//
- using linked_databases = small_vector<reference_wrapper<database>, 16>;
+ class linked_databases: public small_vector<reference_wrapper<database>, 16>
+ {
+ public:
+ using base_type = small_vector<reference_wrapper<database>, 16>;
+
+ using base_type::base_type;
+
+ // Skip the self-link.
+ //
+ const_iterator
+ begin_linked () const
+ {
+ assert (!empty ());
+ return begin () + 1;
+ }
+
+ iterator
+ begin_linked ()
+ {
+ assert (!empty ());
+ return begin () + 1;
+ }
+ };
// Derive a custom database class that handles attaching/detaching
// additional configurations.
@@ -236,12 +281,16 @@ namespace bpkg
// created with the pre_attach flag set to true.
//
+ // The following find_attached() overloads include the self reference into
+ // the search by default and skip it if requested.
+ //
+
// Return the self reference if the id is 0. Otherwise, return the
// database of an explicitly linked configuration with the specified link
// id and issue diagnostics and fail if no link is found.
//
database&
- find_attached (uint64_t id);
+ find_attached (uint64_t id, bool self = true);
// Return the self reference if this is the current configuration
// name. Otherwise, return the database of an explicitly linked
@@ -249,7 +298,24 @@ namespace bpkg
// no link is found.
//
database&
- find_attached (const std::string& name);
+ find_attached (const std::string& name, bool self = true);
+
+ // Return the self reference if this is the current configuration
+ // uuid. Otherwise, return the database of an explicitly linked
+ // configuration with the specified uuid and issue diagnostics and fail if
+ // no link is found.
+ //
+ database&
+ find_attached (const uuid_type&, bool self = true);
+
+ // Return the self reference if this is the current configuration
+ // path. Otherwise, return the database of an explicitly linked
+ // configuration with the specified path and issue diagnostics and fail if
+ // no link is found. The configuration directory should be absolute and
+ // normalized.
+ //
+ database&
+ find_attached (const dir_path&, bool self = true);
// Return the dependency configuration with the specified uuid and issue
// diagnostics and fail if not found.