ThingWorx C SDK
twList.h
1 /***************************************
2  * Copyright 2017, PTC, Inc.
3  ***************************************/
4 
14 #ifndef TW_LIST_H
15 #define TW_LIST_H
16 
17 #ifndef TW_FOREACH_CONTINUE
18 #define TW_FOREACH_CONTINUE 0
19 #define TW_FOREACH_EXIT 1
20 #endif
21 
22 #include "twOSPort.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct ListEntry;
29 
33 int twList_Cleanup ();
34 
42 typedef void (*del_func) (void * item);
43 typedef const char* (*parse_func) (void * item);
44 
48 typedef struct ListEntry {
49  struct ListEntry *next;
50  struct ListEntry *prev;
51  void *value;
52 } ListEntry;
53 
54 typedef int (*twForEachHander)(void *key, size_t key_size, void *data, size_t data_size,void *userData);
55 
59 typedef struct twList {
60  int count;
61  struct ListEntry *first;
62  struct ListEntry *last;
64  del_func delete_function;
65  parse_func parse_function;
66 } twList;
67 
84 twList *twList_Create(del_func delete_function);
85 twList *twList_CreateSearchable(del_func delete_function, parse_func parse_function);
86 
96 int twList_Delete(struct twList *list);
97 
107 int twList_Clear(struct twList *list);
108 
118 int twList_ClearEntries(struct twList *list);
119 
130 int twList_Add(twList *list, void *value);
131 
148 int twList_Remove(struct twList *list, struct ListEntry * entry, char deleteValue);
149 
164 ListEntry * twList_Next(struct twList *list, struct ListEntry * entry);
165 
183 int twList_Foreach(twList *list, twForEachHander listHandler, void *userData);
184 
198 ListEntry * twList_GetByIndex(struct twList *list, int index);
199 
208 int twList_GetCount(struct twList *list);
209 
210 /*
211 twList_ReplaceValue - Replaces the value of the specified list entry with the new value supplied.
212 Parameters:
213  list - pointer to the list to operate on
214  entry - pointer to the entry whose value should be replaced.
215  new_value - the new value
216  dispose - Boolean: delete the old value using the delete function specified when the list was created
217 Return:
218  int - zero if successful, non-zero if an error occurred
219 */
220 int twList_ReplaceValue(struct twList *list, struct ListEntry * entry, void * new_value, char dispose);
221 
236 int twList_Find(twList* list, void* query, void** result);
237 
238 
239 #ifdef _DEBUG
240 
241 void twList_CheckTask(DATETIME now, void * params);
242 #endif
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif
struct ListEntry * first
Definition: twList.h:61
parse_func parse_function
Definition: twList.h:65
TW_MUTEX mtx
Definition: twList.h:63
void * value
Definition: twList.h:51
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
Wrappers for OS-specific functionality.
Linked list structure definition.
Definition: twList.h:59
int count
Definition: twList.h:60
del_func delete_function
Definition: twList.h:64
Linked list entry structure definition.
Definition: twList.h:48
struct ListEntry * prev
Definition: twList.h:50
struct ListEntry * next
Definition: twList.h:49
struct ListEntry * last
Definition: twList.h:62