Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamrock::solvergraph::JsonSerializable_registry Class Reference

Singleton registry mapping type names to JSON factory functions. More...

#include <shamsolvergraph/include/shamsolvergraph/JsonSerializable.hpp>

Public Member Functions

template<JsonDeserializable T>
void register_type (const std::string &name, std::source_location loc=std::source_location::current())
 Register a type under a string name for polymorphic deserialization.
bool is_type_registered (const std::string &name) const
 Check if a type is registered.
std::unique_ptr< JsonSerializablecreate (const std::string &type, const nlohmann::json &data) const
 Create an instance of a registered type from JSON.

Static Public Member Functions

static JsonSerializable_registryinstance ()
 Access the process-wide registry instance.

Detailed Description

Singleton registry mapping type names to JSON factory functions.

Types are registered with register_type. Polymorphic reconstruction goes through JsonSerializable::from_json, which calls create.

Definition at line 140 of file JsonSerializable.hpp.

Member Function Documentation

◆ create()

std::unique_ptr< JsonSerializable > shamrock::solvergraph::JsonSerializable_registry::create ( const std::string & type,
const nlohmann::json & data ) const
inline

Create an instance of a registered type from JSON.

Parameters
typeType discriminator (must have been passed to register_type)
dataFull JSON object passed to the type's static from_json
Returns
Owned instance of the registered type
Exceptions
std::runtime_errorif type is not registered

Definition at line 197 of file JsonSerializable.hpp.

◆ instance()

JsonSerializable_registry & shamrock::solvergraph::JsonSerializable_registry::instance ( )
inlinestatic

Access the process-wide registry instance.

Definition at line 149 of file JsonSerializable.hpp.

◆ is_type_registered()

bool shamrock::solvergraph::JsonSerializable_registry::is_type_registered ( const std::string & name) const
inline

Check if a type is registered.

Parameters
nameType discriminator string
Returns
True if the type is registered, false otherwise

Definition at line 187 of file JsonSerializable.hpp.

◆ register_type()

template<JsonDeserializable T>
void shamrock::solvergraph::JsonSerializable_registry::register_type ( const std::string & name,
std::source_location loc = std::source_location::current() )
inline

Register a type under a string name for polymorphic deserialization.

The name must match T::type_name() and the JSON "type" field. T must satisfy JsonDeserializable.

Template Parameters
TConcrete type deriving from JsonSerializable
Parameters
nameType discriminator string

Definition at line 164 of file JsonSerializable.hpp.

Here is the call graph for this function:

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