2002-11-22 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-hash.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-hash.h  Generic hash table utility (internal to D-BUS implementation)
3  *
4  * Copyright (C) 2002  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program 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
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_HASH_H
25 #define DBUS_HASH_H
26
27 DBUS_BEGIN_DECLS
28
29 #include <dbus/dbus-memory.h>
30 #include <dbus/dbus-types.h>
31
32 typedef struct DBusHashTable DBusHashTable;
33 typedef struct DBusHashIter  DBusHashIter;
34
35 /* The iterator is on the stack, but its real fields are
36  * hidden privately.
37  */
38 struct DBusHashIter
39 {
40   void *dummy1;
41   int   dummy2;
42   void *dummy3;  
43 };
44
45 /* Allowing an arbitrary function as with GLib
46  * would probably be nicer, but this is internal API so
47  * who cares
48  */
49 typedef enum
50 {
51   DBUS_HASH_STRING,
52   DBUS_HASH_INT
53 } DBusHashType;
54
55 DBusHashTable* _dbus_hash_table_new   (DBusHashType     type,
56                                        DBusFreeFunction key_free_function,
57                                        DBusFreeFunction value_free_function);
58 void           _dbus_hash_table_ref   (DBusHashTable   *table);
59 void           _dbus_hash_table_unref (DBusHashTable   *table);
60
61 /* usage "while (_dbus_hash_table_iterate (table, &iter)) { }" */
62 dbus_bool_t _dbus_hash_table_iterate (DBusHashTable *table,
63                                       DBusHashIter  *iter);
64
65 void*       _dbus_hash_iter_get_value      (DBusHashEntry *iter);
66 void        _dbus_hash_iter_set_value      (DBusHashEntry *iter,
67                                             void          *value);
68 int         _dbus_hash_iter_get_int_key    (DBusHashIter  *iter);
69 const char* _dbus_hash_iter_get_string_key (DBusHashIter  *iter);
70
71 void* _dbus_hash_table_lookup_string (DBusHashTable *table,
72                                       const char    *key);
73 void* _dbus_hash_table_lookup_int    (DBusHashTable *table,
74                                       int            key);
75 void  _dbus_hash_table_remove_string (DBusHashTable *table,
76                                       const char    *key);
77 void  _dbus_hash_table_remove_int    (DBusHashTable *table,
78                                       int            key);
79 void  _dbus_hash_table_insert_string (DBusHashTable *table,
80                                       const char    *key,
81                                       void          *value);
82 void  _dbus_hash_table_insert_int    (DBusHashTable *table,
83                                       int            key,
84                                       void          *value);
85
86
87 DBUS_END_DECLS
88
89 #endif /* DBUS_HASH_H */