5 /* we need this for size_t */
13 # ifdef EFL_ECORE_BUILD
15 # define EAPI __declspec(dllexport)
18 # endif /* ! DLL_EXPORT */
20 # define EAPI __declspec(dllimport)
21 # endif /* ! EFL_ECORE_BUILD */
25 # define EAPI __attribute__ ((visibility("default")))
36 * @brief Contains threading, list, hash, debugging and tree functions.
55 #define FREE(ptr) free(ptr); ptr = NULL;
60 #define IF_FREE(ptr) if (ptr) {free(ptr); } ptr = NULL;
62 /* convenience macros for checking pointer parameters for non-NULL */
63 #undef CHECK_PARAM_POINTER_RETURN
64 #define CHECK_PARAM_POINTER_RETURN(sparam, param, ret) \
67 printf("***** Developer Warning ***** :\n" \
68 "\tThis program is calling:\n\n" \
70 "\tWith the parameter:\n\n" \
72 "\tbeing NULL. Please fix your program.", __FUNCTION__, sparam); \
73 if (getenv("ECORE_ERROR_ABORT")) { abort(); } \
77 #undef CHECK_PARAM_POINTER
78 #define CHECK_PARAM_POINTER(sparam, param) \
81 printf("***** Developer Warning ***** :\n" \
82 "\tThis program is calling:\n\n" \
84 "\tWith the parameter:\n\n" \
86 "\tbeing NULL. Please fix your program.", __FUNCTION__, sparam); \
87 if (getenv("ECORE_ERROR_ABORT")) { abort(); } \
93 # define __FUNCTION__ "unknown"
99 # define ECORE_SORT_MIN 0
100 # define ECORE_SORT_MAX 1
102 typedef void (*Ecore_For_Each)(void *value, void *user_data);
103 # define ECORE_FOR_EACH(function) ((Ecore_For_Each)function)
105 typedef void (*Ecore_Free_Cb)(void *data);
106 # define ECORE_FREE_CB(func) ((Ecore_Free_Cb)func)
108 typedef unsigned int (*Ecore_Hash_Cb)(const void *key);
109 # define ECORE_HASH_CB(function) ((Ecore_Hash_Cb)function)
111 typedef int (*Ecore_Compare_Cb)(const void *data1, const void *data2);
112 # define ECORE_COMPARE_CB(function) ((Ecore_Compare_Cb)function)
114 typedef struct _ecore_list Ecore_List;
115 # define ECORE_LIST(list) ((Ecore_List *)list)
117 typedef struct _ecore_list_node Ecore_List_Node;
118 # define ECORE_LIST_NODE(node) ((Ecore_List_Node *)node)
120 typedef struct _ecore_strbuf Ecore_Strbuf;
121 # define ECORE_STRBUF(buf) ((Ecore_Strbuf *)buf)
123 struct _ecore_list_node
126 struct _ecore_list_node *next;
131 Ecore_List_Node *first; /* The first node in the list */
132 Ecore_List_Node *last; /* The last node in the list */
133 Ecore_List_Node *current; /* The current node in the list */
135 Ecore_Free_Cb free_func; /* The callback to free data in nodes */
137 int nodes; /* The number of nodes in the list */
138 int index; /* The position from the front of the
139 list of current node */
142 EAPI int ecore_direct_compare(const void *key1, const void *key2);
143 EAPI int ecore_str_compare(const void *key1, const void *key2);
145 EAPI unsigned int ecore_direct_hash(const void *key);
146 EAPI unsigned int ecore_str_hash(const void *key);
148 /* Creating and initializing new list structures */
149 EAPI Ecore_List * ecore_list_new(void);
150 EAPI int ecore_list_init(Ecore_List *list);
152 /* Adding items to the list */
153 EAPI int ecore_list_append(Ecore_List *list, void *_data);
154 EAPI int ecore_list_prepend(Ecore_List *list, void *_data);
155 EAPI int ecore_list_insert(Ecore_List *list, void *_data);
156 EAPI int ecore_list_append_list(Ecore_List *list,
158 EAPI int ecore_list_prepend_list(Ecore_List *list,
159 Ecore_List *prepend);
161 /* Removing items from the list */
162 EAPI int ecore_list_remove_destroy(Ecore_List *list);
163 EAPI void * ecore_list_remove(Ecore_List *list);
164 EAPI void * ecore_list_first_remove(Ecore_List *list);
165 EAPI void * ecore_list_last_remove(Ecore_List *list);
167 /* Retrieve the current position in the list */
168 EAPI void * ecore_list_current(Ecore_List *list);
169 EAPI void * ecore_list_first(Ecore_List *list);
170 EAPI void * ecore_list_last(Ecore_List *list);
171 EAPI int ecore_list_index(Ecore_List *list);
172 EAPI int ecore_list_count(Ecore_List *list);
174 /* Traversing the list */
175 EAPI int ecore_list_for_each(Ecore_List *list,
176 Ecore_For_Each function,
178 EAPI void * ecore_list_first_goto(Ecore_List *list);
179 EAPI void * ecore_list_last_goto(Ecore_List *list);
180 EAPI void * ecore_list_index_goto(Ecore_List *list, int index);
181 EAPI void * ecore_list_goto(Ecore_List *list, const void *_data);
183 /* Traversing the list and returning data */
184 EAPI void * ecore_list_next(Ecore_List *list);
185 EAPI void * ecore_list_find(Ecore_List *list,
186 Ecore_Compare_Cb function,
187 const void *user_data);
189 /* Sorting the list */
190 EAPI int ecore_list_sort(Ecore_List *list,
191 Ecore_Compare_Cb compare,
193 EAPI int ecore_list_mergesort(Ecore_List *list,
194 Ecore_Compare_Cb compare,
196 EAPI int ecore_list_heapsort(Ecore_List *list,
197 Ecore_Compare_Cb compare,
199 EAPI void ecore_list_merge(Ecore_List *list, Ecore_List *l2,
200 Ecore_Compare_Cb, char order);
202 /* Check to see if there is any data in the list */
203 EAPI int ecore_list_empty_is(Ecore_List *list);
205 /* Remove every node in the list without freeing the list itself */
206 EAPI int ecore_list_clear(Ecore_List *list);
207 /* Free the list and it's contents */
208 EAPI void ecore_list_destroy(Ecore_List *list);
210 /* Creating and initializing list nodes */
211 EAPI Ecore_List_Node *ecore_list_node_new(void);
212 EAPI int ecore_list_node_init(Ecore_List_Node *newNode);
214 /* Destroying nodes */
215 EAPI int ecore_list_node_destroy(Ecore_List_Node *_e_node,
216 Ecore_Free_Cb free_func);
218 EAPI int ecore_list_free_cb_set(Ecore_List *list,
219 Ecore_Free_Cb free_func);
221 typedef Ecore_List Ecore_DList;
222 # define ECORE_DLIST(dlist) ((Ecore_DList *)dlist)
224 typedef struct _ecore_dlist_node Ecore_DList_Node;
225 # define ECORE_DLIST_NODE(dlist) ((Ecore_DList_Node *)dlist)
227 struct _ecore_dlist_node
229 Ecore_List_Node single;
230 Ecore_DList_Node *previous;
233 /* Creating and initializing new list structures */
234 EAPI Ecore_DList *ecore_dlist_new(void);
235 EAPI int ecore_dlist_init(Ecore_DList *list);
236 EAPI void ecore_dlist_destroy(Ecore_DList *list);
238 /* Adding items to the list */
239 EAPI int ecore_dlist_append(Ecore_DList *_e_dlist, void *_data);
240 EAPI int ecore_dlist_prepend(Ecore_DList *_e_dlist, void *_data);
241 EAPI int ecore_dlist_insert(Ecore_DList *_e_dlist, void *_data);
242 EAPI int ecore_dlist_append_list(Ecore_DList *_e_dlist,
243 Ecore_DList *append);
244 EAPI int ecore_dlist_prepend_list(Ecore_DList *_e_dlist,
245 Ecore_DList *prepend);
247 /* Info about list's state */
248 # define ecore_dlist_first(list) ecore_list_first(list)
249 # define ecore_dlist_last(list) ecore_list_last(list)
250 EAPI void * ecore_dlist_current(Ecore_DList *list);
251 EAPI int ecore_dlist_index(Ecore_DList *list);
252 # define ecore_dlist_count(list) ecore_list_count(list)
254 /* Removing items from the list */
255 EAPI void * ecore_dlist_remove(Ecore_DList *_e_dlist);
256 EAPI void * ecore_dlist_first_remove(Ecore_DList *_e_dlist);
257 EAPI int ecore_dlist_remove_destroy(Ecore_DList *list);
258 EAPI void * ecore_dlist_last_remove(Ecore_DList *_e_dlist);
260 /* Traversing the list */
261 # define ecore_dlist_for_each(list, function, user_data) \
262 ecore_list_for_each(list, function, user_data)
263 EAPI void * ecore_dlist_first_goto(Ecore_DList *_e_dlist);
264 EAPI void * ecore_dlist_last_goto(Ecore_DList *_e_dlist);
265 EAPI void * ecore_dlist_index_goto(Ecore_DList *_e_dlist, int index);
266 EAPI void * ecore_dlist_goto(Ecore_DList *_e_dlist, void *_data);
268 /* Traversing the list and returning data */
269 EAPI void * ecore_dlist_next(Ecore_DList *list);
270 EAPI void * ecore_dlist_previous(Ecore_DList *list);
272 /* Sorting the list */
273 EAPI int ecore_dlist_sort(Ecore_DList *list,
274 Ecore_Compare_Cb compare,
276 EAPI int ecore_dlist_mergesort(Ecore_DList *list,
277 Ecore_Compare_Cb compare,
279 # define ecore_dlist_heapsort(list, compare, order) \
280 ecore_list_heapsort(list, compare, order)
281 EAPI void ecore_dlist_merge(Ecore_DList *list, Ecore_DList *l2,
282 Ecore_Compare_Cb, char order);
284 /* Check to see if there is any data in the list */
285 EAPI int ecore_dlist_empty_is(Ecore_DList *_e_dlist);
287 /* Remove every node in the list without free'ing it */
288 EAPI int ecore_dlist_clear(Ecore_DList *_e_dlist);
290 /* Creating and initializing list nodes */
291 EAPI int ecore_dlist_node_init(Ecore_DList_Node *node);
292 EAPI Ecore_DList_Node *ecore_dlist_node_new(void);
294 /* Destroying nodes */
295 EAPI int ecore_dlist_node_destroy(Ecore_DList_Node *node,
296 Ecore_Free_Cb free_func);
298 EAPI int ecore_dlist_free_cb_set(Ecore_DList *dlist,
299 Ecore_Free_Cb free_func);
304 * Hash Table Implementation:
306 * Traditional hash table implementation. I had tried a list of tables
307 * approach to save on the realloc's but it ended up being much slower than
308 * the traditional approach.
311 typedef struct _ecore_hash_node Ecore_Hash_Node;
312 # define ECORE_HASH_NODE(hash) ((Ecore_Hash_Node *)hash)
314 struct _ecore_hash_node
316 Ecore_Hash_Node *next; /* Pointer to the next node in the bucket list */
317 void *key; /* The key for the data node */
318 void *value; /* The value associated with this node */
321 typedef struct _ecore_hash Ecore_Hash;
322 # define ECORE_HASH(hash) ((Ecore_Hash *)hash)
326 Ecore_Hash_Node **buckets;
327 int size; /* An index into the table of primes to
329 int nodes; /* The number of nodes currently in the hash */
331 int index; /* The current index into the bucket table */
333 Ecore_Compare_Cb compare; /* The function used to compare node values */
334 Ecore_Hash_Cb hash_func; /* The callback function to determine hash */
336 Ecore_Free_Cb free_key; /* The callback function to free key */
337 Ecore_Free_Cb free_value; /* The callback function to free value */
340 /* Create and initialize a hash */
341 EAPI Ecore_Hash *ecore_hash_new(Ecore_Hash_Cb hash_func,
342 Ecore_Compare_Cb compare);
343 EAPI int ecore_hash_init(Ecore_Hash *hash,
344 Ecore_Hash_Cb hash_func,
345 Ecore_Compare_Cb compare);
347 /* Functions related to freeing the data in the hash table */
348 EAPI int ecore_hash_free_key_cb_set(Ecore_Hash *hash,
349 Ecore_Free_Cb function);
350 EAPI int ecore_hash_free_value_cb_set(Ecore_Hash *hash,
351 Ecore_Free_Cb function);
352 EAPI void ecore_hash_destroy(Ecore_Hash *hash);
354 EAPI int ecore_hash_count(Ecore_Hash *hash);
355 EAPI int ecore_hash_for_each_node(Ecore_Hash *hash,
356 Ecore_For_Each for_each_func,
358 EAPI Ecore_List *ecore_hash_keys(Ecore_Hash *hash);
360 /* Retrieve and store data into the hash */
361 EAPI void * ecore_hash_get(Ecore_Hash *hash, const void *key);
362 EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
363 EAPI int ecore_hash_hash_set(Ecore_Hash *hash, Ecore_Hash *set);
364 EAPI void * ecore_hash_remove(Ecore_Hash *hash, const void *key);
365 EAPI void * ecore_hash_find(Ecore_Hash *hash,
366 Ecore_Compare_Cb compare,
368 EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
369 EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
372 typedef struct _ecore_heap Ecore_Sheap;
373 # define ECORE_HEAP(heap) ((Ecore_Sheap *)heap)
383 /* Callback for comparing node values, default is direct comparison */
384 Ecore_Compare_Cb compare;
386 /* Callback for freeing node data, default is NULL */
387 Ecore_Free_Cb free_func;
390 EAPI Ecore_Sheap *ecore_sheap_new(Ecore_Compare_Cb compare, int size);
391 EAPI void ecore_sheap_destroy(Ecore_Sheap *heap);
392 EAPI int ecore_sheap_init(Ecore_Sheap *heap,
393 Ecore_Compare_Cb compare,
395 EAPI int ecore_sheap_free_cb_set(Ecore_Sheap *heap,
396 Ecore_Free_Cb free_func);
397 EAPI int ecore_sheap_insert(Ecore_Sheap *heap, void *data);
398 EAPI void * ecore_sheap_extract(Ecore_Sheap *heap);
399 EAPI void * ecore_sheap_extreme(Ecore_Sheap *heap);
400 EAPI int ecore_sheap_change(Ecore_Sheap *heap,
403 EAPI int ecore_sheap_compare_set(Ecore_Sheap *heap,
404 Ecore_Compare_Cb compare);
405 EAPI void ecore_sheap_order_set(Ecore_Sheap *heap, char order);
406 EAPI void ecore_sheap_sort(Ecore_Sheap *heap);
408 EAPI void * ecore_sheap_item(Ecore_Sheap *heap, int i);
411 typedef struct _ecore_string Ecore_String;
418 EAPI int ecore_string_init();
419 EAPI void ecore_string_shutdown();
420 EAPI const char *ecore_string_instance(const char *string);
421 EAPI void ecore_string_release(const char *string);
423 typedef struct _Ecore_Tree_Node Ecore_Tree_Node;
424 # define ECORE_TREE_NODE(object) ((Ecore_Tree_Node *)object)
425 struct _Ecore_Tree_Node
428 /* The actual data for each node */
432 /* Pointers to surrounding nodes */
433 Ecore_Tree_Node *parent;
434 Ecore_Tree_Node *left_child;
435 Ecore_Tree_Node *right_child;
437 /* Book keeping information for quicker balancing of the tree */
442 typedef struct _Ecore_Tree Ecore_Tree;
443 # define ECORE_TREE(object) ((Ecore_Tree *)object)
446 /* Nodes of the tree */
447 Ecore_Tree_Node *tree;
449 /* Callback for comparing node values, default is direct comparison */
450 Ecore_Compare_Cb compare_func;
452 /* Callback for freeing node data, default is NULL */
453 Ecore_Free_Cb free_value;
454 /* Callback for freeing node key, default is NULL */
455 Ecore_Free_Cb free_key;
458 /* Some basic tree functions */
459 /* Allocate and initialize a new tree */
460 EAPI Ecore_Tree * ecore_tree_new(Ecore_Compare_Cb compare_func);
461 /* Initialize a new tree */
462 EAPI int ecore_tree_init(Ecore_Tree *tree,
463 Ecore_Compare_Cb compare_func);
466 EAPI int ecore_tree_destroy(Ecore_Tree *tree);
467 /* Check to see if the tree has any nodes in it */
468 EAPI int ecore_tree_empty_is(Ecore_Tree *tree);
470 /* Retrieve the value associated with key */
471 EAPI void * ecore_tree_get(Ecore_Tree *tree, const void *key);
472 EAPI Ecore_Tree_Node *ecore_tree_get_node(Ecore_Tree *tree, const void *key);
473 /* Retrieve the value of node with key greater than or equal to key */
474 EAPI void * ecore_tree_closest_larger_get(Ecore_Tree *tree,
476 /* Retrieve the value of node with key less than or equal to key */
477 EAPI void * ecore_tree_closest_smaller_get(Ecore_Tree *tree,
480 /* Set the value associated with key to value */
481 EAPI int ecore_tree_set(Ecore_Tree *tree, void *key, void *value);
482 /* Remove the key from the tree */
483 EAPI int ecore_tree_remove(Ecore_Tree *tree, const void *key);
485 /* Add a node to the tree */
486 EAPI int ecore_tree_node_add(Ecore_Tree *tree,
487 Ecore_Tree_Node *node);
488 /* Remove a node from the tree */
489 EAPI int ecore_tree_node_remove(Ecore_Tree *tree,
490 Ecore_Tree_Node *node);
492 /* For each node in the tree perform the for_each_func function */
493 /* For this one pass in the node */
494 EAPI int ecore_tree_for_each_node(Ecore_Tree *tree,
495 Ecore_For_Each for_each_func,
497 /* And here pass in the node's value */
498 EAPI int ecore_tree_for_each_node_value(
504 /* Some basic node functions */
505 /* Initialize a node */
506 EAPI int ecore_tree_node_init(Ecore_Tree_Node *new_node);
507 /* Allocate and initialize a new node */
508 EAPI Ecore_Tree_Node *ecore_tree_node_new(void);
509 /* Free the desired node */
510 EAPI int ecore_tree_node_destroy(Ecore_Tree_Node *node,
511 Ecore_Free_Cb free_value,
512 Ecore_Free_Cb free_key);
514 /* Set the node's key to key */
515 EAPI int ecore_tree_node_key_set(Ecore_Tree_Node *node, void *key);
516 /* Retrieve the key in node */
517 EAPI void * ecore_tree_node_key_get(Ecore_Tree_Node *node);
519 /* Set the node's value to value */
520 EAPI int ecore_tree_node_value_set(Ecore_Tree_Node *node,
522 /* Retrieve the value in node */
523 EAPI void * ecore_tree_node_value_get(Ecore_Tree_Node *node);
525 /* Add a function to free the data stored in nodes */
526 EAPI int ecore_tree_free_value_cb_set(Ecore_Tree *tree,
527 Ecore_Free_Cb free_value);
528 /* Add a function to free the keys stored in nodes */
529 EAPI int ecore_tree_free_key_cb_set(Ecore_Tree *tree,
530 Ecore_Free_Cb free_key);
533 EAPI Ecore_Strbuf * ecore_strbuf_new(void);
534 EAPI void ecore_strbuf_free(Ecore_Strbuf *buf);
535 EAPI void ecore_strbuf_append(Ecore_Strbuf *buf, const char *str);
536 EAPI void ecore_strbuf_append_char(Ecore_Strbuf *buf, char c);
537 EAPI void ecore_strbuf_insert(Ecore_Strbuf *buf, const char *str,
539 # define ecore_strbuf_prepend(buf, str) ecore_strbuf_insert(buf, str, 0)
540 EAPI const char * ecore_strbuf_string_get(Ecore_Strbuf *buf);
541 EAPI size_t ecore_strbuf_length_get(Ecore_Strbuf *buf);
542 EAPI int ecore_strbuf_replace(Ecore_Strbuf *buf, const char *str,
543 const char *with, unsigned int n);
544 # define ecore_strbuf_replace_first(buf, str, with) \
545 ecore_strbuf_replace(buf, str, with, 1)
546 EAPI int ecore_strbuf_replace_all(Ecore_Strbuf *buf,
550 extern int ecore_str_compare(const void *key1, const void *key2);
551 extern int ecore_direct_compare(const void *key1, const void *key2);
552 extern unsigned int ecore_str_hash(const void *key);
557 #endif /* _ECORE_DATA_H */