LogicEnum<T extends Enum>.withMapping constructor
Creates a signal using the explicit hardware encodings in mapping.
The width is inferred from the member count and encoding values unless
width is provided. If reserveDefinitionName is true, generated type
and member names cannot be uniquified around collisions.
Implementation
LogicEnum.withMapping(
Map<T, dynamic> mapping, {
int? width,
super.name,
super.naming,
String? definitionName,
super.reserveDefinitionName,
}) : super(
width: _computeWidth(requestedWidth: width, mapping: mapping),
definitionName: definitionName ?? T.toString()) {
this.mapping =
Map.unmodifiable(_computeMapping(mapping: mapping, width: this.width));
_wire._constrainValue((value) {
if (value.isFloating) {
return LogicValue.filled(this.width, LogicValue.z);
}
if (!value.isValid) {
return LogicValue.filled(this.width, LogicValue.x);
}
if (!this.mapping.containsValue(value)) {
return LogicValue.filled(this.width, LogicValue.x);
}
return value;
});
}