14 #include <type_traits> 20 #include "minijson/minijson.h" 78 virtual const char *
what() const noexcept override final {
return _message.c_str(); }
94 template <
typename DerivedValueType>
95 static char add(
const std::string & type_name)
97 static_assert(std::is_base_of_v<ValueBase, DerivedValueType>,
"Is not derived from ValueBase");
98 using value_type =
typename DerivedValueType::value_type;
99 static const std::type_index index =
typeid(value_type);
103 ::
mooseError(
"WebServerControlTypeRegistry: The string type \"",
105 "\" is already registered.");
107 ::
mooseError(
"WebServerControlRegistry: The type \"",
108 MooseUtils::prettyCppType<value_type>(),
109 "\" is already registered");
121 static std::unique_ptr<ValueBase>
build(
const std::string & type,
const std::string & name)
130 static std::unique_ptr<ValueBase>
131 build(
const std::string & type,
const std::string & name,
const miniJson::Json & json_value)
133 return get(type).
build(
name, json_value);
156 virtual std::unique_ptr<ValueBase>
build(
const std::string & name,
157 const miniJson::Json & json_value)
const = 0;
163 virtual std::unique_ptr<ValueBase>
build(
const std::string & name)
const = 0;
170 template <
class DerivedValueType>
177 virtual std::unique_ptr<ValueBase>
build(
const std::string & name)
const override final 179 return std::make_unique<DerivedValueType>(
name,
type());
181 virtual std::unique_ptr<ValueBase>
build(
const std::string & name,
182 const miniJson::Json & json_value)
const override final 184 return std::make_unique<DerivedValueType>(
name,
type(), json_value);
191 static const TypeBase &
get(
const std::string & type)
194 const auto it = registry._name_map.find(type);
195 if (it == registry._name_map.end())
196 mooseError(
"WebServerControlTypeRegistry: The type '", type,
"' is not registered");
201 std::map<std::string, std::unique_ptr<TypeBase>>
_name_map;
std::string name(const ElemQuality q)
const std::string & name() const
TypeBase(const std::string &type)
static bool isRegistered(const std::string &type)
static WebServerControlTypeRegistry & getRegistry()
Starts a webserver that an external process can connect to in order to send JSON messages to control ...
std::map< std::string, std::unique_ptr< TypeBase > > _name_map
The registration data.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
virtual void setControllableValue(WebServerControl &control)=0
Sets the controllable value given the name and type via the controllable interface in control...
typename DerivedValueType::value_type value_type
The base class for a value that is produced by this registry.
Common exception for parsing related errors in converting JSON to a value.
const std::string _name
The name that the value is for.
std::set< std::type_index > _value_types
The registered value types, to avoid registering the same underlying value type multiple times...
const std::string & type() const
A static registry used to register and build values of different types for the WebServerControl.
const std::string & type() const
virtual std::unique_ptr< ValueBase > build(const std::string &name, const miniJson::Json &json_value) const override final
Builds a value with the given type, name name, and JSON value json_value.
const std::string _message
virtual const char * what() const noexcept override final
ValueBase(const std::string &name, const std::string &type)
Constructor.
static std::unique_ptr< ValueBase > build(const std::string &type, const std::string &name, const miniJson::Json &json_value)
Builds a value with the type type, name name, and a value parsed from json_value. ...
virtual std::unique_ptr< ValueBase > build(const std::string &name) const override final
Builds a value with the given type, name name, and a default value.
virtual std::unique_ptr< ValueBase > build(const std::string &name, const miniJson::Json &json_value) const =0
Builds a value with the given type, name name, and JSON value json_value.
Exception(const std::string &message)
Base registry class for a type that is used to build values.
Type(const std::string &type)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const std::string _type
The string representation of the type.
static std::unique_ptr< ValueBase > build(const std::string &type, const std::string &name)
Builds a value with the type type, name name, and a default value.
const std::string _type
The string representation of the underlying type.
static char add(const std::string &type_name)
Registers a type with string name type_name and the given derived type.