ThingWorx C SDK
twList.h
1 /***************************************
2  * Copyright (C) 2015 ThingWorx Inc. *
3  ***************************************/
4 
14 #ifndef TW_LIST_H
15 #define TW_LIST_H
16 
17 #include "twOSPort.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 struct ListEntry;
24 
32 typedef void (*del_func) (void * item);
33 
37 typedef struct ListEntry {
38  struct ListEntry *next;
39  struct ListEntry *prev;
40  void *value;
41 } ListEntry;
42 
46 typedef struct twList {
47  int count;
48  struct ListEntry *first;
49  struct ListEntry *last;
51  del_func delete_function;
52 } twList;
53 
70 twList * twList_Create(del_func delete_function);
71 
81 int twList_Delete(struct twList *list);
82 
92 int twList_Clear(struct twList *list);
93 
104 int twList_Add(twList *list, void *value);
105 
122 int twList_Remove(struct twList *list, struct ListEntry * entry, char deleteValue);
123 
138 ListEntry * twList_Next(struct twList *list, struct ListEntry * entry);
139 
153 ListEntry * twList_GetByIndex(struct twList *list, int index);
154 
163 int twList_GetCount(struct twList *list);
164 
165 /*
166 twList_ReplaceValue - Replaces the value of the specified list entry with the new value supplied.
167 Parameters:
168  list - pointer to the list to operate on
169  entry - pointer to the entry whose value should be replaced.
170  new_value - the new value
171  dispose - Boolean: delete the old value using the delete function specified when the list was created
172 Return:
173  int - zero if successful, non-zero if an error occurred
174 */
175 int twList_ReplaceValue(struct twList *list, struct ListEntry * entry, void * new_value, char dispose);
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif
struct ListEntry * first
Definition: twList.h:48
TW_MUTEX mtx
Definition: twList.h:50
void * value
Definition: twList.h:40
#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:46
int count
Definition: twList.h:47
del_func delete_function
Definition: twList.h:51
Linked list entry structure definition.
Definition: twList.h:37
struct ListEntry * prev
Definition: twList.h:39
struct ListEntry * next
Definition: twList.h:38
struct ListEntry * last
Definition: twList.h:49