14 #include <type_traits> 18 #include "minijson/minijson.h" 76 virtual const char *
what() const noexcept override final {
return _message.c_str(); }
92 template <
typename DerivedValueType>
93 static char add(
const std::string & type_name)
95 static_assert(std::is_base_of_v<ValueBase, DerivedValueType>,
"Is not derived from ValueBase");
108 static std::unique_ptr<ValueBase>
build(
const std::string & type,
const std::string & name)
117 static std::unique_ptr<ValueBase>
118 build(
const std::string & type,
const std::string & name,
const miniJson::Json & json_value)
120 return get(type).
build(
name, json_value);
143 virtual std::unique_ptr<ValueBase>
build(
const std::string & name,
144 const miniJson::Json & json_value)
const = 0;
150 virtual std::unique_ptr<ValueBase>
build(
const std::string & name)
const = 0;
157 template <
class DerivedValueType>
162 virtual std::unique_ptr<ValueBase>
build(
const std::string & name)
const override final 164 return std::make_unique<DerivedValueType>(
name,
type());
166 virtual std::unique_ptr<ValueBase>
build(
const std::string & name,
167 const miniJson::Json & json_value)
const override final 169 return std::make_unique<DerivedValueType>(
name,
type(), json_value);
176 static const TypeBase &
get(
const std::string & type)
179 const auto it = registry._types.find(type);
180 if (it == registry._types.end())
181 mooseError(
"WebServerControlTypeRegistry: The type '", type,
"' is not registered");
186 std::map<std::string, std::unique_ptr<TypeBase>>
_types;
std::string name(const ElemQuality q)
std::map< std::string, std::unique_ptr< TypeBase > > _types
The registration data.
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 ...
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...
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.
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.