https://mooseframework.inl.gov
Classes | Static Public Member Functions | Static Private 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

struct  Type
 
class  TypeBase
 Base registry class for a type that is used to build values. More...
 
class  ValueBase
 The base class for a value that is produced by this registry. More...
 

Static Public Member Functions

static WebServerControlTypeRegistrygetRegistry ()
 
template<typename DerivedValueType >
static char add (const std::string &type_name)
 Registers a type with string name type_name and the given derived type. More...
 
static bool isRegistered (const std::string &type)
 
static std::unique_ptr< ValueBasebuild (const std::string &type, const std::string &name)
 Builds a value with the type type, name name, and a default value. More...
 
static std::unique_ptr< ValueBasebuild (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. More...
 

Static Private Member Functions

static const TypeBaseget (const std::string &type)
 Internal getter for the registration object for type type. More...
 

Private Attributes

std::map< std::string, std::unique_ptr< TypeBase > > _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 32 of file WebServerControlTypeRegistry.h.

Member Function Documentation

◆ add()

template<typename DerivedValueType >
static char Moose::WebServerControlTypeRegistry::add ( const std::string &  type_name)
inlinestatic

Registers a type with string name type_name and the given derived type.

Definition at line 95 of file WebServerControlTypeRegistry.h.

Referenced by WebServerControl::registerRealEigenMatrix(), WebServerControl::registerScalarType(), and WebServerControl::registerVectorType().

96  {
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);
100  if (!getRegistry()
101  ._name_map.emplace(type_name, std::make_unique<Type<DerivedValueType>>(type_name))
102  .second)
103  ::mooseError("WebServerControlTypeRegistry: The string type \"",
104  type_name,
105  "\" is already registered.");
106  if (!getRegistry()._value_types.insert(index).second)
107  ::mooseError("WebServerControlRegistry: The type \"",
108  MooseUtils::prettyCppType<value_type>(),
109  "\" is already registered");
110  return 0;
111  }
static WebServerControlTypeRegistry & getRegistry()
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...
Definition: MooseError.h:333
std::set< std::type_index > _value_types
The registered value types, to avoid registering the same underlying value type multiple times...

◆ build() [1/2]

static std::unique_ptr<ValueBase> Moose::WebServerControlTypeRegistry::build ( const std::string &  type,
const std::string &  name 
)
inlinestatic

Builds a value with the type type, name name, and a default value.

Definition at line 121 of file WebServerControlTypeRegistry.h.

Referenced by build(), WebServerControl::execute(), and WebServerControl::startServer().

122  {
123  return get(type).build(name);
124  }
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.

◆ build() [2/2]

static std::unique_ptr<ValueBase> Moose::WebServerControlTypeRegistry::build ( const std::string &  type,
const std::string &  name,
const miniJson::Json &  json_value 
)
inlinestatic

Builds a value with the type type, name name, and a value parsed from json_value.

Will throw ValueBase::Exception on a parsing error.

Definition at line 131 of file WebServerControlTypeRegistry.h.

132  {
133  return get(type).build(name, json_value);
134  }
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.

◆ get()

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

Internal getter for the registration object for type type.

Definition at line 191 of file WebServerControlTypeRegistry.h.

192  {
193  auto & registry = getRegistry();
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");
197  return *it->second;
198  }
static WebServerControlTypeRegistry & getRegistry()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333

◆ getRegistry()

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

Definition at line 15 of file WebServerControlTypeRegistry.C.

Referenced by add(), get(), and isRegistered().

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

◆ isRegistered()

static bool Moose::WebServerControlTypeRegistry::isRegistered ( const std::string &  type)
inlinestatic
Returns
Whether or not the type type is registered.

Definition at line 116 of file WebServerControlTypeRegistry.h.

Referenced by WebServerControl::startServer().

116 { return getRegistry()._name_map.count(type); }
static WebServerControlTypeRegistry & getRegistry()
std::map< std::string, std::unique_ptr< TypeBase > > _name_map
The registration data.

Member Data Documentation

◆ _name_map

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

The registration data.

Definition at line 201 of file WebServerControlTypeRegistry.h.

Referenced by add(), and isRegistered().

◆ _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 204 of file WebServerControlTypeRegistry.h.

Referenced by add().


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