![]() |
Shamrock 2025.10.0
Astrophysical Code
|
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< JsonSerializable > | create (const std::string &type, const nlohmann::json &data) const |
| Create an instance of a registered type from JSON. | |
Static Public Member Functions | |
| static JsonSerializable_registry & | instance () |
| Access the process-wide registry instance. | |
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.
|
inline |
Create an instance of a registered type from JSON.
| type | Type discriminator (must have been passed to register_type) |
| data | Full JSON object passed to the type's static from_json |
| std::runtime_error | if type is not registered |
Definition at line 197 of file JsonSerializable.hpp.
|
inlinestatic |
Access the process-wide registry instance.
Definition at line 149 of file JsonSerializable.hpp.
|
inline |
Check if a type is registered.
| name | Type discriminator string |
Definition at line 187 of file JsonSerializable.hpp.
|
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.
| T | Concrete type deriving from JsonSerializable |
| name | Type discriminator string |
Definition at line 164 of file JsonSerializable.hpp.