Exemplo n.º 1
0
gdouble
ghb_dict_get_double(const GhbValue *dict, const gchar *key)
{
    const GhbValue* value;
    value = ghb_dict_get_value(dict, key);
    if (value == NULL) return 0;
    return ghb_value_get_double(value);
}
Exemplo n.º 2
0
static void
gval_write(FILE *file, GhbValue *gval)
{
    static gint indent = 0;
    gint ii;
    GhbType gtype;

    if (gval == NULL) return;
    gtype = ghb_value_type(gval);
    if (gtype == GHB_ARRAY)
    {
        GhbValue *val;
        gint count;

        indent_fprintf(file, indent, "<array>\n");
        indent++;
        count = ghb_array_len(gval);
        for (ii = 0; ii < count; ii++)
        {
            val = ghb_array_get(gval, ii);
            gval_write(file, val);
        }
        indent--;
        indent_fprintf(file, indent, "</array>\n");
    }
    else if (gtype == GHB_DICT)
    {
        const char *key;
        GhbValue *val;
        GhbDictIter iter;

        indent_fprintf(file, indent, "<dict>\n");
        indent++;

        iter = ghb_dict_iter_init(gval);
        while (ghb_dict_iter_next(gval, &iter, &key, &val))
        {
            indent_fprintf(file, indent, "<key>%s</key>\n", key);
            gval_write(file, val);
        }

        indent--;
        indent_fprintf(file, indent, "</dict>\n");
    }
    else if (gtype == GHB_BOOL)
    {
        gchar *tag;
        if (ghb_value_get_bool(gval))
        {
            tag = "true";
        }
        else
        {
            tag = "false";
        }
        indent_fprintf(file, indent, "<%s />\n", tag);
    }
    else if (gtype == GHB_DOUBLE)
    {
        gdouble val = ghb_value_get_double(gval);
        indent_fprintf(file, indent, "<real>%.17g</real>\n", val);
    }
    else if (gtype == GHB_INT)
    {
        gint64 val = ghb_value_get_int(gval);
        indent_fprintf(file, indent, "<integer>%"PRId64"</integer>\n", val);
    }
    else if (gtype == GHB_STRING)
    {
        const gchar *str = ghb_value_get_string(gval);
        gchar *esc = g_markup_escape_text(str, -1);
        indent_fprintf(file, indent, "<string>%s</string>\n", esc);
        g_free(esc);
    }
    else
    {
        // Try to make anything thats unrecognized into a string
        g_warning("Unhandled data type %d", gtype);
    }
}