gtopt/unit_registry.hpp file

Runtime-loadable dictionary of (class, canonical, dialect) → unit.

Companion to names_registry.hpp. Loads share/gtopt/unit_dialects.json (or an embedded fallback) and exposes a (class, canonical, dialect) → unit accessor. The unit strings are free-form physical-unit literals like "MW", "USD/MWh", "m3/s", "Mm3" — they are not parsed into a unit algebra; downstream code uses them only for diagnostics (--list-dialects --units), mismatch warnings under --naming-dialect, and (eventually) auto-conversion by a separate unit engine.

Resolution order mirrors find_names_file():

  1. $GTOPT_UNIT_DIALECTS_FILE — explicit override file (logged at info level; warns when it has fewer entries than the compiled-in dictionary)
  2. Compiled-in dictionary (share/gtopt/unit_dialects.json embedded at configure time — always matches the binary)
  3. Empty registry (graceful degradation; every lookup returns nullopt and no unit-aware behaviour fires)

Install / user share dirs are never probed, so a stale installed copy cannot shadow the running binary's dictionary.

The registry is loaded once on first access (singleton); subsequent lookups are O(log n) via gtopt::flat_map.

Namespaces

namespace gtopt

Classes

class gtopt::UnitRegistry