mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 02:19:01 +08:00
Disable nil_value() for enum and remove NilValue<Enum>.
Fixes: https://github.com/prusa3d/PrusaSlicer/issues/12455.
This commit is contained in:
parent
718afc9876
commit
58e32e173b
@ -324,7 +324,6 @@ typedef const ConfigOption* ConfigOptionConstPtr;
|
||||
template<class T, class En = void> struct NilValueTempl
|
||||
{
|
||||
using NilType = T;
|
||||
static_assert(always_false<T>::value, "Type has no well defined nil value");
|
||||
};
|
||||
|
||||
template<class T> struct NilValueTempl<T, std::enable_if_t<std::is_integral_v<T>, void>> {
|
||||
@ -334,14 +333,6 @@ template<class T> struct NilValueTempl<T, std::enable_if_t<std::is_integral_v<T>
|
||||
|
||||
template<> struct NilValueTempl<bool> : public NilValueTempl<int>{};
|
||||
|
||||
// For enums the nil is the max value of the underlying type.
|
||||
template<class T>
|
||||
struct NilValueTempl<T, std::enable_if_t<std::is_enum_v<T>, void>>
|
||||
{
|
||||
using NilType = T;
|
||||
static constexpr auto value = static_cast<T>(std::numeric_limits<std::underlying_type_t<T>>::max());
|
||||
};
|
||||
|
||||
template<class T> struct NilValueTempl<T, std::enable_if_t<std::is_floating_point_v<T>, void>> {
|
||||
using NilType = T;
|
||||
static constexpr auto value = std::numeric_limits<T>::quiet_NaN();
|
||||
@ -375,7 +366,7 @@ public:
|
||||
T value;
|
||||
explicit ConfigOptionSingle(T value) : value(std::move(value)) {}
|
||||
operator T() const { return this->value; }
|
||||
|
||||
|
||||
void set(const ConfigOption *rhs) override
|
||||
{
|
||||
if (rhs->type() != this->type())
|
||||
@ -440,7 +431,8 @@ public:
|
||||
|
||||
bool nullable() const override { return NULLABLE; }
|
||||
|
||||
static constexpr NilType<T> nil_value() { return NilValue<T>(); }
|
||||
template<bool IsNullable = NULLABLE, typename std::enable_if_t<IsNullable, bool> = true>
|
||||
static constexpr NilType<T> nil_value() { return NilType<T>(); }
|
||||
|
||||
// A scalar is nil, or all values of a vector are nil.
|
||||
bool is_nil() const override
|
||||
@ -717,7 +709,7 @@ public:
|
||||
std::istringstream iss(str);
|
||||
|
||||
if (str == "nil") {
|
||||
if (NULLABLE)
|
||||
if constexpr (NULLABLE)
|
||||
this->value = this->nil_value();
|
||||
else
|
||||
throw ConfigurationError("Deserializing nil into a non-nullable object");
|
||||
@ -890,7 +882,8 @@ public:
|
||||
std::string serialize() const override
|
||||
{
|
||||
std::ostringstream ss;
|
||||
if (this->value == this->nil_value()) {
|
||||
|
||||
if (this->value == std::numeric_limits<int>::max()) {
|
||||
if (NULLABLE)
|
||||
ss << "nil";
|
||||
else
|
||||
@ -907,7 +900,7 @@ public:
|
||||
std::istringstream iss(str);
|
||||
|
||||
if (str == "nil") {
|
||||
if (NULLABLE)
|
||||
if constexpr (NULLABLE)
|
||||
this->value = this->nil_value();
|
||||
else
|
||||
throw ConfigurationError("Deserializing nil into a non-nullable object");
|
||||
|
Loading…
x
Reference in New Issue
Block a user