Blame src/grl-range-value.c

Packit 67b98c
/*
Packit 67b98c
 * Copyright (C) 2011 Igalia S.L.
Packit 67b98c
 *
Packit 67b98c
 * Contact: Iago Toral Quiroga <itoral@igalia.com>
Packit 67b98c
 *
Packit 67b98c
 * This library is free software; you can redistribute it and/or
Packit 67b98c
 * modify it under the terms of the GNU Lesser General Public License
Packit 67b98c
 * as published by the Free Software Foundation; version 2.1 of
Packit 67b98c
 * the License, or (at your option) any later version.
Packit 67b98c
 *
Packit 67b98c
 * This library is distributed in the hope that it will be useful, but
Packit 67b98c
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67b98c
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit 67b98c
 * Lesser General Public License for more details.
Packit 67b98c
 *
Packit 67b98c
 * You should have received a copy of the GNU Lesser General Public
Packit 67b98c
 * License along with this library; if not, write to the Free Software
Packit 67b98c
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit 67b98c
 * 02110-1301 USA
Packit 67b98c
 *
Packit 67b98c
 */
Packit 67b98c
Packit 67b98c
/*
Packit 67b98c
 * This module provides helper functions to use Range Values easily.
Packit 67b98c
 * Inspired by libsoup's soup-value-utils:
Packit 67b98c
 * http://git.gnome.org/browse/libsoup/tree/libsoup/soup-value-utils.c
Packit 67b98c
 *
Packit 67b98c
 */
Packit 67b98c
Packit 67b98c
#include <grl-range-value.h>
Packit 67b98c
#include <grl-value-helper.h>
Packit 67b98c
Packit 67b98c
G_DEFINE_BOXED_TYPE (GrlRangeValue, grl_range_value,
Packit 67b98c
                     (GBoxedCopyFunc) grl_range_value_dup,
Packit 67b98c
                     (GBoxedFreeFunc) grl_range_value_free)
Packit 67b98c
Packit 67b98c
Packit 67b98c
GrlRangeValue *
Packit 67b98c
grl_range_value_new (GValue *min, GValue *max)
Packit 67b98c
{
Packit 67b98c
  GrlRangeValue *range;
Packit 67b98c
Packit 67b98c
  range = g_slice_new0 (GrlRangeValue);
Packit 67b98c
  if (min) {
Packit 67b98c
    range->min = grl_g_value_dup (min);
Packit 67b98c
  }
Packit 67b98c
Packit 67b98c
  if (max) {
Packit 67b98c
    range->max = grl_g_value_dup (max);
Packit 67b98c
  }
Packit 67b98c
Packit 67b98c
  return range;
Packit 67b98c
}
Packit 67b98c
Packit 67b98c
void
Packit 67b98c
grl_range_value_free (GrlRangeValue *range)
Packit 67b98c
{
Packit 67b98c
  g_clear_pointer (&range->min, grl_g_value_free);
Packit 67b98c
  g_clear_pointer (&range->max, grl_g_value_free);
Packit 67b98c
Packit 67b98c
  g_slice_free (GrlRangeValue, range);
Packit 67b98c
}
Packit 67b98c
Packit 67b98c
/**
Packit 67b98c
 * grl_range_value_hashtable_new:
Packit 67b98c
 *
Packit 67b98c
 * Returns: (transfer full) (element-type gpointer GrlRangeValue): a #GHashTable
Packit 67b98c
 */
Packit 67b98c
GHashTable *
Packit 67b98c
grl_range_value_hashtable_new (void)
Packit 67b98c
{
Packit 67b98c
  return g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)grl_range_value_free);
Packit 67b98c
}
Packit 67b98c
Packit 67b98c
GrlRangeValue *
Packit 67b98c
grl_range_value_dup (const GrlRangeValue *range)
Packit 67b98c
{
Packit 67b98c
  return grl_range_value_new (range->min, range->max);
Packit 67b98c
}
Packit 67b98c
Packit 67b98c
void
Packit 67b98c
grl_range_value_hashtable_insert (GHashTable *hash_table,
Packit 67b98c
                                  gpointer key,
Packit 67b98c
                                  GValue *min,
Packit 67b98c
                                  GValue *max)
Packit 67b98c
{
Packit 67b98c
  GrlRangeValue *range = grl_range_value_new (min, max);
Packit 67b98c
  g_hash_table_insert (hash_table, key, range);
Packit 67b98c
}