validate method
Method to validate the configuration of a single field.
Implementation
void validate() {
// reset value must fit within the field's width
if (resetValue.bitLength > width) {
throw CsrValidationException(
'Field $name reset value does not fit within the field.');
}
// there must be at least 1 legal value for a READ_WRITE_LEGAL field
// and the reset value must be legal
// and every legal value must fit within the field's width
if (access == CsrFieldAccess.readWriteLegal) {
if (legalValues.isEmpty) {
throw CsrValidationException(
'Field $name has no legal values but has access READ_WRITE_LEGAL.');
} else if (!legalValues.contains(resetValue)) {
throw CsrValidationException(
'Field $name reset value is not a legal value.');
}
for (final lv in legalValues) {
if (lv.bitLength > width) {
throw CsrValidationException(
'Field $name legal value $lv does not fit within the field.');
}
}
}
}