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