https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParameterRegistry.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "Moose.h"
11
12#include "ParameterRegistry.h"
13
14namespace Moose
15{
16ParameterRegistry &
18{
19 static ParameterRegistry * registry = nullptr;
20 if (!registry)
21 registry = new ParameterRegistry();
22 return *registry;
23}
24
25void
26ParameterRegistry::set(libMesh::Parameters::Value & value, const hit::Field & field) const
27{
28 const std::type_index key(value.type_info());
29 const auto it = _registry.find(key);
30 if (it == _registry.end())
31 mooseError("ParameterRegistry::set(): Parameter type '",
32 MooseUtils::prettyCppType(value.type()),
33 "' is not registered");
34
35 // Catch all mooseErrors so that they can be accumulated during
36 // parsing and building instead of ending the run
37 Moose::ScopedThrowOnError scoped_throw_on_error;
38
39 it->second(value, field);
40}
41}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Registry that allows for the typeless setting of a parameter value from a hit field.
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.
ParameterRegistry()
Constructor; private so that it can only be created with the singleton.
Scoped helper for setting Moose::_throw_on_error during this scope.
Definition Moose.h:298
std::string prettyCppType(const std::string &cpp_type)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...