feat: add limits to input attributes#4063
Conversation
Will not compile due to std::optional instantiation (used by m_minValue and m_maxVavlue) for abstract types like PartitionBase
setLimits() has the same capabilities and should be the only one kept.
dkachuma
left a comment
There was a problem hiding this comment.
I really like this idea. It will simplify greatly some of the boiler plate validation code.
Will this work for lists of numbers?
This part may be refactored, to build the range string somewhere else
MelReyCG
left a comment
There was a problem hiding this comment.
Please apply this feature on at least one (maybe basic) 'Group' to demonstrate usage (array and scalar ideally).
| #include "common/format/Format.hpp" | ||
| #include "common/logger/Logger.hpp" |
There was a problem hiding this comment.
un-needed inclusion, beware of clangd ;)
There was a problem hiding this comment.
There are still some,
<type_traits>, <optional>, maybe some more
| * // default to true. | ||
| * @endcode | ||
| */ | ||
| Bound( T v, bool inclusive = true ) |
There was a problem hiding this comment.
do we want this constructor explicit?
There was a problem hiding this comment.
It was made not explicit so we can write .setLimits( 0.0, 1.0 ) instead of .setLimits( WrapperBound{ 0.0 }, WrapperBound{ 1.0 } )
There was a problem hiding this comment.
That implicit conversion from any double to your type, at this (critical) level of the inclusion hierarchy, may cause the compiler to try undesired casts.
Why not an overload or a different signature for setLimits()?
Applied to |
| #include "common/format/Format.hpp" | ||
| #include "common/logger/Logger.hpp" |
There was a problem hiding this comment.
There are still some,
<type_traits>, <optional>, maybe some more
| string const msg = GEOS_FMT( "Value {} for attribute '{}' is outside the allowed range {}.", | ||
| value, getDataContext(), m_limits.getRangeStr() ); | ||
|
|
||
| switch( m_limitsMode ) | ||
| { | ||
| case WrapperLimitsMode::Warning: | ||
| GEOS_WARNING( msg ); | ||
| break; | ||
|
|
||
| case WrapperLimitsMode::Error: | ||
| GEOS_THROW( msg, InputError ); | ||
| break; | ||
|
|
||
| default: | ||
| GEOS_LOG_RANK_0( "Unimplemented WrapperLimitsMode" ); | ||
| break; |
There was a problem hiding this comment.
What gives the following in the log?
| string const msg = GEOS_FMT( "Value {} for attribute '{}' is outside the allowed range {}.", | |
| value, getDataContext(), m_limits.getRangeStr() ); | |
| switch( m_limitsMode ) | |
| { | |
| case WrapperLimitsMode::Warning: | |
| GEOS_WARNING( msg ); | |
| break; | |
| case WrapperLimitsMode::Error: | |
| GEOS_THROW( msg, InputError ); | |
| break; | |
| default: | |
| GEOS_LOG_RANK_0( "Unimplemented WrapperLimitsMode" ); | |
| break; | |
| string const msg = GEOS_FMT( "Value {} is outside the allowed range {}.", | |
| value, m_limits.getRangeStr() ); | |
| switch( m_limitsMode ) | |
| { | |
| case WrapperLimitsMode::Warning: | |
| GEOS_WARNING( msg, getDataContext() ); | |
| break; | |
| case WrapperLimitsMode::Error: | |
| GEOS_THROW( msg, InputError, getDataContext() ); | |
| break; | |
| default: | |
| GEOS_LOG_RANK_0( "Unimplemented WrapperLimitsMode" ); | |
| break; |
| * // default to true. | ||
| * @endcode | ||
| */ | ||
| Bound( T v, bool inclusive = true ) |
There was a problem hiding this comment.
That implicit conversion from any double to your type, at this (critical) level of the inclusion hierarchy, may cause the compiler to try undesired casts.
Why not an overload or a different signature for setLimits()?
This PR adds the possibility to specify a min and/or a max value to
Wrappers attributes.The goal is to provide the foundations for two follow-up efforts planned in future PRs:
Usage:
This will serve as a documentation for values, but also prevents users from making typos that could lead to wrong results, taking time to find (if noticed).
The limits come with 3 modes:
The mode can be set when specifying the limit, using this syntax:
... or it will default to
Errorif unset.Limits also support inclusive and exclusive bounds:
Not using
inclusive(...)orexclusive(...)will default to an inclusive limit.Some examples: