https://mooseframework.inl.gov
Classes | Static Public Member Functions | Private Attributes | List of all members
Moose::WebServerControlTypeRegistry Class Reference

A static registry used to register and build values of different types for the WebServerControl. More...

#include <WebServerControlTypeRegistry.h>

Classes

class  ControlledValueBase
 The base class for a value that is produced by this registry. More...
 
struct  RegisteredType
 Derived registry item. More...
 
class  RegisteredTypeBase
 Base registry class for a type that is used to build values. More...
 

Static Public Member Functions

static WebServerControlTypeRegistrygetRegistry ()
 
template<class ControlledValue , class ValueType >
static char add (const std::string &type_name, std::function< ValueType(const nlohmann::json &)> &&parse_function)
 Register a type in the registry. More...
 
static const RegisteredTypeBasequery (const std::string &type)
 Query the registration for the given type. More...
 
static const RegisteredTypeBaseget (const std::string &type)
 Get the registration for the given type, erroring if it isn't registered. More...
 

Private Attributes

std::map< std::string, std::unique_ptr< RegisteredTypeBase > > _name_map
 The registration data. More...
 
std::set< std::type_index > _value_types
 The registered value types, to avoid registering the same underlying value type multiple times. More...
 

Detailed Description

A static registry used to register and build values of different types for the WebServerControl.

Needed due to the complexities of parsing parameter types from generic JSON received by the web server.

Definition at line 33 of file WebServerControlTypeRegistry.h.

Member Function Documentation

◆ add()

template<class ControlledValue , class ValueType >
char Moose::WebServerControlTypeRegistry::add ( const std::string &  type_name,
std::function< ValueType(const nlohmann::json &)> &&  parse_function 
)
static

Register a type in the registry.

Template Parameters
ControlledValueThe derived ControlledValueBase class that contains the implementation for setting the controllable value
ValueTypeThe underlying type of the value to be controlled
Parameters
type_nameHuman readable name for the type of the value to be controlled
parse_functionFunction used to parse the value from JSON

Definition at line 185 of file WebServerControlTypeRegistry.h.

Referenced by Moose::WebServerControlTypeRegistration::registerType().

188 {
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");
192 
193  auto entry = std::make_unique<RegisteredType<ControlledValue, ValueType>>(
194  type_name, std::move(parse_function));
195  if (!getRegistry()._name_map.emplace(type_name, std::move(entry)).second)
196  ::mooseError(
197  "WebServerControlTypeRegistry: The string type \"", type_name, "\" is already registered.");
198 
199  static const std::type_index index = typeid(ValueType);
200  if (!getRegistry()._value_types.insert(index).second)
201  ::mooseError("WebServerControlRegistry: The type \"",
202  MooseUtils::prettyCppType<ValueType>(),
203  "\" is already registered");
204  return 0;
205 }
static WebServerControlTypeRegistry & getRegistry()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::set< std::type_index > _value_types
The registered value types, to avoid registering the same underlying value type multiple times...
std::map< std::string, std::unique_ptr< RegisteredTypeBase > > _name_map
The registration data.

◆ get()

const WebServerControlTypeRegistry::RegisteredTypeBase & Moose::WebServerControlTypeRegistry::get ( const std::string &  type)
static

Get the registration for the given type, erroring if it isn't registered.

Definition at line 36 of file WebServerControlTypeRegistry.C.

Referenced by WebServerControl::execute().

37 {
38  if (const auto obj = query(type))
39  return *obj;
40  mooseError("WebServerControlTypeRegistry: The type '", type, "' is not registered");
41 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
static const RegisteredTypeBase * query(const std::string &type)
Query the registration for the given type.

◆ getRegistry()

WebServerControlTypeRegistry & Moose::WebServerControlTypeRegistry::getRegistry ( )
static
Returns
The WebServerControlTypeRegistry singleton

Definition at line 15 of file WebServerControlTypeRegistry.C.

Referenced by add(), and query().

16 {
17  static WebServerControlTypeRegistry * registry_singleton = nullptr;
18  if (!registry_singleton)
19  registry_singleton = new WebServerControlTypeRegistry;
20  return *registry_singleton;
21 }

◆ query()

const WebServerControlTypeRegistry::RegisteredTypeBase * Moose::WebServerControlTypeRegistry::query ( const std::string &  type)
static

Query the registration for the given type.

Definition at line 24 of file WebServerControlTypeRegistry.C.

Referenced by WebServerControl::addServerActionsInternal(), and get().

25 {
26  const auto & name_map = getRegistry()._name_map;
27  if (const auto it = name_map.find(type); it != name_map.end())
28  {
29  mooseAssert(it->second, "Item is nullptr");
30  return it->second.get();
31  }
32  return nullptr;
33 }
static WebServerControlTypeRegistry & getRegistry()
std::map< std::string, std::unique_ptr< RegisteredTypeBase > > _name_map
The registration data.

Member Data Documentation

◆ _name_map

std::map<std::string, std::unique_ptr<RegisteredTypeBase> > Moose::WebServerControlTypeRegistry::_name_map
private

The registration data.

Definition at line 177 of file WebServerControlTypeRegistry.h.

Referenced by add(), and query().

◆ _value_types

std::set<std::type_index> Moose::WebServerControlTypeRegistry::_value_types
private

The registered value types, to avoid registering the same underlying value type multiple times.

Definition at line 180 of file WebServerControlTypeRegistry.h.

Referenced by add().


The documentation for this class was generated from the following files: