Exemple #1
0
ex_value_t *
convert_value (ex_value_t *value, type_t *type)
{
	if (!is_scalar (type) || !is_scalar (ev_types[value->type])) {
		error (0, "unable to convert non-scalar value");
		return value;
	}
	if (is_float (type)) {
		float       val = value_as_float (value);
		return new_float_val (val);
	} else if (type->type == ev_short) {
		int         val = value_as_int (value);
		return new_short_val (val);
	} else if (type->type == ev_uinteger) {
		unsigned    val = value_as_uint (value);
		return new_uinteger_val (val);
	} else {
		//FIXME handle enums separately?
		int         val = value_as_int (value);
		return new_integer_val (val);
	}
}
Exemple #2
0
std::string ConstField::to_s() const
{
    switch (type()) {
        case TIME:
            return boost::lexical_cast<std::string>(value_as_time());
        case NUMBER:
            return boost::lexical_cast<std::string>(value_as_number());
        case FLOAT:
            return
                boost::lexical_cast<std::string>(value_as_float());
        case NULL_STRING:
            return std::string(value_as_null_string());
        case BYTE_STRING:
            return value_as_byte_string().to_s();
        default:
            BOOST_THROW_EXCEPTION(
                einval() << errinfo_what(
                    "ConstField::to_s() does not support field type: " +
                    Internal::type_as_s(type())
                )
            );
    }
}
Exemple #3
0
long double ConstField::value_as_float(const std::string& arg) const
{
    return value_as_float(arg.data(), arg.length());
}
Exemple #4
0
PValue flag(PValue *args) {
    printf("flag %f\n",value_as_float(args[1]));
    return NULL;
}