1 /* hashable.c generated by valac 0.18.0, the Vala compiler
2 * generated from hashable.vala, do not modify */
6 * Copyright (C) 2010 Maciej Piechotka
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Maciej Piechotka <uzytkwonik2@gmail.com>
27 #include <glib-object.h>
30 #define GEE_TYPE_HASHABLE (gee_hashable_get_type ())
31 #define GEE_HASHABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_HASHABLE, GeeHashable))
32 #define GEE_IS_HASHABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_HASHABLE))
33 #define GEE_HASHABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_HASHABLE, GeeHashableIface))
35 typedef struct _GeeHashable GeeHashable;
36 typedef struct _GeeHashableIface GeeHashableIface;
38 struct _GeeHashableIface {
39 GTypeInterface parent_iface;
40 guint (*hash) (GeeHashable* self);
41 gboolean (*equal_to) (GeeHashable* self, gconstpointer object);
46 GType gee_hashable_get_type (void) G_GNUC_CONST;
47 guint gee_hashable_hash (GeeHashable* self);
48 gboolean gee_hashable_equal_to (GeeHashable* self, gconstpointer object);
52 * Computes hash for an objects. Two hashes of equal objects have to be
53 * equal. Hash have to not change during lifetime of object.
55 * @return hash of an object
57 guint gee_hashable_hash (GeeHashable* self) {
58 g_return_val_if_fail (self != NULL, 0U);
59 return GEE_HASHABLE_GET_INTERFACE (self)->hash (self);
64 * Compares this object with the specifed object.
66 * @return true if objects are equal
68 gboolean gee_hashable_equal_to (GeeHashable* self, gconstpointer object) {
69 g_return_val_if_fail (self != NULL, FALSE);
70 return GEE_HASHABLE_GET_INTERFACE (self)->equal_to (self, object);
74 static void gee_hashable_base_init (GeeHashableIface * iface) {
75 static gboolean initialized = FALSE;
83 * This interface defines a hash function amongs instances of each class
88 GType gee_hashable_get_type (void) {
89 static volatile gsize gee_hashable_type_id__volatile = 0;
90 if (g_once_init_enter (&gee_hashable_type_id__volatile)) {
91 static const GTypeInfo g_define_type_info = { sizeof (GeeHashableIface), (GBaseInitFunc) gee_hashable_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
92 GType gee_hashable_type_id;
93 gee_hashable_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeHashable", &g_define_type_info, 0);
94 g_type_interface_add_prerequisite (gee_hashable_type_id, G_TYPE_OBJECT);
95 g_once_init_leave (&gee_hashable_type_id__volatile, gee_hashable_type_id);
97 return gee_hashable_type_id__volatile;