D-Bus
1.4.10
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* dbus-hash.h Generic hash table utility (internal to D-Bus implementation) 00003 * 00004 * Copyright (C) 2002 Red Hat, Inc. 00005 * 00006 * Licensed under the Academic Free License version 2.1 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 */ 00023 00024 #ifndef DBUS_HASH_H 00025 #define DBUS_HASH_H 00026 00027 #ifdef HAVE_STDINT_H 00028 #include <stdint.h> 00029 #endif 00030 00031 #ifdef HAVE_INTTYPES_H 00032 #include <inttypes.h> 00033 #endif 00034 00035 #include <dbus/dbus-memory.h> 00036 #include <dbus/dbus-types.h> 00037 #include <dbus/dbus-sysdeps.h> 00038 00039 DBUS_BEGIN_DECLS 00040 00049 struct DBusHashIter 00050 { 00051 void *dummy1; 00052 void *dummy2; 00053 void *dummy3; 00054 void *dummy4; 00055 int dummy5; 00056 int dummy6; 00057 }; 00058 00059 typedef struct DBusHashTable DBusHashTable; 00060 typedef struct DBusHashIter DBusHashIter; 00061 00062 /* Allowing an arbitrary function as with GLib 00063 * would be nicer for a public API, but for 00064 * an internal API this saves typing, we can add 00065 * more whenever we feel like it. 00066 */ 00067 typedef enum 00068 { 00069 DBUS_HASH_STRING, 00070 DBUS_HASH_TWO_STRINGS, 00071 DBUS_HASH_INT, 00072 DBUS_HASH_POINTER, 00073 DBUS_HASH_UINTPTR 00074 } DBusHashType; 00075 00076 DBusHashTable* _dbus_hash_table_new (DBusHashType type, 00077 DBusFreeFunction key_free_function, 00078 DBusFreeFunction value_free_function); 00079 DBusHashTable* _dbus_hash_table_ref (DBusHashTable *table); 00080 void _dbus_hash_table_unref (DBusHashTable *table); 00081 void _dbus_hash_table_remove_all (DBusHashTable *table); 00082 void _dbus_hash_iter_init (DBusHashTable *table, 00083 DBusHashIter *iter); 00084 dbus_bool_t _dbus_hash_iter_next (DBusHashIter *iter); 00085 void _dbus_hash_iter_remove_entry (DBusHashIter *iter); 00086 void* _dbus_hash_iter_get_value (DBusHashIter *iter); 00087 void _dbus_hash_iter_set_value (DBusHashIter *iter, 00088 void *value); 00089 int _dbus_hash_iter_get_int_key (DBusHashIter *iter); 00090 const char* _dbus_hash_iter_get_string_key (DBusHashIter *iter); 00091 const char* _dbus_hash_iter_get_two_strings_key (DBusHashIter *iter); 00092 uintptr_t _dbus_hash_iter_get_uintptr_key (DBusHashIter *iter); 00093 dbus_bool_t _dbus_hash_iter_lookup (DBusHashTable *table, 00094 void *key, 00095 dbus_bool_t create_if_not_found, 00096 DBusHashIter *iter); 00097 void* _dbus_hash_table_lookup_string (DBusHashTable *table, 00098 const char *key); 00099 void* _dbus_hash_table_lookup_two_strings (DBusHashTable *table, 00100 const char *key); 00101 void* _dbus_hash_table_lookup_int (DBusHashTable *table, 00102 int key); 00103 void* _dbus_hash_table_lookup_pointer (DBusHashTable *table, 00104 void *key); 00105 void* _dbus_hash_table_lookup_uintptr (DBusHashTable *table, 00106 uintptr_t key); 00107 dbus_bool_t _dbus_hash_table_remove_string (DBusHashTable *table, 00108 const char *key); 00109 dbus_bool_t _dbus_hash_table_remove_two_strings (DBusHashTable *table, 00110 const char *key); 00111 dbus_bool_t _dbus_hash_table_remove_int (DBusHashTable *table, 00112 int key); 00113 dbus_bool_t _dbus_hash_table_remove_pointer (DBusHashTable *table, 00114 void *key); 00115 dbus_bool_t _dbus_hash_table_remove_uintptr (DBusHashTable *table, 00116 uintptr_t key); 00117 dbus_bool_t _dbus_hash_table_insert_string (DBusHashTable *table, 00118 char *key, 00119 void *value); 00120 dbus_bool_t _dbus_hash_table_insert_two_strings (DBusHashTable *table, 00121 char *key, 00122 void *value); 00123 dbus_bool_t _dbus_hash_table_insert_int (DBusHashTable *table, 00124 int key, 00125 void *value); 00126 dbus_bool_t _dbus_hash_table_insert_pointer (DBusHashTable *table, 00127 void *key, 00128 void *value); 00129 dbus_bool_t _dbus_hash_table_insert_uintptr (DBusHashTable *table, 00130 uintptr_t key, 00131 void *value); 00132 int _dbus_hash_table_get_n_entries (DBusHashTable *table); 00133 00134 /* Preallocation */ 00135 00137 typedef struct DBusPreallocatedHash DBusPreallocatedHash; 00138 00139 DBusPreallocatedHash *_dbus_hash_table_preallocate_entry (DBusHashTable *table); 00140 void _dbus_hash_table_free_preallocated_entry (DBusHashTable *table, 00141 DBusPreallocatedHash *preallocated); 00142 void _dbus_hash_table_insert_string_preallocated (DBusHashTable *table, 00143 DBusPreallocatedHash *preallocated, 00144 char *key, 00145 void *value); 00146 00149 DBUS_END_DECLS 00150 00151 #endif /* DBUS_HASH_H */