15 #include <type_traits> 18 #include "nlohmann/json.h" 102 virtual std::unique_ptr<ControlledValueBase>
build(
const std::string & name,
103 const nlohmann::json & json_value)
const = 0;
111 virtual std::unique_ptr<ControlledValueBase>
build(
const std::string & name)
const = 0;
127 template <
class ControlledValue,
class ValueType>
131 std::function<ValueType(
const nlohmann::json &)> && parse_function)
136 virtual std::unique_ptr<ControlledValueBase>
137 build(
const std::string & name)
const override final 139 return std::make_unique<ControlledValue>(
name,
type());
141 virtual std::unique_ptr<ControlledValueBase>
142 build(
const std::string & name,
const nlohmann::json & json_value)
const override final 161 template <
class ControlledValue,
class ValueType>
162 static char add(
const std::string & type_name,
163 std::function<ValueType(
const nlohmann::json &)> && parse_function);
177 std::map<std::string, std::unique_ptr<RegisteredTypeBase>>
_name_map;
183 template <
class ControlledValue,
class ValueType>
186 const std::string & type_name,
187 std::function<ValueType(
const nlohmann::json &)> && parse_function)
189 static_assert(std::is_base_of_v<ControlledValueBase, ControlledValue>,
190 "Is not derived from ControlledValueBase");
191 static_assert(std::is_same_v<typename ControlledValue::value_type, ValueType>,
"Is not the same");
193 auto entry = std::make_unique<RegisteredType<ControlledValue, ValueType>>(
194 type_name, std::move(parse_function));
197 "WebServerControlTypeRegistry: The string type \"", type_name,
"\" is already registered.");
199 static const std::type_index index =
typeid(ValueType);
201 ::
mooseError(
"WebServerControlRegistry: The type \"",
202 MooseUtils::prettyCppType<ValueType>(),
203 "\" is already registered");
std::string name(const ElemQuality q)
Base registry class for a type that is used to build values.
virtual std::unique_ptr< ControlledValueBase > build(const std::string &name) const override final
Builds a value with the given type, name name, and a default value.
static WebServerControlTypeRegistry & getRegistry()
Starts a webserver that an external process can connect to in order to send JSON messages to control ...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
ControlledValueBase(const std::string &name, const std::string &type)
Constructor.
virtual void setControllableValue(WebServerControl &control)=0
Sets the controllable value given the name and type via the controllable interface in control...
const std::string _type
The string representation of the underlying type.
RegisteredTypeBase(const std::string &type)
std::set< std::type_index > _value_types
The registered value types, to avoid registering the same underlying value type multiple times...
A static registry used to register and build values of different types for the WebServerControl.
const std::string & type() const
const std::string _name
The name that the value is for.
static const RegisteredTypeBase * query(const std::string &type)
Query the registration for the given type.
static char add(const std::string &type_name, std::function< ValueType(const nlohmann::json &)> &&parse_function)
Register a type in the registry.
const std::string & type() const
std::map< std::string, std::unique_ptr< RegisteredTypeBase > > _name_map
The registration data.
const std::function< ValueType(const nlohmann::json &)> _parse_function
Function that converts from json -> the value for the ValueType.
The base class for a value that is produced by this registry.
virtual ~RegisteredTypeBase()
virtual std::unique_ptr< ControlledValueBase > build(const std::string &name, const nlohmann::json &json_value) const override final
Builds a value with the given type, name name, and JSON value json_value.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual ~ControlledValueBase()
const std::string _type
The string representation of the type.
virtual std::unique_ptr< ControlledValueBase > build(const std::string &name, const nlohmann::json &json_value) const =0
Builds a value with the given type, name name, and JSON value json_value.
RegisteredType(const std::string &type, std::function< ValueType(const nlohmann::json &)> &&parse_function)
const std::string & name() const