diff --git a/include/openspace/documentation/verifier.h b/include/openspace/documentation/verifier.h index ae5cba8dbd..2c55fb2dc3 100644 --- a/include/openspace/documentation/verifier.h +++ b/include/openspace/documentation/verifier.h @@ -525,10 +525,6 @@ struct LessVerifier : public OperatorVerifier> { !std::is_base_of::value, "T cannot be StringVerifier" ); static_assert(!std::is_base_of::value, "T cannot be TableVerifier"); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); using OperatorVerifier>::OperatorVerifier; @@ -550,10 +546,6 @@ struct LessEqualVerifier : public OperatorVerifier::value, "T cannot be TableVerifier"); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); using OperatorVerifier>::OperatorVerifier; @@ -575,10 +567,6 @@ struct GreaterVerifier : public OperatorVerifier::value, "T cannot be TableVerifier"); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); using OperatorVerifier>::OperatorVerifier; @@ -602,10 +590,6 @@ struct GreaterEqualVerifier : public OperatorVerifier::value, "T cannot be TableVerifier"); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); using OperatorVerifier>::OperatorVerifier; @@ -754,10 +738,6 @@ struct InRangeVerifier : public T { !std::is_base_of::value, "T cannot be TableVerifier" ); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); /** * Constructs a InRangeVerifier that checks whether the incoming value is of the @@ -816,10 +796,6 @@ struct NotInRangeVerifier : public T { !std::is_base_of::value, "T cannot be TableVerifier" ); - static_assert( - !std::is_base_of::value, - "T cannot be VectorVerifier" - ); /** * Constructs a InRangeVerifier that checks whether the incoming value is of the @@ -1145,6 +1121,8 @@ using StringNotInListVerifier = NotInListVerifier; using IntInRangeVerifier = InRangeVerifier; /// A short-hand definition for a InRangeVerifier with a type check for \c double using DoubleInRangeVerifier = InRangeVerifier; +/// A short-hand definition for a InRangeVerifier with a type check for \c vec2 +using Vec2InRangeVerifier = InRangeVerifier; /// A short-hand definition for a NotInRangeVerifier with a type check for \c int using IntNotInRangeVerifier = NotInRangeVerifier; /// A short-hand definition for a NotInRangeVerifier with a type check for \c double diff --git a/include/openspace/documentation/verifier.inl b/include/openspace/documentation/verifier.inl index 237a7c7286..1b99d785e3 100644 --- a/include/openspace/documentation/verifier.inl +++ b/include/openspace/documentation/verifier.inl @@ -24,9 +24,388 @@ #include +#include #include #include +template <> +struct std::less { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x < b.x && a.x < b.y; + } +}; + +template <> +struct std::less { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z; + } +}; + +template <> +struct std::less { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z && a.w < b.w; + } +}; + +template <> +struct std::less { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x < b.x && a.x < b.y; + } +}; + +template <> +struct std::less { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z; + } +}; + +template <> +struct std::less { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z && a.w < b.w; + } +}; + +template <> +struct std::less { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x < b.x && a.x < b.y; + } +}; + +template <> +struct std::less { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z; + } +}; + +template <> +struct std::less { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x < b.x && a.x < b.y && a.z < b.z && a.w < b.w; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x <= b.x && a.x <= b.y; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z && a.w <= b.w; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x <= b.x && a.x <= b.y; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z && a.w <= b.w; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x <= b.x && a.x <= b.y; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z; + } +}; + +template <> +struct std::less_equal { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x <= b.x && a.x <= b.y && a.z <= b.z && a.w <= b.w; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x > b.x && a.x > b.y; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z && a.w > b.w; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x > b.x && a.x > b.y; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z && a.w > b.w; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x > b.x && a.x > b.y; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z; + } +}; + +template <> +struct std::greater { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x > b.x && a.x > b.y && a.z > b.z && a.w > b.w; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x >= b.x && a.x >= b.y; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z && a.w >= b.w; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x >= b.x && a.x >= b.y; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z && a.w >= b.w; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x >= b.x && a.x >= b.y; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z; + } +}; + +template <> +struct std::greater_equal { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x >= b.x && a.x >= b.y && a.z >= b.z && a.w >= b.w; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x == b.x && a.x == b.y; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z && a.w == b.w; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x == b.x && a.x == b.y; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z && a.w == b.w; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x == b.x && a.x == b.y; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z; + } +}; + +template <> +struct std::equal_to { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x == b.x && a.x == b.y && a.z == b.z && a.w == b.w; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::vec2& a, const glm::vec2& b) const { + return a.x != b.x && a.x != b.y; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::vec3& a, const glm::vec3& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::vec4& a, const glm::vec4& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z && a.w != b.w; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::ivec2& a, const glm::ivec2& b) const { + return a.x != b.x && a.x != b.y; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::ivec3& a, const glm::ivec3& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::ivec4& a, const glm::ivec4& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z && a.w != b.w; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::dvec2& a, const glm::dvec2& b) const { + return a.x != b.x && a.x != b.y; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::dvec3& a, const glm::dvec3& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z; + } +}; + +template <> +struct std::not_equal_to { + bool operator()(const glm::dvec4& a, const glm::dvec4& b) const { + return a.x != b.x && a.x != b.y && a.z != b.z && a.w != b.w; + } +}; + namespace openspace::documentation { template <> @@ -145,7 +524,16 @@ TestResult OperatorVerifier::operator()(const ghoul::Dictionary& di TestResult res = T::operator()(dict, key); if (res.success) { typename T::Type val; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { const double d = dict.value(key); double intPart; bool isInt = modf(d, &intPart) == 0.0; @@ -165,6 +553,7 @@ TestResult OperatorVerifier::operator()(const ghoul::Dictionary& di else { val = dict.value(key); } + if (Operator()(val, value)) { return { true, {}, {} }; } @@ -322,7 +711,30 @@ InRangeVerifier::InRangeVerifier(typename T::Type l, typename T::Type u) : lower(std::move(l)) , upper(std::move(u)) { - ghoul_assert(lower <= upper, "lower must be smaller or equal to upper"); + if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + } + else if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + ghoul_assert(lower.z <= upper.z, "lower must be smaller or equal to upper for z"); + } + else if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + ghoul_assert(lower.z <= upper.z, "lower must be smaller or equal to upper for z"); + ghoul_assert(lower.w <= upper.w, "lower must be smaller or equal to upper for w"); + } + else { + ghoul_assert(lower <= upper, "lower must be smaller or equal to upper"); + } } template @@ -332,7 +744,16 @@ TestResult InRangeVerifier::operator()(const ghoul::Dictionary& dict, TestResult res = T::operator()(dict, key); if (res.success) { typename T::Type val; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { const double d = dict.value(key); double intPart; bool isInt = modf(d, &intPart) == 0.0; @@ -353,7 +774,9 @@ TestResult InRangeVerifier::operator()(const ghoul::Dictionary& dict, val = dict.value(key); } - if (val >= lower && val <= upper) { + if (std::greater_equal()(val, lower) && + std::less_equal()(val, upper)) + { return { true, {}, {} }; } else { @@ -382,7 +805,30 @@ NotInRangeVerifier::NotInRangeVerifier(typename T::Type l, typename T::Type u : lower(std::move(l)) , upper(std::move(u)) { - ghoul_assert(lower <= upper, "lower must be smaller or equal to upper"); + if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + } + else if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + ghoul_assert(lower.z <= upper.z, "lower must be smaller or equal to upper for z"); + } + else if constexpr (std::is_same_v || + std::is_same_v) + { + ghoul_assert(lower.x <= upper.x, "lower must be smaller or equal to upper for x"); + ghoul_assert(lower.y <= upper.y, "lower must be smaller or equal to upper for y"); + ghoul_assert(lower.z <= upper.z, "lower must be smaller or equal to upper for z"); + ghoul_assert(lower.w <= upper.w, "lower must be smaller or equal to upper for w"); + } + else { + ghoul_assert(lower <= upper, "lower must be smaller or equal to upper"); + } } template @@ -391,7 +837,16 @@ TestResult NotInRangeVerifier::operator()(const ghoul::Dictionary& dict, TestResult res = T::operator()(dict, key); if (res.success) { typename T::Type val; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { + val = dict.value(key); + } + else if constexpr (std::is_same_v) { const double d = dict.value(key); double intPart; bool isInt = modf(d, &intPart) == 0.0; @@ -412,7 +867,12 @@ TestResult NotInRangeVerifier::operator()(const ghoul::Dictionary& dict, val = dict.value(key); } - if (val >= lower && val <= upper) { + if (std::less()(val, lower) || + std::greater()(val, upper)) + { + return { true, {}, {} }; + } + else { TestResult r; r.success = false; TestResult::Offense o; @@ -421,9 +881,6 @@ TestResult NotInRangeVerifier::operator()(const ghoul::Dictionary& dict, r.offenses.push_back(o); return r; } - else { - return { true, {}, {} }; - } } else { return res; diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index 23cf99dc8c..5e85eb7235 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -94,8 +94,20 @@ template struct NotInListVerifier; template struct InRangeVerifier; template struct InRangeVerifier; +template struct InRangeVerifier; +template struct InRangeVerifier; +template struct InRangeVerifier; +template struct InRangeVerifier; +template struct InRangeVerifier; +template struct InRangeVerifier; template struct NotInRangeVerifier; template struct NotInRangeVerifier; +template struct NotInRangeVerifier; +template struct NotInRangeVerifier; +template struct NotInRangeVerifier; +template struct NotInRangeVerifier; +template struct NotInRangeVerifier; +template struct NotInRangeVerifier; template struct AnnotationVerifier; diff --git a/support/coding/codegen b/support/coding/codegen index 425a0a224e..ff569901b6 160000 --- a/support/coding/codegen +++ b/support/coding/codegen @@ -1 +1 @@ -Subproject commit 425a0a224e28802f0f2d88c0b2034ee5a473cc3b +Subproject commit ff569901b6e6877c69029e22735796d2bc26b8b3