DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
DNDS::ConfigRegistry< T > Class Template Reference

Per-type singleton registry of config field metadata and validation checks. More...

#include <ConfigRegistry.hpp>

Static Public Member Functions

static bool registerField (FieldMeta meta)
 Register a single field's metadata.
 
static bool registerCheck (CrossFieldCheck check)
 Register a cross-field validation check (no runtime context needed).
 
static bool registerContextualCheck (ContextualCheck check)
 Register a cross-field validation check that needs runtime context.
 
static void registerPostReadHook (std::function< void(T &)> hook)
 Register a post-read hook called after all fields are deserialized. Useful for recomputing derived quantities (e.g. CpGas from gamma and Rgas).
 
static const std::vector< FieldMeta > & fields ()
 All registered field descriptors, in declaration order.
 
static const std::vector< CrossFieldCheck > & checks ()
 All registered context-free checks.
 
static const std::vector< ContextualCheck > & contextualChecks ()
 All registered context-aware checks.
 
static void readFromJson (const nlohmann::ordered_json &j, T &obj)
 Deserialize all registered fields from a JSON object into a struct.
 
static void writeToJson (nlohmann::ordered_json &j, const T &obj)
 Serialize all registered fields from a struct into a JSON object.
 
static nlohmann::ordered_json emitSchema (const std::string &sectionDescription="")
 Emit a JSON Schema (draft-07) object describing all registered fields.
 
static std::vector< CheckResultvalidate (const T &obj)
 Run all context-free cross-field checks on a struct instance.
 
static std::vector< CheckResultvalidateWithContext (const T &obj, const ConfigContext &ctx)
 Run all checks (both context-free and context-aware) on a struct instance.
 
static void validateKeys (const nlohmann::ordered_json &userJson)
 Check that every key in a user-supplied JSON object corresponds to a registered field. Throws on the first unknown key found.
 

Detailed Description

template<typename T>
class DNDS::ConfigRegistry< T >

Per-type singleton registry of config field metadata and validation checks.

Template Parameters
TThe config section struct type (e.g. LimiterControl, VRSettings).

Thread Safety

Registration happens lazily on first use of to_json, from_json, or schema() (via _dnds_ensure_registered()). After the one-time init completes, the registry is read-only. All const accessors and operations (readFromJson, writeToJson, emitSchema, validate) are safe to call concurrently from multiple threads.

Registration Order

Fields are stored in the order the DNDS_FIELD / config.field() calls execute inside the _dnds_do_register() body, which matches the source order. This gives deterministic JSON key ordering and schema property ordering.

Definition at line 229 of file ConfigRegistry.hpp.

Member Function Documentation

◆ checks()

template<typename T >
static const std::vector< CrossFieldCheck > & DNDS::ConfigRegistry< T >::checks ( )
inlinestatic

All registered context-free checks.

Definition at line 306 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ contextualChecks()

template<typename T >
static const std::vector< ContextualCheck > & DNDS::ConfigRegistry< T >::contextualChecks ( )
inlinestatic

All registered context-aware checks.

Definition at line 309 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ emitSchema()

template<typename T >
static nlohmann::ordered_json DNDS::ConfigRegistry< T >::emitSchema ( const std::string &  sectionDescription = "")
inlinestatic

Emit a JSON Schema (draft-07) object describing all registered fields.

The output looks like:

{
"type": "object",
"description": "...",
"properties": {
"dtImplicit": { "type": "number", "default": 1e100, "description": "..." },
"nTimeStep": { "type": "integer", "default": 1000000, "description": "..." },
...
}
}
Parameters
sectionDescriptionOptional description for the section itself.
Returns
The schema JSON object.

Definition at line 379 of file ConfigRegistry.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fields()

template<typename T >
static const std::vector< FieldMeta > & DNDS::ConfigRegistry< T >::fields ( )
inlinestatic

All registered field descriptors, in declaration order.

Definition at line 303 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ readFromJson()

