/**************************************************************************** * Copyright (c) 2023 by the ArborX authors * * All rights reserved. * * * * This file is part of the ArborX library. ArborX is * * distributed under a BSD 3-clause license. For the licensing terms see * * the LICENSE file in the top-level directory. * * * * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ #ifndef ARBORX_DETAILS_LEGACY_HPP #define ARBORX_DETAILS_LEGACY_HPP #include #include #include namespace ArborX::Details { template class LegacyValues { Primitives _primitives; using Access = AccessTraits; public: using memory_space = typename Access::memory_space; using index_type = unsigned; using value_type = PairValueIndex; using size_type = Kokkos::detected_t; LegacyValues(Primitives const &primitives) : _primitives(primitives) {} KOKKOS_FUNCTION auto operator()(size_type i) const { using Primitive = std::decay_t; if constexpr (std::is_same_v) { return value_type{Access::get(_primitives, i), (index_type)i}; } else { BoundingVolume bounding_volume{}; expand(bounding_volume, Access::get(_primitives, i)); return value_type{bounding_volume, (index_type)i}; } #if (defined(KOKKOS_COMPILER_NVCC) && (KOKKOS_COMPILER_NVCC < 1150)) || \ (defined(KOKKOS_COMPILER_INTEL) && (KOKKOS_COMPILER_INTEL <= 2021)) // FIXME_NVCC, FIXME_INTEL: workaround for spurios "missing return // statement at end of non-void function" warning return value_type{}; #endif } KOKKOS_FUNCTION size_type size() const { return Access::size(_primitives); } }; template class AccessValuesI, PrimitivesTag> : public LegacyValues { public: using self_type = LegacyValues; }; template struct LegacyCallbackWrapper { Callback _callback; template KOKKOS_FUNCTION auto operator()(Predicate const &predicate, PairValueIndex const &value) const { return _callback(predicate, value.index); } template KOKKOS_FUNCTION void operator()(Predicate const &predicate, PairValueIndex const &value, Output const &out) const { // APIv1 callback has the signature operator()(Query, int) // As we store PairValueIndex with potentially non int index (like // unsigned), we explicitly cast it here. _callback(predicate, (int)value.index, out); } }; struct LegacyDefaultCallback { template KOKKOS_FUNCTION void operator()(Query const &, PairValueIndex const &value, OutputFunctor const &output) const { // APIv1 callback has the signature operator()(Query, int) // As we store PairValueIndex with potentially non int index (like // unsigned), we explicitly cast it here. output((int)value.index); } }; struct LegacyDefaultTemplateValue {}; } // namespace ArborX::Details template <> struct ArborX::GeometryTraits::dimension< ArborX::Details::LegacyDefaultTemplateValue> { static constexpr int value = 3; }; template <> struct ArborX::GeometryTraits::tag { using type = BoxTag; }; template <> struct ArborX::GeometryTraits::coordinate_type< ArborX::Details::LegacyDefaultTemplateValue> { using type = float; }; template struct ArborX::AccessTraits< ArborX::Details::LegacyValues, ArborX::PrimitivesTag> { using Values = ArborX::Details::LegacyValues; using memory_space = typename Values::memory_space; using size_type = typename Values::size_type; using value_type = typename Values::value_type; KOKKOS_FUNCTION static size_type size(Values const &values) { return values.size(); } KOKKOS_FUNCTION static decltype(auto) get(Values const &values, size_type i) { return values(i); } }; #endif