Avoid an int->string->int conversion

This commit is contained in:
Erica Fischer
2024-01-24 11:54:01 -08:00
parent 16560f8ae8
commit b91908c967
3 changed files with 27 additions and 1 deletions
+25
View File
@@ -800,3 +800,28 @@ serial_val mvt_value_to_serial_val(mvt_value const &v) {
return sv;
}
// This extracts an integer value from an mvt_value
long long mvt_value_to_long_long(mvt_value const &v) {
switch (v.type) {
case mvt_string:
return atoll(v.string_value.c_str());
case mvt_float:
return v.numeric_value.float_value;
case mvt_double:
return v.numeric_value.double_value;
case mvt_int:
return v.numeric_value.int_value;
case mvt_uint:
return v.numeric_value.uint_value;
case mvt_sint:
return v.numeric_value.sint_value;
case mvt_bool:
return v.numeric_value.bool_value;
case mvt_null:
return 0;
default:
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}