From d1fa0047be1db658b165514dc429ce494517b39c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 11 Aug 2021 20:17:12 +0300 Subject: Add support for cfg-unlink --- bpkg/database.hxx | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 8 deletions(-) (limited to 'bpkg/database.hxx') 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; + class linked_configs: public small_vector + { + public: + using base_type = small_vector; + + 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, 16>; + class linked_databases: public small_vector, 16> + { + public: + using base_type = small_vector, 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. -- cgit v1.1