-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add limits to input attributes #4063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kdrienCG
wants to merge
39
commits into
develop
Choose a base branch
from
feature/kdrienCG/attributeLimitMetadata
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
2f08163
(WIP) add min/max limit to Wrapper.hpp
kdrienCG 45713ea
move min/max optionals in a struct instanciated only when T is limitable
kdrienCG c07a75a
create is_limitable trait
kdrienCG 4c49318
add limits validation for input values
kdrienCG 19d2ae8
add limits modes to limits
kdrienCG fd14de4
implement limits modes in validateLimits()
kdrienCG 32f1586
remove setMinValue() and setMaxValue()
kdrienCG 796bb16
add convenience alias is_limitable_v
kdrienCG 14bda7b
modify outside range message
kdrienCG 581b6d8
add inclusive-exclusive properties using a Bound type
kdrienCG 2590521
Merge branch 'develop' into feature/kdrienCG/attributeLimitMetadata
kdrienCG 7436f3c
support arrays of numbers
kdrienCG a456aca
set validateLimit() to public
kdrienCG 80a9541
add tests
kdrienCG 65779e4
add getDataContext() to the limit validation message
kdrienCG 54053c7
add range to the limit validation message
kdrienCG 7d08bd2
set default mode to Error
kdrienCG ace25d5
move range string creation in the Limits struct
kdrienCG 0f51019
add limits to generated documentation
kdrienCG 3ccdc0f
add GEOS_UNUSED_PARAM to setLimits overload for non-limits
kdrienCG 931c469
modify BCBakerRelPerm to use limits
kdrienCG 7ceb5a6
Merge branch 'develop' into feature/kdrienCG/attributeLimitMetadata
kdrienCG 9d275da
Merge branch 'develop' into feature/kdrienCG/attributeLimitMetadata
kdrienCG 9067eec
remove un-needed inclusions
kdrienCG 600d6cf
rename Bound struct to WrapperBound
kdrienCG 3de9174
rename Limits to WrapperLimits
kdrienCG 2a0af9f
rename file AttributeLimits.hpp to WrapperLimits.hpp
kdrienCG 23d56ce
add doxygen group delimiters for helper methods in WrapperLimits
kdrienCG 1af0ec5
remove static qualifier
kdrienCG 919b359
add check for min <= max when setting a limit
kdrienCG 0022a39
remove includes
kdrienCG d0cb744
move getDataContext() in logger macros
kdrienCG 7affa36
remove implicit conversions for WrapperBound
kdrienCG 718d221
fix: rename conduit node "root" to "problem
kdrienCG 98cdb7f
add schema.xsd.other
kdrienCG 340897a
add new line character to the documentated ranges
kdrienCG 8a68e85
add a namespace for wrapper limits
kdrienCG 07c20e1
rename getter methods
kdrienCG f535f76
Merge branch 'develop' into feature/kdrienCG/attributeLimitMetadata
kdrienCG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| * | ||
| * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC | ||
| * Copyright (c) 2018-2024 TotalEnergies | ||
| * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University | ||
| * Copyright (c) 2023-2024 Chevron | ||
| * Copyright (c) 2019- GEOS/GEOSX Contributors | ||
| * All rights reserved | ||
| * | ||
| * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| */ | ||
|
|
||
|
|
||
| #ifndef GEOS_DATAREPOSITORY_ATTRIBUTELIMITS_HPP_ | ||
| #define GEOS_DATAREPOSITORY_ATTRIBUTELIMITS_HPP_ | ||
|
|
||
| #include "common/DataTypes.hpp" | ||
| #include "common/format/EnumStrings.hpp" | ||
| #include <optional> | ||
| #include <type_traits> | ||
|
|
||
| namespace geos | ||
| { | ||
|
|
||
| namespace dataRepository | ||
| { | ||
|
|
||
| /** | ||
| * @enum LimitsMode | ||
| * @brief Enforcement mode associated with the limits of an attribute | ||
| * | ||
| * - Indicative: the limits are documentation only, no runtime check is performed. | ||
| * - Warning: a value outside the limits emits a runtime warning. | ||
| * - Error: a value outside the limits throws. | ||
| */ | ||
| enum class LimitsMode : integer | ||
| { | ||
| Indicative, | ||
| Warning, | ||
| Error | ||
| }; | ||
|
|
||
| ENUM_STRINGS( LimitsMode, | ||
| "Indicative", | ||
| "Warning", | ||
| "Error" ); | ||
|
|
||
| /** | ||
| * @struct is_limitable | ||
| * @tparam T type to check | ||
| * @brief Trait determining whether attribute limits can be applied to type @p T | ||
| * | ||
| * Limits apply to scalar numeric types (integer, real32, real64, etc.) | ||
| */ | ||
| template< typename T > | ||
| struct is_limitable | ||
| { | ||
| static constexpr bool value = std::is_arithmetic< T >::value; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Convenience variable template alias for is_limitable< T >::value | ||
| */ | ||
| template< typename T > | ||
| inline constexpr bool is_limitable_v = is_limitable< T >::value; | ||
|
|
||
| /** | ||
| * @struct Bound | ||
| * @brief Structure containing informations about an attribute limit. | ||
| */ | ||
| template< typename T > | ||
| struct Bound | ||
| { | ||
| T value; | ||
| bool isInclusive = true; | ||
|
|
||
| /** | ||
| * @brief Bound constructor to write a limit without the "Bound{ ... }" syntax | ||
| * @param value The limit value to set | ||
| * @param isInclusive Wether the limit should be inclusive or not | ||
| * | ||
|
MelReyCG marked this conversation as resolved.
Outdated
|
||
| * @code | ||
| * .setLimits( 0.0, 1.0 ) // where setLimits takes `Bound` parameters, those parameters can | ||
| * // be written only with the value. The isInclusive property will | ||
| * // default to true. | ||
| * @endcode | ||
| */ | ||
| Bound( T v, bool inclusive = true ) | ||
|
MelReyCG marked this conversation as resolved.
Outdated
|
||
| : value( v ), isInclusive( inclusive ) | ||
| {} | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Creates an inclusive limit of @p value | ||
| * @param value The inclusive limit value to set | ||
| */ | ||
| template< typename T > | ||
| Bound< T > inclusive( T value ) | ||
| { | ||
| return Bound< T >{ value, /*isInclusive*/ true }; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Creates an exclusive limit of @p value | ||
| * @param value The inclusive limit value to set | ||
| */ | ||
| template< typename T > | ||
| Bound< T > exclusive( T value ) | ||
| { | ||
| return Bound< T >{ value, /*isInclusive*/ false }; | ||
| } | ||
|
|
||
| /** | ||
| * @struct Limits | ||
| * @brief Storage for the optional min/max bounds of a wrapped value. | ||
| * | ||
| * Specialized so that the members (std::optional< T >) are only instanciated | ||
| * for limitable types. Preventing instantiation of non-limitable types, especially | ||
| * abstract types that can't be instantiated with std::optional< absT >. | ||
| */ | ||
| template< typename T, bool = is_limitable_v< T > > | ||
| struct Limits | ||
|
MelReyCG marked this conversation as resolved.
|
||
| {}; | ||
|
|
||
| template< typename T > | ||
| struct Limits< T, true > | ||
| { | ||
| std::optional< Bound< T > > min; | ||
| std::optional< Bound< T > > max; | ||
| }; | ||
|
|
||
|
|
||
| // Helper methods | ||
|
MelReyCG marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @brief Compare the given value with the min limit, taking account for the inclusive xor exclusive | ||
| * property of the limit. | ||
| * @param value The value to compare to the limit | ||
| * @param minLimit The min limit containing the inclusive | ||
| * @return True if the value is below the min limit, false otherwise | ||
| */ | ||
| template< typename T > | ||
| static bool isValueBelowMin( T const & value, Bound< T > const & minLimit ) | ||
|
MelReyCG marked this conversation as resolved.
Outdated
|
||
| { | ||
| return minLimit.isInclusive ? ( value < minLimit.value ) | ||
| : ( value <= minLimit.value ); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compare the given value with the max limit, taking account for the inclusive xor exclusive | ||
| * property of the limit. | ||
| * @param value The value to compare to the limit | ||
| * @param maxLimit The max limit containing the inclusive | ||
| * @return True if the value is above the max limit, false otherwise | ||
| */ | ||
| template< typename T > | ||
| static bool isValueAboveMax( T const & value, Bound< T > const & maxLimit ) | ||
| { | ||
| return maxLimit.isInclusive ? ( value > maxLimit.value ) | ||
| : ( value >= maxLimit.value ); | ||
| } | ||
|
|
||
| } /* namespace dataRepository */ | ||
|
|
||
| } /* namespace geos */ | ||
|
|
||
| #endif /* GEOS_DATAREPOSITORY_ATTRIBUTELIMITS_HPP_ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.