ParameterSchema Library
Overview
ParameterSchema is a lightweight, non-Qt static library at src/ParameterSchema/ that provides compile-time parameter schema extraction for reflect-cpp structs. It is a shared dependency used by both TransformsV2 (for transform parameter forms) and the Command Architecture (for command introspection and guided pipeline editors).
The library has no Qt dependency and depends only on reflect-cpp and the C++ standard library.
Source Location
src/ParameterSchema/
├── CMakeLists.txt
├── ParameterSchema.hpp — All types, template function, and helper declarations
└── ParameterSchema.cpp — Non-template helper implementations
Key Types
ParameterFieldDescriptor
Describes a single field in a parameter struct at runtime:
| Field | Type | Description |
|---|---|---|
name |
std::string |
Reflect-cpp field name (snake_case) |
type_name |
std::string |
Underlying type: "float", "double", "int", "std::string", "bool", "enum", "variant", or "vector<...>" (e.g. "vector<std::string>") |
raw_type_name |
std::string |
Full raw type string from reflect-cpp |
display_name |
std::string |
Human-readable “Title Case” label |
display_order |
int |
Sequential field index (0-based) assigned during extraction |
min_value / max_value |
std::optional<double> |
From rfl::Validator constraints |
is_exclusive_min/max |
bool |
Exclusive vs. inclusive bound |
allowed_values |
std::vector<std::string> |
For enum-like string fields; auto-populated for enum class fields |
default_value_json |
std::optional<std::string> |
Default value as JSON string |
tooltip |
std::string |
UI hint (from ParameterUIHints) |
group |
std::string |
Grouping label for the UI |
is_advanced |
bool |
Collapsed by default in the UI |
is_hidden |
bool |
Omit the form row in AutoParamWidget but still serialize the field (hidden widgets keep default state) |
is_optional |
bool |
True for std::optional<T> fields |
is_bound |
bool |
True if typically populated from a value store |
dynamic_combo |
bool |
If true, create QComboBox even with empty allowed_values |
include_none_sentinel |
bool |
If true, prepend “(None)” sentinel to combo (maps to "" in JSON) |
path_field_kind |
PathFieldKind |
None, FilePath, or DirectoryPath for browse-enabled path fields |
file_dialog_id |
std::string |
AppFileDialog session id when path_field_kind != None |
is_vector |
bool |
True for std::vector<T> fields |
vector_element_type |
std::string |
Element type for vector fields (e.g. "std::string", "int", "float", "double") |
is_variant |
bool |
True for rfl::TaggedUnion fields |
variant_discriminator |
std::string |
Tag field name (e.g. "model") |
variant_alternatives |
std::vector<VariantAlternative> |
One entry per union alternative |
ParameterSchema
Holds the complete schema for one parameter struct:
struct ParameterSchema {
std::string params_type_name;
std::vector<ParameterFieldDescriptor> fields;
ParameterFieldDescriptor * field(std::string const & name);
ParameterFieldDescriptor const * field(std::string const & name) const;
};ParameterUIHints<T>
A template trait struct for providing custom UI annotations. Specialize it alongside a params struct to add tooltips, allowed values, grouping, and ordering without modifying the struct itself:
template<>
struct ParameterUIHints<MyParams> {
static void annotate(ParameterSchema & schema) {
schema.field("threshold")->tooltip = "Detection threshold (0.0–1.0)";
schema.field("mode")->allowed_values = {"Fast", "Accurate"};
}
};extractParameterSchema<T>()
The core function template. Enumerates all fields of a reflect-cpp struct at compile time, parses type strings (stripping std::optional<>, rfl::Validator<> wrappers), extracts validator constraints, and applies any ParameterUIHints<T> specialization:
ParameterSchema schema = extractParameterSchema<MyParams>();This is typically called once per type — either at static registration time (TransformsV2) or lazily by the command factory (Command Architecture).
std::vector<T> Auto-Detection
std::vector<T> fields (where T is std::string, int, float, or double) are automatically detected at compile time using detail::is_std_vector_v<T>. When detected:
is_vectoris set totruevector_element_typeis set to the element type name (e.g."std::string","int","float")type_nameis set to"vector<element_type>"(e.g."vector<std::string>")- Default values serialize as JSON arrays (e.g.
["ch1","ch2"]or[0,1,2])
struct MultiChannelParams {
std::vector<std::string> channels; // → multi-select list or free-form CSV
std::vector<int> columns = {0, 1, 2}; // → CSV line edit with defaults
std::vector<float> thresholds; // → CSV line edit
};AutoParamWidget renders vector fields in two modes:
Multi-select list — When
vector_element_type == "std::string"anddynamic_combo == true, aQListWidgetwith checkable items is created. Items are populated at runtime viaupdateAllowedValues(). All items are checked by default on first population. The list has a maximum height of 200px and scrolls for larger lists.CSV line edit — For numeric vectors (
int,float,double) or free-form string vectors (withoutdynamic_combo), aQLineEditis shown. Values are entered as comma-separated text (e.g."0, 1, 2"). Default values from the struct are pre-populated.
Both modes serialize to/from JSON arrays via toJson() and fromJson().
ParameterUIHints for Vectors
Use dynamic_combo = true on a std::vector<std::string> field to enable the multi-select list mode. The allowed values are populated at runtime by updateAllowedValues():
template<>
struct ParameterUIHints<MultiChannelParams> {
static void annotate(ParameterSchema & schema) {
schema.field("channels")->dynamic_combo = true;
}
};Enum Class Auto-Detection
C++ enum class fields (including std::optional<enum class>) are automatically detected at compile time using rfl::to_view() and std::is_enum_v. When detected:
type_nameis set to"enum"allowed_valuesis populated with all enumerator names viarfl::get_enumerator_array<E>()- Default values serialize as JSON strings (e.g.
"fast"forMyEnum::fast) - No
ParameterUIHintsspecialization is needed
enum class MotionModel { linear, sinusoidal, brownian };
struct MyParams {
MotionModel model = MotionModel::linear; // → combo box with 3 entries
std::optional<MotionModel> alt_model; // → gated combo box
};Limitations:
- Scoped enum underlying values are scanned in [0, 127] by default (reflect-cpp compile-time name extraction via
rfl::get_enumerator_array<E>()). - The enum must be in a named namespace (anonymous namespaces break reflect-cpp’s compile-time name extraction).
Tagged Variant (Discriminated Union) Auto-Detection
rfl::TaggedUnion fields are automatically detected at compile time using a is_tagged_union_v<T> SFINAE trait (checks for T::VariantType and T::discrimininator_). When detected:
type_nameis set to"variant"is_variantis set totruevariant_discriminatoris set to the compile-time discriminator string (e.g."model")variant_alternativesis populated with oneVariantAlternativeper union alternative, each containing the tag name and a recursively-extractedParameterSchemafor that alternative’s fieldsallowed_valuesis auto-populated with the tag names (for combo box rendering)default_value_jsonis the full JSON serialization of the default-constructed variant (including discriminator and sub-fields)
struct LinearMotionParams {
float velocity_x = 1.0f;
float velocity_y = 0.0f;
};
struct SinusoidalMotionParams {
float amplitude_x = 0.0f;
float amplitude_y = 0.0f;
float frequency_x = 0.0f;
float frequency_y = 0.0f;
float phase_x = 0.0f;
float phase_y = 0.0f;
};
struct BrownianMotionParams {
float diffusion = 1.0f;
uint64_t seed = 42;
};
using MotionVariant = rfl::TaggedUnion<
"model",
LinearMotionParams,
SinusoidalMotionParams,
BrownianMotionParams>;
struct MovingPointParams {
float start_x = 100.0f;
int num_frames = 100;
MotionVariant motion = LinearMotionParams{}; // ← variant field
};JSON output:
{
"start_x": 100.0,
"num_frames": 100,
"motion": {
"model": "LinearMotionParams",
"velocity_x": 1.0,
"velocity_y": 0.0
}
}AutoParamWidget renders variant fields as a combo box (discriminator) above a QStackedWidget containing one sub-form per alternative. Changing the combo box selection swaps the visible sub-form. Each combo item stores its stack index in Qt::UserRole so that updateVariantAlternatives() can filter visible alternatives without breaking the combo-to-stack mapping.
Runtime Variant Filtering
Call AutoParamWidget::updateVariantAlternatives() to show only a subset of alternatives at runtime (e.g. when only some encoder types are valid for the current model):
widget->updateVariantAlternatives("motion", {"LinearMotionParams", "SinusoidalMotionParams"});If the currently selected alternative is hidden, the widget switches to the first visible alternative. See AutoParam System for full behavior.
Important: rfl::TaggedUnion has no default constructor. The variant field in your params struct must have a default member initializer that provides one of the alternative types (e.g. = LinearMotionParams{}).
Limitations:
- Only
rfl::TaggedUnion(internally tagged) variants are supported.std::variantwithout a tag is not auto-detected. - Alternative structs must be default-constructible.
VariantAlternative
Describes one alternative in a variant field:
| Field | Type | Description |
|---|---|---|
tag |
std::string |
Discriminator value (struct name, e.g. "LinearMotionParams") |
schema |
std::unique_ptr<ParameterSchema> |
Sub-schema for this alternative’s fields |
std::unique_ptr is used to break the circular type dependency (VariantAlternative → ParameterSchema → ParameterFieldDescriptor → VariantAlternative).
Helper Functions
| Function | Description |
|---|---|
snakeCaseToDisplay(s) |
"scale_factor" → "Scale Factor" |
parseUnderlyingType(s) |
Strips optional<> / Validator<> to return "float", "int", "vector<int>", etc. |
isOptionalType(s) |
True if the type string contains "optional" |
isVectorType(s) |
True if the type string contains "vector" |
hasValidator(s) |
True if the type string contains "Validator" |
extractConstraints(s) |
Returns ConstraintInfo with min_value, max_value, exclusivity flags |
CMake Integration
The CMake target is WhiskerToolbox::ParameterSchema. Link it directly when you need schema extraction without pulling in TransformsV2:
target_link_libraries(MyTarget PUBLIC WhiskerToolbox::ParameterSchema)TransformsV2 already links ParameterSchema publicly, so any target that links TransformsV2 inherits access to the ParameterSchema headers automatically.
Namespace
All types live in WhiskerToolbox::Transforms::V2. The namespace was preserved during the extraction from TransformsV2 to avoid breaking all existing code that uses using namespace WhiskerToolbox::Transforms::V2.
Include Path
#include "ParameterSchema/ParameterSchema.hpp"The library’s target_include_directories exposes src/ as the include root, so this include works from any target that links WhiskerToolbox::ParameterSchema (directly or transitively through TransformsV2).