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