From 98371821893010e251fcffcb6f9729dd981435c6 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 2 Dec 2024 19:25:34 +0100 Subject: [PATCH] Rename overload selection tags and refine docstring wording --- include/podio/LinkNavigator.h | 50 +++++++++++++++++++---------------- tests/unittests/links.cpp | 8 +++--- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/include/podio/LinkNavigator.h b/include/podio/LinkNavigator.h index fc7569d32..ceb02df45 100644 --- a/include/podio/LinkNavigator.h +++ b/include/podio/LinkNavigator.h @@ -28,17 +28,17 @@ namespace detail::links { }; /// Simple struct tag for overload selection in LinkNavigator below - struct LookupFromTag {}; + struct ReturnFromTag {}; /// Simple struct tag for overload selection in LinkNavigator below - struct LookupToTag {}; + struct ReturnToTag {}; } // namespace detail::links -/// Tag variable to select the lookup of *From* objects that are linked from a -/// *To* object in podio::LinkNavigator::getLinked -static constexpr detail::links::LookupFromTag LookupFrom; -/// Tag variable to select the lookup of *To* objects that are linked from a +/// Tag variable to select the lookup of *From* objects have links with a *To* +/// object in podio::LinkNavigator::getLinked +static constexpr detail::links::ReturnFromTag ReturnFrom; +/// Tag variable to select the lookup of *To* objects that have links with a /// *From* object in podio::LinkNavigator::getLinked -static constexpr detail::links::LookupToTag LookupTo; +static constexpr detail::links::ReturnToTag ReturnTo; /// A helper class to more easily handle one-to-many links. /// @@ -69,7 +69,8 @@ class LinkNavigator { LinkNavigator& operator=(LinkNavigator&&) = default; ~LinkNavigator() = default; - /// Get all the objects and weights that are linked to the passed object + /// Get all the *From* objects and weights that have links with the passed + /// object /// /// You will get this overload if you pass the podio::LookupFrom tag as second /// argument @@ -78,12 +79,12 @@ class LinkNavigator { /// to construct this instance of the LinkNavigator has the same From and To /// types. /// - /// @param object The object that is labeled *to* in the link + /// @param object The object that is labeled *To* in the link /// @param . tag variable for selecting this overload /// - /// @returns A vector of all objects and their weights that are linked to + /// @returns A vector of all objects and their weights that have links with /// the passed object - std::vector> getLinked(const ToT& object, podio::detail::links::LookupFromTag) const { + std::vector> getLinked(const ToT& object, podio::detail::links::ReturnFromTag) const { const auto& [begin, end] = m_to2from.equal_range(object); std::vector> result; result.reserve(std::distance(begin, end)); @@ -94,22 +95,24 @@ class LinkNavigator { return result; } - /// Get all the objects and weights that are linked to the passed object + /// Get all the *From* objects and weights that have links with the passed + /// object /// /// @note This overload will automatically do the right thing (TM) in case the /// LinkCollection that has been passed to construct this LinkNavigator has /// different From and To types. /// - /// @param object The object that is labeled *to* in the link + /// @param object The object that is labeled *To* in the link /// - /// @returns A vector of all objects and their weights that are linked to + /// @returns A vector of all objects and their weights that have links with /// the passed object template std::enable_if_t, std::vector>> getLinked(const ToT& object) const { - return getLinked(object, podio::LookupFrom); + return getLinked(object, podio::ReturnFrom); } - /// Get all the objects and weights that are linked to the passed object + /// Get all the *To* objects and weights that have links with the passed + /// object /// /// You will get this overload if you pass the podio::LookupTo tag as second /// argument @@ -118,12 +121,12 @@ class LinkNavigator { /// to construct this instance of the LinkNavigator has the same From and To /// types. /// - /// @param object The object that is labeled *from* in the link + /// @param object The object that is labeled *From* in the link /// @param . tag variable for selecting this overload /// - /// @returns A vector of all objects and their weights that are linked to + /// @returns A vector of all objects and their weights that have links with /// the passed object - std::vector> getLinked(const FromT& object, podio::detail::links::LookupToTag) const { + std::vector> getLinked(const FromT& object, podio::detail::links::ReturnToTag) const { const auto& [begin, end] = m_from2to.equal_range(object); std::vector> result; result.reserve(std::distance(begin, end)); @@ -134,19 +137,20 @@ class LinkNavigator { return result; } - /// Get all the objects and weights that are linked to the passed object + /// Get all the *To* objects and weights that have links with the passed + /// object /// /// @note This overload will automatically do the right thing (TM) in case the /// LinkCollection that has been passed to construct this LinkNavigator has /// different From and To types. /// - /// @param object The object that is labeled *from* in the link + /// @param object The object that is labeled *From* in the link /// - /// @returns A vector of all objects and their weights that are linked to + /// @returns A vector of all objects and their weights that have links with /// the passed object template std::enable_if_t, std::vector>> getLinked(const FromT& object) const { - return getLinked(object, podio::LookupTo); + return getLinked(object, podio::ReturnTo); } private: diff --git a/tests/unittests/links.cpp b/tests/unittests/links.cpp index b164d95b3..6731d1193 100644 --- a/tests/unittests/links.cpp +++ b/tests/unittests/links.cpp @@ -539,12 +539,12 @@ TEST_CASE("LinkNavigator same types", "[links]") { link.setWeight(0.66f); auto navigator = podio::LinkNavigator{linkColl}; - auto linkedClusters = navigator.getLinked(clusters[1], podio::LookupTo); + auto linkedClusters = navigator.getLinked(clusters[1], podio::ReturnTo); REQUIRE(linkedClusters.size() == 1); REQUIRE(linkedClusters[0].o == clusters[2]); REQUIRE(linkedClusters[0].weight == 0.66f); - linkedClusters = navigator.getLinked(clusters[1], podio::LookupTo); + linkedClusters = navigator.getLinked(clusters[1], podio::ReturnTo); REQUIRE(linkedClusters.size() == 1); REQUIRE(linkedClusters[0].o == clusters[0]); REQUIRE(linkedClusters[0].weight == 0.5f); @@ -552,11 +552,11 @@ TEST_CASE("LinkNavigator same types", "[links]") { using Catch::Matchers::UnorderedEquals; using podio::detail::links::WeightedObject; using WeightedObjVec = std::vector>; - linkedClusters = navigator.getLinked(clusters[0], podio::LookupTo); + linkedClusters = navigator.getLinked(clusters[0], podio::ReturnTo); REQUIRE_THAT(linkedClusters, UnorderedEquals(WeightedObjVec{WeightedObject(clusters[1], 0.5f), WeightedObject{clusters[2], 0.25f}})); - linkedClusters = navigator.getLinked(clusters[2], podio::LookupFrom); + linkedClusters = navigator.getLinked(clusters[2], podio::ReturnFrom); REQUIRE_THAT(linkedClusters, UnorderedEquals(WeightedObjVec{WeightedObject{clusters[0], 0.25f}, WeightedObject{clusters[1], 0.66f}})); }