Пример #1
0
static void
_adg_set_named_pair(AdgModel *model, const gchar *name, const CpmlPair *pair)
{
    AdgModelPrivate *data;
    GHashTable **hash;
    gchar *key;
    CpmlPair *value;

    data = model->data;
    hash = &data->named_pairs;

    if (pair == NULL) {
        /* Delete mode: raise a warning if @name is not found */
        if (*hash == NULL || !g_hash_table_remove(*hash, name))
            g_warning(_("%s: attempting to remove nonexistent '%s' named pair"),
                      G_STRLOC, name);

        return;
    }

    /* Insert or update mode */
    key = g_strdup(name);
    value = cpml_pair_dup(pair);

    if (*hash == NULL)
        *hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

    g_hash_table_insert(*hash, key, value);
}
Пример #2
0
/**
 * adg_point_get_pair:
 * @point: an #AdgPoint
 *
 * #AdgPoint is an evolution of the pair concept but internally the
 * relevant data is still stored in an #CpmlPair struct. This function
 * returns a copy of the internally owned pair.
 *
 * <note><para>
 * The #CpmlPair is the first field of an #AdgPoint struct so casting
 * is allowed between them and, in fact, it is often more convenient
 * than calling this function. Just remember to update the internal
 * pair by using adg_point_update() before.
 * </para></note>
 *
 * Returns: (transfer full): the pair of @point or <constant>NULL</constant> if the named pair does not exist.
 *
 * Since: 1.0
 **/
CpmlPair *
adg_point_get_pair(AdgPoint *point)
{
    g_return_val_if_fail(point != NULL, NULL);

    if (! adg_point_update(point))
        return NULL;

    return cpml_pair_dup(& point->pair);
}