]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_hash.h
Prepare for #inclusion in C++
[OpenSRF.git] / include / opensrf / osrf_hash.h
1 #ifndef OSRF_HASH_H
2 #define OSRF_HASH_H
3
4 #include <opensrf/utils.h>
5 #include <opensrf/string_array.h>
6 #include <opensrf/osrf_list.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 struct _osrfHashStruct;
13 typedef struct _osrfHashStruct osrfHash;
14
15 struct _osrfHashIteratorStruct;
16 typedef struct _osrfHashIteratorStruct osrfHashIterator;
17
18 /**
19   Allocates a new hash object
20   */
21 osrfHash* osrfNewHash();
22
23 /** Installs a callback function for freeing stored items
24  */
25 void osrfHashSetCallback( osrfHash* hash, void (*callback) (char* key, void* item) );
26
27 /**
28   Sets the given key with the given item
29   if "freeItem" is defined and an item already exists at the given location, 
30   then old item is freed and the new item is put into place.
31   if "freeItem" is not defined and an item already exists, the old item
32   is returned.
33   @return The old item if exists and there is no 'freeItem', returns NULL
34   otherwise
35   */
36 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
37
38 /**
39   Removes an item from the hash.
40   if 'freeItem' is defined it is used and NULL is returned,
41   else the freed item is returned
42   */
43 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
44
45 void* osrfHashGet( osrfHash* hash, const char* key, ... );
46
47
48 /**
49   @return A list of strings representing the keys of the hash. 
50   caller is responsible for freeing the returned string array 
51   with osrfStringArrayFree();
52   */
53 osrfStringArray* osrfHashKeys( osrfHash* hash );
54
55 /**
56   Frees a hash
57   */
58 void osrfHashFree( osrfHash* hash );
59
60 /**
61   @return The number of items in the hash
62   */
63 unsigned long osrfHashGetCount( osrfHash* hash );
64
65 /**
66   Creates a new list iterator with the given list
67   */
68 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
69
70 int osrfHashIteratorHasNext( osrfHashIterator* itr );
71
72 /**
73   Returns the next non-NULL item in the list, return NULL when
74   the end of the list has been reached
75   */
76 void* osrfHashIteratorNext( osrfHashIterator* itr );
77
78 /**
79   Returns a pointer to the key of the current hash item
80   */
81 const char* osrfHashIteratorKey( const osrfHashIterator* itr );
82
83 /**
84   Deallocates the given list
85   */
86 void osrfHashIteratorFree( osrfHashIterator* itr );
87
88 void osrfHashIteratorReset( osrfHashIterator* itr );
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif