|
From: Aaron J. <ja...@go...> - 2011-05-26 02:51:06
|
Okay, in revision 224 I've further reworked the type system to act as follows:
* isFoo methods determine exact representability.
* asFoo methods cause casting when safe.
* isConvertibleTo indicates whether casting is safe.
(See NEWS.txt for more details.) I think this makes isConvertibleTo fit in
with the new system properly. I had for example found code at Google that
looks like this:
int ConvertValueToInt(const Json::Value& v) {
if (v.isConvertibleTo(Json::intValue)) {
return v.asInt();
}
else { ...}
}
That caused problems with my last attempt because asInt() would chuck an
exception if the value was 3.5, for example. Now I've restored the behavior of
casting when requested.
The remaining rough edge is 64-bit integers -- it would break existing code to
introduce a new ValueType enum value for them, and given the code above we
can't have `Value(1LL<<40).isConvertibleTo(intValue)` return true. So as of
now, `isConvertibleTo(intValue)` may return false even if the value's type is
intValue. (See NEWS.txt for a better explanation.)
|