ModuleFactory
Source:
ModuleFactory.h
ModuleFactory¶
src/core/util/ModuleFactory.h:36The registry mapping a type name to the function that builds one, which is what lets a preset name a module this build has never instantiated.
Storage grows on demand rather than reserving a fixed cap, which once held a kilobyte of internal memory empty.
Public Static Methods¶
template<typename T> static inline bool registerType(const char * typeName, const char * docPath = "")
: Register a type, capturing everything from one stack probe: what is taken, and how.
static inline bool registerType(const char * typeName, CreateModuleFn fn, size_t classSize = 0, ModuleRole role = ModuleRole::Generic, const char * docPath = "", const char * tags = "")
: Register an entry built by hand, for a factory that is not a simple construction, with no dimensionality to capture.
static inline MoonModule * create(const char * typeName)
: Build a module by type name, or nothing when no such type is registered.
static inline const char * displayNameFor(const char * typeName, ModuleRole role)
: Strip the role noun from a type name, into a shared buffer the caller copies: which suffix each role loses.
static inline uint8_t typeCount()
: how many types are registered
static inline const char * typeName(uint8_t i)
: The registered name at an index, or nothing when it is out of range.
static inline ModuleRole typeRole(uint8_t i)
: The role a type declares, generic when it declares none.
static inline const char * typeDocPath(uint8_t i)
: The documentation page a type names, which the interface links to.
static inline const char * typeTags(uint8_t i)
: The tags a type declares, which the interface renders as its emoji.
static inline uint8_t typeDim(uint8_t i)
: How many dimensions the type declares, or none when it declares no such method.
static inline const char * typeAcceptsChildRoles(uint8_t i)
: Which child roles this type accepts, empty for none, which is how the interface knows what may be added under it.
More info¶
What a registration captures¶
A single stack probe yields the type's size, its role, its tags and its dimensionality, so registering is one line at boot. The path to its documentation page rides along as a flash literal with no per-instance cost, and the interface builds a help link from it.
Dimensionality is captured only when the type declares it, which the effect and modifier bases do and nothing else does. The probe detects the method and reduces its result to a byte rather than naming the return type, so a light-domain concept stays out of core.
Registering the same name twice is a no-op¶
Production registers each type once at boot, but a test fixture registers per construction. Without that, the registry accumulated a duplicate set per test case until the capacity saturated and every later registration in the run failed.
The display name drops the role noun¶
A card's label would otherwise repeat what the role chip already says, so the suffix naming the role is stripped. An effect, a modifier, a layout, a driver and a service each lose their own. A name without the suffix is returned unchanged, and the type name itself stays intact for persistence and lookup.