ThingWorx C SDK
twMap.h
1 #include <stdio.h>
2 #ifndef TW_C_SDK_TWMAP_H
3 #define TW_C_SDK_TWMAP_H
4 
5 #ifndef TW_FOREACH_CONTINUE
6 #define TW_FOREACH_CONTINUE 0
7 #define TW_FOREACH_EXIT 1
8 #endif
9 
10 #define TW_MAP_MISSING -3 /* No such element */
11 #define TW_MAP_FULL -2 /* Hashmap is full */
12 #define TW_MAP_OMEM -1 /* Out of Memory */
13 #define TW_MAP_OK 0 /* OK */
14 
15 /*
16  * twMap is a pointer to an internally maintained data structure.
17  * Clients of this package do not need to know how hashmaps are
18  * represented. They see and manipulate only twMap's.
19  */
20 typedef void twMap;
21 
22 /*
23  * Tears down lazy-created globals. Return TW_OK or TW_UNKNOWN_ERROR
24  * if invoked with one or more dangling map references.
25 */
26 int twMap_Cleanup();
27 
28 /*
29  * Return an empty hashmap. Returns NULL if empty.
30 */
31 twMap* twMap_new();
32 
33 /*
34  * Add an element to the hashmap. Return MAP_OK or MAP_OMEM.
35  */
36 int twMap_put(twMap* in, const char* key, void * value);
37 
38 /*
39  * Get an element from the hashmap. Return MAP_OK or MAP_MISSING.
40  */
41 int twMap_get(twMap* in, const char* key, void * *arg);
42 
43 /*
44  * Remove an element from the hashmap. Return MAP_OK or MAP_MISSING.
45  */
46 int twMap_remove(twMap* in, const char* key);
47 
48 /*
49  * Free the hashmap
50  */
51 void twMap_free(twMap* in);
52 
53 /*
54  * Get the current size of a hashmap
55  */
56 int twMap_length(twMap* in);
57 
58 
59 /* Mock List Interface */
60 typedef void (*map_del_func) (void * item);
61 typedef const char* (*map_key_parse_func) (void * item);
62 twMap * twMap_Create(map_del_func delete_function,map_key_parse_func parse_func);
63 int twMap_Delete(twMap* in);
64 int twMap_Clear(twMap* in);
65 
66 int twMap_Add(twMap* in, void *value);
67 int twMap_Remove(twMap* in, void * item, char deleteValue);
68 
69 typedef int (*twMap_foreach_fn)(void *key, size_t key_size, void *data, size_t data_size,void *arg);
70 
71 size_t twMap_Foreach(twMap* in, twMap_foreach_fn listHandler, void *userData);
72 
73 
74 int twMap_Find(twMap* in, void* query, void** results);
75 
76 int twMap_GetCount(twMap* in);
77 int twMap_ReplaceValue(twMap* in, void * value, void * new_value, char dispose);
78 
79 
80 #endif /* TW_C_SDK_TWHASHMAP_H */