Update Changelog
[profile/ivi/libgee.git] / gee / hashable.c
1 /* hashable.c generated by valac 0.18.0, the Vala compiler
2  * generated from hashable.vala, do not modify */
3
4 /* hashable.vala
5  *
6  * Copyright (C) 2010  Maciej Piechotka
7  *
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.
12
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.
17
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
21  *
22  * Author:
23  *      Maciej Piechotka <uzytkwonik2@gmail.com>
24  */
25
26 #include <glib.h>
27 #include <glib-object.h>
28
29
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))
34
35 typedef struct _GeeHashable GeeHashable;
36 typedef struct _GeeHashableIface GeeHashableIface;
37
38 struct _GeeHashableIface {
39         GTypeInterface parent_iface;
40         guint (*hash) (GeeHashable* self);
41         gboolean (*equal_to) (GeeHashable* self, gconstpointer object);
42 };
43
44
45
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);
49
50
51 /**
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.
54  *
55  * @return hash of an object
56  */
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);
60 }
61
62
63 /**
64  * Compares this object with the specifed object.
65  *
66  * @return true if objects are equal
67  */
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);
71 }
72
73
74 static void gee_hashable_base_init (GeeHashableIface * iface) {
75         static gboolean initialized = FALSE;
76         if (!initialized) {
77                 initialized = TRUE;
78         }
79 }
80
81
82 /**
83  * This interface defines a hash function amongs instances of each class
84  * implementing it.
85  * 
86  * @see Comparable
87  */
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);
96         }
97         return gee_hashable_type_id__volatile;
98 }
99
100
101