Skip to content

feat: add limits to input attributes#4063

Open
kdrienCG wants to merge 17 commits into
developfrom
feature/kdrienCG/attributeLimitMetadata
Open

feat: add limits to input attributes#4063
kdrienCG wants to merge 17 commits into
developfrom
feature/kdrienCG/attributeLimitMetadata

Conversation

@kdrienCG
Copy link
Copy Markdown
Contributor

This PR adds the possibility to specify a min and/or a max value to Wrappers attributes.

registerWrapper( viewKeysStruct::fooString(), &m_foo )
  .setLimits( 0.0, 1.0 )  // sets a minimal value of 0.0 and a maximal value of 1.0

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:

  • Indicative: No validation of the input is made, serves as documentation only.
  • Warning: A warning is emitted if the attribute's value is outside the allowed range.
  • Error: An error is emitted if the attribute's value is outside the allowed range.

The mode can be set when specifying the limit, using this syntax:

  .setLimits( 0.0, 1.0, LimitsMode::Warning )

... or it will default to Warning if unset.

Limits also support inclusive and exclusive bounds:

  .setLimits( inclusive( 0.0 ), exclusive( 1.0 ) )

Not using inclusive(...) or exclusive(...) will default to an inclusive limit.


Some examples:

  .setLimits( 0.0, 1.0 )  // [0.0, 1.0]
  .setLimits( 0.0, std::nullopt )  // [0.0, +inf)
  .setLimits( inclusive( 0.0 ), std::nullopt )  // [0.0, +inf)
  .setLimits( std::nullopt, exclusive( 0.0 ) )  // (-inf, 0.0)

@kdrienCG kdrienCG self-assigned this May 20, 2026
@kdrienCG kdrienCG added the type: feature New feature or request label May 20, 2026
@kdrienCG kdrienCG marked this pull request as ready for review May 20, 2026 09:06
Copy link
Copy Markdown
Contributor

@dkachuma dkachuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this idea. It will simplify greatly some of the boiler plate validation code.

Will this work for lists of numbers?

return;
}

string const msg = GEOS_FMT( "Value {} for attribute '{}' is outside the allowed range.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the range to the message.

Also will this show the full context, not just the field name? Should we use getDataContext()?

std::enable_if_t< is_limitable_v< U >, Wrapper< T > & >
setLimits( std::optional< Bound< T > > min,
std::optional< Bound< T > > max,
LimitsMode mode = LimitsMode::Warning )
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LimitsMode mode = LimitsMode::Warning )
LimitsMode mode = LimitsMode::Error )

I think error is a better default here (most cases would be errors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants