- Updated operator_partial to handle trivial values.
This commit is contained in:
Paul Beckingham 2014-06-16 18:42:11 -04:00
parent c1a9e1e452
commit e0bca6c4ad

View file

@ -961,8 +961,10 @@ bool Variant::operator_partial (const Variant& other) const
case type_integer: left.cast (type_integer); return left._integer == right._integer;
case type_real: left.cast (type_real); return left._real == right._real;
case type_string: left.cast (type_string); return left._string == right._string;
// TODO Implement same-day comparison.
case type_date: left.cast (type_date); return left._date == right._date;
case type_duration: left.cast (type_duration); return left._duration == right._duration;
}
break;
@ -975,8 +977,10 @@ bool Variant::operator_partial (const Variant& other) const
case type_integer: return left._integer == right._integer;
case type_real: left.cast (type_real); return left._real == right._real;
case type_string: left.cast (type_string); return left._string == right._string;
// TODO Implement same-day comparison.
case type_date: left.cast (type_date); return left._date == right._date;
case type_duration: left.cast (type_duration); return left._duration == right._duration;
}
break;
@ -984,76 +988,105 @@ bool Variant::operator_partial (const Variant& other) const
case type_real:
switch (right._type)
{
case type_unknown: throw std::string ("Cannot equate unknown type");
case type_boolean: right.cast (type_real); return left._real == right._real;
case type_integer: right.cast (type_real); return left._real == right._real;
case type_real: return left._real == right._real;
case type_string: left.cast (type_string); return left._string == right._string;
case type_unknown:
throw std::string ("Cannot equate unknown type");
case type_boolean:
case type_integer:
case type_real:
right.cast (type_real);
return left._real == right._real;
case type_string:
left.cast (type_string);
return left._string == right._string;
// TODO Implement same-day comparison.
case type_date: left.cast (type_date); return left._date == right._date;
case type_duration: left.cast (type_duration); return left._duration == right._duration;
case type_date:
left.cast (type_date);
return left._date == right._date;
case type_duration:
left.cast (type_duration);
return left._duration == right._duration;
}
break;
case type_string:
switch (right._type)
{
case type_unknown: throw std::string ("Cannot equate unknown type");
case type_boolean: right.cast (type_string); return left._string == right._string;
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_unknown:
throw std::string ("Cannot equate unknown type");
case type_boolean:
case type_integer:
case type_real:
case type_string:
{
int left_length = left._string.length ();
if (left_length == 0)
if (left.trivial () || right.trivial ())
return false;
int right_length = right._string.length ();
if (right_length == 0)
right.cast (type_string);
if (left._string.length () < right._string.length ())
return false;
if (left_length < right_length)
return false;
return left._string.substr (0, right._string.length ()) == right._string;
return left._string.substr (0, right_length) == right._string;
}
// TODO Implement same-day comparison.
case type_date: left.cast (type_date); return left._date == right._date;
case type_duration: left.cast (type_duration); return left._duration == right._duration;
case type_date:
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;
case type_date:
switch (right._type)
{
case type_unknown: throw std::string ("Cannot equate unknown type");
case type_unknown:
throw std::string ("Cannot equate unknown type");
// TODO Implement same-day comparison.
case type_boolean: right.cast (type_date); return left._date == right._date;
// TODO Implement same-day comparison.
case type_integer: right.cast (type_date); return left._date == right._date;
// TODO Implement same-day comparison.
case type_real: right.cast (type_date); return left._date == right._date;
// TODO Implement same-day comparison.
case type_string: right.cast (type_date); return left._date == right._date;
// TODO Implement same-day comparison.
case type_date: return left._date == right._date;
// TODO Implement same-day comparison.
case type_duration: return left._date == right._duration;
case type_boolean:
case type_integer:
case type_real:
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;
case type_duration:
switch (right._type)
{
case type_unknown: throw std::string ("Cannot equate unknown type");
case type_boolean: right.cast (type_duration); return left._duration == right._duration;
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_string: right.cast (type_duration); return left._duration == right._duration;
case type_unknown:
throw std::string ("Cannot equate unknown type");
// TODO Implement same-day comparison.
case type_date: return left._duration == right._date;
// TODO Implement same-day comparison.
case type_duration: return left._duration == right._duration;
case type_boolean:
case type_integer:
case type_real:
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;
}