template<typename T >
static void DNDS::ConfigRegistry< T >::readFromJson ( const nlohmann::ordered_json &  j,
T &  obj 
)
inlinestatic

Deserialize all registered fields from a JSON object into a struct.

For each field, reads j[field.name] and writes it into the corresponding member of obj. If the field has a range constraint (from DNDS::Config::range()), the parsed numeric value is checked against min/max bounds before assignment.

Parameters
jSource JSON object.
objDestination struct instance.
Exceptions
std::runtime_erroron missing keys, type mismatch, or range constraint violation.

Definition at line 326 of file ConfigRegistry.hpp.

Here is the call graph for this function:

◆ registerCheck()

template<typename T >
static bool DNDS::ConfigRegistry< T >::registerCheck ( CrossFieldCheck  check)
inlinestatic

Register a cross-field validation check (no runtime context needed).

Parameters
checkLambda taking const void* and returning CheckResult.
Returns
Always true.

Definition at line 276 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ registerContextualCheck()

template<typename T >
static bool DNDS::ConfigRegistry< T >::registerContextualCheck ( ContextualCheck  check)
inlinestatic

Register a cross-field validation check that needs runtime context.

Parameters
checkLambda taking const void* and const ConfigContext&, returning CheckResult.
Returns
Always true.

Definition at line 285 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ registerField()

template<typename T >
static bool DNDS::ConfigRegistry< T >::registerField ( FieldMeta  meta)
inlinestatic

Register a single field's metadata.

Parameters
metaThe field descriptor to store.
Returns
Always true (return value kept for legacy compatibility).

Definition at line 267 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ registerPostReadHook()

template<typename T >
static void DNDS::ConfigRegistry< T >::registerPostReadHook ( std::function< void(T &)>  hook)
inlinestatic

Register a post-read hook called after all fields are deserialized. Useful for recomputing derived quantities (e.g. CpGas from gamma and Rgas).

Definition at line 293 of file ConfigRegistry.hpp.

Here is the caller graph for this function:

◆ validate()

template<typename T >
static std::vector< CheckResult > DNDS::ConfigRegistry< T >::validate ( const T &  obj)
inlinestatic

Run all context-free cross-field checks on a struct instance.

Parameters
objThe struct to validate.
Returns
A vector of failed CheckResults. Empty if all checks pass.

Definition at line 399 of file ConfigRegistry.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateKeys()

template<typename T >
static void DNDS::ConfigRegistry< T >::validateKeys ( const nlohmann::ordered_json &  userJson)
inlinestatic

Check that every key in a user-supplied JSON object corresponds to a registered field. Throws on the first unknown key found.

This is the equivalent of EulerP's valid_patch_keys(), but generated automatically from the registry instead of requiring a hand-written default config to compare against.

Parameters
userJsonThe user-supplied JSON object to validate.
Exceptions
std::runtime_errorwith the offending key path.

Definition at line 441 of file ConfigRegistry.hpp.

Here is the call graph for this function:

◆ validateWithContext()

template<typename T >
static std::vector< CheckResult > DNDS::ConfigRegistry< T >::validateWithContext ( const T &  obj,
const ConfigContext ctx 
)
inlinestatic

Run all checks (both context-free and context-aware) on a struct instance.

Parameters
objThe struct to validate.
ctxRuntime context (nVars, dim, model, etc.).
Returns
A vector of failed CheckResults. Empty if all checks pass.

Definition at line 416 of file ConfigRegistry.hpp.

Here is the call graph for this function:

◆ writeToJson()

template<typename T >
static void DNDS::ConfigRegistry< T >::writeToJson ( nlohmann::ordered_json &  j,
const T &  obj 
)
inlinestatic

Serialize all registered fields from a struct into a JSON object.

Fields are written in registration order, producing deterministic key ordering in the output JSON.

Parameters
jDestination JSON object (existing keys are overwritten).
objSource struct instance.

Definition at line 352 of file ConfigRegistry.hpp.

Here is the call graph for this function:

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