17#include "libmesh/parameters.h"
23#include "gtest/gtest.h"
54 template <
class T,
class F>
77 std::unordered_map<std::type_index,
82template <
class T,
class F>
86 static_assert(std::is_invocable_r_v<void, F &, T &, const hit::Field &>,
87 "Setter function must be callable with (T &, const hit::Field &) and return void");
93 const hit::Field & field) ->
void
96 mooseAssert(cast_param_value,
"Cast failed");
97 f(cast_param_value->set(), field);
100 const std::type_index key(
typeid(T));
101 const auto it_inserted_pair =
_registry.emplace(key, std::move(setter));
103 if (!it_inserted_pair.second)
104 mooseError(
"ParameterRegistry: Parameter with type '",
105 MooseUtils::prettyCppType<T>(),
106 "' is already registered");
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
class GTEST_TEST_CLASS_NAME_(ParameterRegistryTest, add)
Registry that allows for the typeless setting of a parameter value from a hit field.
char add(F &&f)
Add a parameter.
std::unordered_map< std::type_index, std::function< void(libMesh::Parameters::Value &value, const hit::Field &)> > _registry
Registration map of type -> function to fill each type.
static ParameterRegistry & get()
Get the singleton registry.
void set(libMesh::Parameters::Value &value, const hit::Field &field) const
Sets a parameter value given a hit field.
FRIEND_TEST(::ParameterRegistryTest, set)
FRIEND_TEST(::ParameterRegistryTest, setCatchMooseError)
ParameterRegistry()
Constructor; private so that it can only be created with the singleton.
FRIEND_TEST(::ParameterRegistryTest, setNotRegistered)
FRIEND_TEST(::ParameterRegistryTest, addExists)
FRIEND_TEST(::ParameterRegistryTest, add)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...