00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00075 #ifndef COUCAL_DEFH
00076 #define COUCAL_DEFH
00077
00078
00079 #ifdef _WIN32
00080 #include <stddef.h>
00081 typedef unsigned __int32 uint32_t;
00082 typedef unsigned __int64 uint64_t;
00083 #elif (defined(SOLARIS) || defined(sun) || defined(HAVE_INTTYPES_H) \
00084 || defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD_kernel__))
00085 #include <inttypes.h>
00086 #else
00087 #include <stdint.h>
00088 #endif
00089 #include <stdarg.h>
00090
00091
00092 #ifndef COUCAL_EXTERN
00093 #ifdef _WIN32
00094 #ifdef COUCAL_BUILDING
00095 #define COUCAL_EXTERN __declspec(dllimport)
00096 #else
00097 #define COUCAL_EXTERN __declspec(dllexport)
00098 #endif
00099 #elif ( ( defined(__GNUC__) && ( __GNUC__ >= 4 ) ) \
00100 || ( defined(HAVE_VISIBILITY) && HAVE_VISIBILITY ) )
00101 #define COUCAL_EXTERN extern __attribute__ ((visibility("default")))
00102 #else
00103 #define COUCAL_EXTERN extern
00104 #endif
00105 #endif
00106
00108 typedef void* coucal_key;
00109
00111 typedef const void* coucal_key_const;
00112
00114 typedef void* coucal_opaque;
00115
00117 typedef union coucal_value {
00119 intptr_t intg;
00120
00122 uintptr_t uintg;
00123
00125 void *ptr;
00126 } coucal_value;
00127
00129 typedef const coucal_value coucal_value_const;
00130
00132 #define INTHASH_VALUE_NULL { 0 }
00133
00134 #ifndef HTS_DEF_FWSTRUCT_coucal_item
00135 #define HTS_DEF_FWSTRUCT_coucal_item
00136 typedef struct coucal_item coucal_item;
00137 #endif
00138
00140 #ifndef COUCAL_HASH_SIZE
00141 #define COUCAL_HASH_SIZE 32
00142 #endif
00143
00145 #if (COUCAL_HASH_SIZE == 32)
00146
00148 typedef uint32_t coucal_hashkey;
00149
00150 #elif (COUCAL_HASH_SIZE == 64)
00151
00153 typedef uint64_t coucal_hashkey;
00154
00155 #else
00156 #error "Unsupported COUCAL_HASH_SIZE"
00157 #endif
00158
00160 typedef struct coucal_hashkeys {
00161 coucal_hashkey hash1;
00162 coucal_hashkey hash2;
00163 } coucal_hashkeys;
00164
00166 #define INTHASH_KEYS_NULL { 0, 0 }
00167
00169 struct coucal_item {
00171 coucal_key name;
00172
00174 coucal_value value;
00175
00177 coucal_hashkeys hashes;
00178 };
00179
00181 typedef enum coucal_loglevel {
00182 coucal_log_critical,
00183 coucal_log_warning,
00184 coucal_log_info,
00185 coucal_log_debug,
00186 coucal_log_trace
00187 } coucal_loglevel;
00188
00190 typedef void (*t_coucal_key_freehandler)(coucal_opaque arg,
00191 coucal_key key);
00192
00194 typedef void (*t_coucal_value_freehandler)(coucal_opaque arg,
00195 coucal_value value);
00196
00198 typedef coucal_key (*t_coucal_duphandler)(coucal_opaque arg,
00199 coucal_key_const name);
00200
00202 typedef coucal_hashkeys (*t_coucal_hasheshandler)(coucal_opaque arg,
00203 coucal_key_const name);
00204
00206 typedef void (*t_coucal_loghandler)(coucal_opaque arg, coucal_loglevel level,
00207 const char* format, va_list args);
00208
00210 typedef void (*t_coucal_asserthandler)(coucal_opaque arg, const char* exp,
00211 const char* file, int line);
00212
00214 typedef const char* (*t_coucal_printkeyhandler)(coucal_opaque arg,
00215 coucal_key_const name);
00216
00218 typedef const char* (*t_coucal_printvaluehandler)(coucal_opaque arg,
00219 coucal_value_const value);
00220
00224 typedef int (*t_coucal_cmphandler)(coucal_opaque arg,
00225 coucal_key_const a,
00226 coucal_key_const b);
00227
00229 #ifndef HTS_DEF_FWSTRUCT_struct_coucal
00230 #define HTS_DEF_FWSTRUCT_struct_coucal
00231 typedef struct struct_coucal struct_coucal, *coucal;
00232 #endif
00233
00235 #ifndef HTS_DEF_FWSTRUCT_struct_coucal_enum
00236 #define HTS_DEF_FWSTRUCT_struct_coucal_enum
00237 typedef struct struct_coucal_enum struct_coucal_enum;
00238 #endif
00239
00241 struct struct_coucal_enum {
00242 coucal table;
00243 size_t index;
00244 };
00245
00246 #ifdef __cplusplus
00247 extern "C" {
00248 #endif
00249
00261 COUCAL_EXTERN coucal coucal_new(size_t size);
00262
00267 COUCAL_EXTERN int coucal_created(coucal hashtable);
00268
00272 COUCAL_EXTERN void coucal_delete(coucal * hashtable);
00273
00277 COUCAL_EXTERN size_t coucal_nitems(coucal hashtable);
00278
00283 COUCAL_EXTERN size_t coucal_memory_size(coucal hashtable);
00284
00289 COUCAL_EXTERN size_t coucal_hash_size(void);
00290
00295 COUCAL_EXTERN void coucal_value_is_malloc(coucal hashtable, int flag);
00296
00304 COUCAL_EXTERN void coucal_value_set_value_handler(coucal hashtable,
00305 t_coucal_value_freehandler free,
00306 coucal_opaque arg);
00307
00319 COUCAL_EXTERN void coucal_value_set_key_handler(coucal hashtable,
00320 t_coucal_duphandler dup,
00321 t_coucal_key_freehandler free,
00322 t_coucal_hasheshandler hash,
00323 t_coucal_cmphandler equals,
00324 coucal_opaque arg);
00325
00331 COUCAL_EXTERN void coucal_set_assert_handler(coucal hashtable,
00332 t_coucal_loghandler log,
00333 t_coucal_asserthandler fatal,
00334 coucal_opaque arg);
00335
00343 COUCAL_EXTERN void coucal_set_print_handler(coucal hashtable,
00344 t_coucal_printkeyhandler key,
00345 t_coucal_printvaluehandler value,
00346 coucal_opaque arg);
00347
00352 COUCAL_EXTERN void coucal_set_name(coucal hashtable, coucal_key_const name);
00353
00358 COUCAL_EXTERN const char* coucal_get_name(coucal hashtable);
00359
00364 COUCAL_EXTERN int coucal_read(coucal hashtable, coucal_key_const name,
00365 intptr_t * intvalue);
00366
00370 COUCAL_EXTERN int coucal_readptr(coucal hashtable, coucal_key_const name,
00371 intptr_t * intvalue);
00372
00377 COUCAL_EXTERN intptr_t coucal_get_intptr(coucal hashtable,
00378 coucal_key_const name);
00379
00383 COUCAL_EXTERN int coucal_exists(coucal hashtable, coucal_key_const name);
00384
00389 COUCAL_EXTERN int coucal_read_value(coucal hashtable, coucal_key_const name,
00390 coucal_value *value);
00391
00396 COUCAL_EXTERN int coucal_write_value(coucal hashtable, coucal_key_const name,
00397 coucal_value_const value);
00398
00403 COUCAL_EXTERN int coucal_read_pvoid(coucal hashtable, coucal_key_const name,
00404 void **value);
00405
00410 COUCAL_EXTERN void* coucal_get_pvoid(coucal hashtable, coucal_key_const name);
00411
00416 COUCAL_EXTERN int coucal_write_pvoid(coucal hashtable, coucal_key_const name,
00417 void *value);
00418
00422 COUCAL_EXTERN void coucal_add_pvoid(coucal hashtable, coucal_key_const name,
00423 void *value);
00424
00429 COUCAL_EXTERN int coucal_write(coucal hashtable, coucal_key_const name,
00430 intptr_t value);
00431
00435 COUCAL_EXTERN void coucal_add(coucal hashtable, coucal_key_const name,
00436 intptr_t value);
00437
00443 COUCAL_EXTERN int coucal_inc(coucal hashtable, coucal_key_const name);
00444
00450 COUCAL_EXTERN int coucal_dec(coucal hashtable, coucal_key_const name);
00451
00458 COUCAL_EXTERN coucal_value* coucal_fetch_value(coucal hashtable,
00459 coucal_key_const name);
00460
00470 COUCAL_EXTERN coucal_value* coucal_fetch_value_hashes(coucal hashtable,
00471 coucal_key_const name,
00472 const coucal_hashkeys
00473 *hashes);
00474
00479 COUCAL_EXTERN int coucal_remove(coucal hashtable, coucal_key_const name);
00480
00486 COUCAL_EXTERN struct_coucal_enum coucal_enum_new(coucal hashtable);
00487
00491 COUCAL_EXTERN coucal_item *coucal_enum_next(struct_coucal_enum * e);
00492
00498 COUCAL_EXTERN coucal_hashkeys coucal_calc_hashes(coucal hashtable,
00499 coucal_key_const value);
00500
00506 COUCAL_EXTERN coucal_hashkeys coucal_hash_string(const char *value);
00507
00511 COUCAL_EXTERN coucal_hashkeys coucal_hash_data(const void *data, size_t size);
00512
00522 COUCAL_EXTERN void coucal_set_global_assert_handler(t_coucal_loghandler log,
00523 t_coucal_asserthandler fatal);
00524
00525 #ifdef __cplusplus
00526 }
00527 #endif
00528
00529 #endif