// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception #ifndef DUNE_ISTL_COMMON_REGISTRY_HH #define DUNE_ISTL_COMMON_REGISTRY_HH #include #include #include #include #include #include "counter.hh" #include #include #include #define DUNE_REGISTRY_PUT(Tag, id, ...) \ namespace { \ template<> \ struct Registry \ { \ static auto getCreator() \ { \ return __VA_ARGS__; \ } \ static std::string name() { return id; } \ }; \ } \ DUNE_INC_COUNTER(Tag) namespace Dune { namespace { template struct Registry; } namespace { template class Base, class V, class Tag, typename... Args> auto registryGet(Tag , std::string name, Args... args) { constexpr auto count = DUNE_GET_COUNTER(Tag); std::shared_ptr > result; Dune::Hybrid::forEach(std::make_index_sequence{}, [&](auto index) { using Reg = Registry; if(!result && Reg::name() == name) { result = Reg::getCreator()(Dune::MetaType{}, args...); } }); return result; } /* Register all creators from the registry in the Parameterizedobjectfactory. An object of V is passed in the creator and should be used to determine the template arguments. */ template int addRegistryToFactory(Dune::ParameterizedObjectFactory& factory, Tag){ constexpr auto count = DUNE_GET_COUNTER(Tag); Dune::Hybrid::forEach(std::make_index_sequence{}, [&](auto index) { // we first get the generic lambda // and later specialize it with given parameters. // doing all at once leads to an ICE with g++-6 using Reg = Registry; auto genericcreator = Reg::getCreator(); factory.define(Reg::name(), [genericcreator](Args... args){ return genericcreator(V{}, args...); }); }); return count; } } // end anonymous namespace } // end namespace Dune #endif // DUNE_ISTL_COMMON_REGISTRY_HH