# Parameterized Objects

`parameterized.h`/`parameterized.cpp` define `Parameterized`, the abstract "has named, gettable/settable parameters" interface implemented by `Model` and `Instance` ([Device, Instance, and Model Base Classes](devbase.md)), and `IStruct<CoreT>`, the concrete adapter that implements it by forwarding to [`Introspection<CoreT>`](introspection.md) over a plain struct. This is the layer that connects the parser's parsed-parameter representation ([PTParameterValue and PTParameterExpression](ptparametervalue.md), [PTParameters and PTParameterMap](ptparameters.md)) to an actual device/model/instance's parameter storage.

## `Parameterized`

Declares the by-index primitives every concrete parameter-holder must implement (`parameterCount()`, `parameterIndex(name)`, `parameterName(ndx)`, `parameterType()`, `getParameter()`, `setParameter()`, `parameterGiven()`) and supplies by-name overloads of most of them in terms of the by-index ones (resolve the name to an index via `parameterIndex()`, then delegate) - a concrete subclass only has to implement the by-index half.

On top of those primitives, `setParameters()` (four overloads) is what actually consumes a parsed parameter list:

- From a `std::vector<PTParameterValue>`: apply each fixed value directly via `setParameter(name, value)`.
- From a `std::vector<PTParameterExpression>`: evaluate each expression with a given [`RpnEvaluator`](rpneval.md)/`RpnEvaluationNetlistContext` (setting the context's parameter id first, for Monte Carlo generator identity - see [the netlist context](rpnevalctx.md)) and apply the result.
- From a whole [`PTParameters`](ptparameters.md): both of the above, values then expressions.
- From a [`PTParameterMap`](ptparameters.md): walks the map's borrowed-or-owned entries, applying values and/or expressions selectively based on the `Write` enum (`All`, `Values`, `Expressions`) - used where a caller wants to apply only the constant part or only the expression part of an assembled parameter set in one pass.

Every overload returns `(ok, changed)`, aggregating each individual `setParameter()`'s "did this actually change" result (see [Structure Introspection](introspection.md)) with `|=`, and stops at the first failure, attaching the failing parameter's [`Loc`](sourceloc.md) to the [`Status`](status.md) before returning.

`dump()` prints every parameter as `name = value`, built from `parameterCount()`/`parameterName()`/`getParameter()` alone - it works for any `Parameterized` subclass without needing its own override.

## `IStruct<CoreT>`

A thin template adapter: `IStruct<CoreT>` owns one `CoreT core_` and implements every `Parameterized` primitive by forwarding straight to `Introspection<CoreT>` with `core_` as the target struct. This is how a device's `ModelParams`/`InstanceParams` struct (see [Instance, and Model Base Classes](devbuiltin.md)) becomes a `Parameterized` object without writing any get/set code of its own - only the plain struct definition plus its `Introspection<CoreT>::setup()` registration ([Structure Introspection](introspection.md)) are needed. `core()` exposes the underlying struct directly for code that wants typed field access instead of going through the `Value`-based interface.
