7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Add std::optional<int> support to property validators

The properties using units seem to return std::optional<int> values,
so the validators need to properly handle these to unwrap them.
This commit is contained in:
Ian McInerney 2025-01-06 11:43:02 +00:00
parent 660f5bad21
commit ac7ebdd94d

View File

@ -106,9 +106,15 @@ public:
template<int Min, int Max>
static VALIDATOR_RESULT RangeIntValidator( const wxAny&& aValue, EDA_ITEM* aItem )
{
wxASSERT_MSG( aValue.CheckType<int>(), "Expecting int-containing value" );
wxASSERT_MSG( aValue.CheckType<int>() || aValue.CheckType<std::optional<int>>(),
"Expecting int-containing value" );
int val = aValue.As<int>();
int val = 0;
if( aValue.CheckType<int>() )
val = aValue.As<int>();
else if( aValue.CheckType<std::optional<int>>() )
val = aValue.As<std::optional<int>>().value_or( 0 );
if( val > Max )
return std::make_unique<VALIDATION_ERROR_TOO_LARGE<int>>( val, Max );
@ -120,9 +126,15 @@ public:
static VALIDATOR_RESULT PositiveIntValidator( const wxAny&& aValue, EDA_ITEM* aItem )
{
wxASSERT_MSG( aValue.CheckType<int>(), "Expecting int-containing value" );
wxASSERT_MSG( aValue.CheckType<int>() || aValue.CheckType<std::optional<int>>(),
"Expecting int-containing value" );
int val = aValue.As<int>();
int val = 0;
if( aValue.CheckType<int>() )
val = aValue.As<int>();
else if( aValue.CheckType<std::optional<int>>() )
val = aValue.As<std::optional<int>>().value_or( 0 );
if( val < 0 )
return std::make_unique<VALIDATION_ERROR_TOO_SMALL<int>>( val, 0 );