Variant
- Updated operator> to handle trivial values.
This commit is contained in:
@@ -556,10 +556,15 @@ bool Variant::operator> (const Variant& other) const
|
|||||||
case type_string:
|
case type_string:
|
||||||
switch (right._type)
|
switch (right._type)
|
||||||
{
|
{
|
||||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
case type_unknown:
|
||||||
case type_boolean: right.cast (type_string); return left._string > right._string;
|
throw std::string ("Cannot compare unknown type");
|
||||||
case type_integer: right.cast (type_string); return left._string > right._string;
|
|
||||||
case type_real: right.cast (type_string); return left._string > right._string;
|
case type_boolean:
|
||||||
|
case type_integer:
|
||||||
|
case type_real:
|
||||||
|
right.cast (type_string);
|
||||||
|
return left._string > right._string;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
if (left.source () == "priority" || right.source () == "priority")
|
if (left.source () == "priority" || right.source () == "priority")
|
||||||
{
|
{
|
||||||
@@ -570,36 +575,64 @@ bool Variant::operator> (const Variant& other) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (left.trivial () || right.trivial ())
|
||||||
|
return false;
|
||||||
|
|
||||||
return left._string> right._string;
|
return left._string> right._string;
|
||||||
}
|
}
|
||||||
case type_date: left.cast (type_date); return left._date > right._date;
|
case type_date:
|
||||||
case type_duration: left.cast (type_duration); return left._duration > right._duration;
|
if (left.trivial () || right.trivial ())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
left.cast (type_date);
|
||||||
|
return left._date > right._date;
|
||||||
|
|
||||||
|
case type_duration:
|
||||||
|
if (left.trivial () || right.trivial ())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
left.cast (type_duration);
|
||||||
|
return left._duration > right._duration;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case type_date:
|
case type_date:
|
||||||
switch (right._type)
|
switch (right._type)
|
||||||
{
|
{
|
||||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
case type_unknown:
|
||||||
case type_boolean: right.cast (type_date); return left._date > right._date;
|
throw std::string ("Cannot compare unknown type");
|
||||||
case type_integer: right.cast (type_date); return left._date > right._date;
|
|
||||||
case type_real: right.cast (type_date); return left._date > right._date;
|
case type_boolean:
|
||||||
case type_string: right.cast (type_date); return left._date > right._date;
|
case type_integer:
|
||||||
case type_date: return left._date > right._date;
|
case type_real:
|
||||||
case type_duration: return left._date > right._duration;
|
case type_string:
|
||||||
|
case type_date:
|
||||||
|
case type_duration:
|
||||||
|
if (left.trivial () || right.trivial ())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
right.cast (type_date);
|
||||||
|
return left._date > right._date;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case type_duration:
|
case type_duration:
|
||||||
switch (right._type)
|
switch (right._type)
|
||||||
{
|
{
|
||||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
case type_unknown:
|
||||||
case type_boolean: right.cast (type_duration); return left._duration > right._duration;
|
throw std::string ("Cannot compare unknown type");
|
||||||
case type_integer: right.cast (type_duration); return left._duration > right._duration;
|
|
||||||
case type_real: right.cast (type_duration); return left._duration > right._duration;
|
case type_boolean:
|
||||||
case type_string: right.cast (type_duration); return left._duration > right._duration;
|
case type_integer:
|
||||||
case type_date: return left._duration > right._date;
|
case type_real:
|
||||||
case type_duration: return left._duration > right._duration;
|
case type_string:
|
||||||
|
case type_date:
|
||||||
|
case type_duration:
|
||||||
|
if (left.trivial () || right.trivial ())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
right.cast (type_duration);
|
||||||
|
return left._duration > right._duration;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user