69 /** |
69 /** |
70 * The allocator to use. |
70 * The allocator to use. |
71 */ |
71 */ |
72 CxAllocator const *allocator; |
72 CxAllocator const *allocator; |
73 /** |
73 /** |
74 * A mandatory destructor for the list structure. |
|
75 */ |
|
76 cx_destructor_func list_destructor; |
|
77 /** |
|
78 * An optional destructor for the list contents. |
74 * An optional destructor for the list contents. |
79 */ |
75 */ |
80 cx_destructor_func content_destructor; |
76 cx_destructor_func content_destructor; |
81 /** |
77 /** |
82 * The comparator function for the elements. |
78 * The comparator function for the elements. |
92 size_t size; |
88 size_t size; |
93 /** |
89 /** |
94 * The capacity of the list (maximum number of elements). |
90 * The capacity of the list (maximum number of elements). |
95 */ |
91 */ |
96 size_t capacity; |
92 size_t capacity; |
97 /** |
|
98 * Flag indicating whether cxListDestroy() shall free the list structure, |
|
99 * even if cx_list_s.list_destructor did not do that. |
|
100 */ |
|
101 bool autofree; |
|
102 /** |
93 /** |
103 * Flag indicating whether cxListDestroy() shall free each list element, |
94 * Flag indicating whether cxListDestroy() shall free each list element, |
104 * even if cx_list_s.content_destructor did not do that. |
95 * even if cx_list_s.content_destructor did not do that. |
105 */ |
96 */ |
106 bool autofree_contents; |
97 bool autofree_contents; |
108 |
99 |
109 /** |
100 /** |
110 * The class definition for arbitrary lists. |
101 * The class definition for arbitrary lists. |
111 */ |
102 */ |
112 struct cx_list_class_s { |
103 struct cx_list_class_s { |
|
104 /** |
|
105 * Destructor function. |
|
106 */ |
|
107 void (*destructor)(struct cx_list_s *list); |
|
108 |
113 /** |
109 /** |
114 * Member function for adding an element. |
110 * Member function for adding an element. |
115 */ |
111 */ |
116 int (*add)( |
112 int (*add)( |
117 struct cx_list_s *list, |
113 struct cx_list_s *list, |
189 |
185 |
190 /** |
186 /** |
191 * Common type for all list implementations. |
187 * Common type for all list implementations. |
192 */ |
188 */ |
193 typedef struct cx_list_s CxList; |
189 typedef struct cx_list_s CxList; |
194 |
|
195 /** |
|
196 * Convenience function to configure the memory management for this list. |
|
197 * |
|
198 * @param list the list to configure |
|
199 * @param list_destructor an alternative list destructor to use (if \c NULL, the current destructor remains unchanged) |
|
200 * @param content_destructor the content destructor to use (if \c NULL, no content destructor is used) |
|
201 * @param list_autofree a flag indicating, if the list allocator shall free the list, if the destructor did not do that |
|
202 * @param content_autofree a flag indicating, if the list allocator shall free an element, |
|
203 * if the content destructor did not do that or no content destructor exists |
|
204 */ |
|
205 __attribute__((__nonnull__(1))) |
|
206 void cxListMemoryMgmt( |
|
207 CxList *list, |
|
208 cx_destructor_func list_destructor, |
|
209 cx_destructor_func content_destructor, |
|
210 bool list_autofree, |
|
211 bool content_autofree |
|
212 ); |
|
213 |
190 |
214 /** |
191 /** |
215 * Adds an item to the end of the list. |
192 * Adds an item to the end of the list. |
216 * |
193 * |
217 * @param list the list |
194 * @param list the list |