DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ConfigRegistry.hpp File Reference

Per-type configuration field registry with JSON serialization, JSON Schema (draft-07) emission, and cross-field validation. More...

#include "Defines.hpp"
#include "JsonUtil.hpp"
#include "Errors.hpp"
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <optional>
#include <stdexcept>
#include <fmt/core.h>
Include dependency graph for ConfigRegistry.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DNDS::CheckResult
 Result of a single validation check. More...
 
struct  DNDS::ConfigContext
 Runtime context supplied to context-aware validation checks. More...
 
struct  DNDS::FieldMeta
 Descriptor for a single configuration field. More...
 
class  DNDS::ConfigRegistry< T >
 Per-type singleton registry of config field metadata and validation checks. More...
 

Namespaces

namespace  DNDS
 the host side operators are provided as implemented
 

Typedefs

using DNDS::CrossFieldCheck = std::function< CheckResult(const void *obj)>
 A cross-field validation check that does not require runtime context.
 
using DNDS::ContextualCheck = std::function< CheckResult(const void *obj, const ConfigContext &ctx)>
 A cross-field validation check that requires runtime context.
 

Enumerations

enum class  DNDS::ConfigTypeTag {
  DNDS::Bool , DNDS::Int , DNDS::Real , DNDS::String ,
  DNDS::Enum , DNDS::Array , DNDS::Object , DNDS::ArrayOfObjects ,
  DNDS::MapOfObjects , DNDS::Json
}
 Enumerates the JSON Schema type associated with a config field. More...
 

Detailed Description

Per-type configuration field registry with JSON serialization, JSON Schema (draft-07) emission, and cross-field validation.

Overview

ConfigRegistry<T> is a singleton that stores, for each config struct T:

  • An ordered list of FieldMeta descriptors (one per JSON-visible member).
  • Lists of cross-field checks (context-free and context-aware).

The registry is populated lazily on first use by the DNDS_DECLARE_CONFIG machinery in ConfigParam.hpp. It never affects the layout or trivial copyability of T itself — all metadata lives in static singletons, so T remains a POD struct safe for CUDA device views.

Design Principles

  1. POD structs are untouched. DNDS_DECLARE_CONFIG generates only static methods and friend functions. The struct has no base class, no virtual methods, and no added instance data. Structs embedded in CUDA device views (e.g. FiniteVolumeSettings) remain trivially copyable.
  2. Type-erased field accessors. Each FieldMeta stores std::function lambdas for read, write, and schema emission. These capture a pointer-to-member and live only in host-side static storage.
  3. Per-field + cross-field validation. Single-field constraints (range, enum membership) are checked inside each field's readField closure at parse time. Multi-field constraints (mutual exclusion, conditional requirements, derived-value consistency) are registered as standalone check lambdas via config.check() / config.check_ctx().
  4. Context-aware validation. Some checks depend on runtime values not stored in the config (e.g. nVars, model). These use ConfigContext, passed to validateWithContext().
  5. Incremental adoption. Sections using the old DNDS_NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_ORDERED_JSON keep working. The --emit-schema flag falls back to type-inference from default JSON for unmigrated sections. Migrated and unmigrated sections coexist.

Usage

Users interact with this file indirectly through ConfigParam.hpp:

struct TimeMarchControl
{
real dtImplicit = 1e100;
int nTimeStep = 1000000;
DNDS_DECLARE_CONFIG(TimeMarchControl)
{
DNDS_FIELD(dtImplicit, "Max time step; 1e100 for steady",
DNDS_FIELD(nTimeStep, "Max number of time steps",
}
};
#define DNDS_FIELD(name_, desc_,...)
Register a field inside a DNDS_DECLARE_CONFIG body.
#define DNDS_DECLARE_CONFIG(Type_)
Open a config section registration body.
RangeTag range(double min)
Create a minimum-only range constraint.

Direct registry access (for tooling, --emit-schema, etc.):

static nlohmann::ordered_json emitSchema(const std::string &sectionDescription="")
Emit a JSON Schema (draft-07) object describing all registered fields.
static std::vector< CheckResult > validate(const T &obj)
Run all context-free cross-field checks on a struct instance.

Definition in file ConfigRegistry.hpp.