9 # ifdef EFL_ECORE_BUILD
11 # define EAPI __declspec(dllexport)
14 # endif /* ! DLL_EXPORT */
16 # define EAPI __declspec(dllimport)
17 # endif /* ! EFL_ECORE_BUILD */
21 # define EAPI __attribute__ ((visibility("default")))
30 /* we need this for size_t */
35 * @brief Contains threading, list, hash, debugging and tree functions.
43 # define __FUNCTION__ "unknown"
49 EAPI extern const unsigned int ecore_prime_table[];
51 # define ECORE_SORT_MIN 0
52 # define ECORE_SORT_MAX 1
54 typedef void (*Ecore_For_Each) (void *value, void *user_data);
55 # define ECORE_FOR_EACH(function) ((Ecore_For_Each)function)
57 typedef void (*Ecore_Free_Cb) (void *data);
58 # define ECORE_FREE_CB(func) ((Ecore_Free_Cb)func)
60 typedef unsigned int (*Ecore_Hash_Cb) (const void *key);
61 # define ECORE_HASH_CB(function) ((Ecore_Hash_Cb)function)
63 typedef int (*Ecore_Compare_Cb) (const void *data1, const void *data2);
64 # define ECORE_COMPARE_CB(function) ((Ecore_Compare_Cb)function)
66 typedef struct _ecore_list Ecore_List;
67 # define ECORE_LIST(list) ((Ecore_List *)list)
69 typedef struct _ecore_list_node Ecore_List_Node;
70 # define ECORE_LIST_NODE(node) ((Ecore_List_Node *)node)
72 typedef struct _ecore_strbuf Ecore_Strbuf;
73 # define ECORE_STRBUF(buf) ((Ecore_Strbuf *)buf)
75 struct _ecore_list_node {
77 struct _ecore_list_node *next;
81 Ecore_List_Node *first; /* The first node in the list */
82 Ecore_List_Node *last; /* The last node in the list */
83 Ecore_List_Node *current; /* The current node in the list */
85 Ecore_Free_Cb free_func; /* The callback to free data in nodes */
87 int nodes; /* The number of nodes in the list */
88 int index; /* The position from the front of the
89 list of current node */
92 EAPI int ecore_direct_compare(const void *key1, const void *key2);
93 EAPI int ecore_str_compare(const void *key1, const void *key2);
95 EAPI unsigned int ecore_direct_hash(const void *key);
96 EAPI unsigned int ecore_str_hash(const void *key);
98 /* Creating and initializing new list structures */
99 EAPI Ecore_List *ecore_list_new(void);
100 EAPI int ecore_list_init(Ecore_List *list);
102 /* Adding items to the list */
103 EAPI int ecore_list_append(Ecore_List * list, void *_data);
104 EAPI int ecore_list_prepend(Ecore_List * list, void *_data);
105 EAPI int ecore_list_insert(Ecore_List * list, void *_data);
106 EAPI int ecore_list_append_list(Ecore_List * list, Ecore_List * append);
107 EAPI int ecore_list_prepend_list(Ecore_List * list, Ecore_List * prepend);
109 /* Removing items from the list */
110 EAPI int ecore_list_remove_destroy(Ecore_List *list);
111 EAPI void *ecore_list_remove(Ecore_List * list);
112 EAPI void *ecore_list_first_remove(Ecore_List * list);
113 EAPI void *ecore_list_last_remove(Ecore_List * list);
115 /* Retrieve the current position in the list */
116 EAPI void *ecore_list_current(Ecore_List * list);
117 EAPI void *ecore_list_first(Ecore_List * list);
118 EAPI void *ecore_list_last(Ecore_List * list);
119 EAPI int ecore_list_index(Ecore_List * list);
120 EAPI int ecore_list_count(Ecore_List * list);
122 /* Traversing the list */
123 EAPI int ecore_list_for_each(Ecore_List *list, Ecore_For_Each function,
125 EAPI void *ecore_list_first_goto(Ecore_List * list);
126 EAPI void *ecore_list_last_goto(Ecore_List * list);
127 EAPI void *ecore_list_index_goto(Ecore_List * list, int index);
128 EAPI void *ecore_list_goto(Ecore_List * list, const void *_data);
130 /* Traversing the list and returning data */
131 EAPI void *ecore_list_next(Ecore_List * list);
132 EAPI void *ecore_list_find(Ecore_List *list, Ecore_Compare_Cb function,
133 const void *user_data);
135 /* Sorting the list */
136 EAPI int ecore_list_sort(Ecore_List *list, Ecore_Compare_Cb compare,
138 EAPI int ecore_list_mergesort(Ecore_List *list, Ecore_Compare_Cb compare,
140 EAPI int ecore_list_heapsort(Ecore_List *list, Ecore_Compare_Cb compare,
142 EAPI void ecore_list_merge(Ecore_List *list, Ecore_List *l2,
143 Ecore_Compare_Cb, char order);
145 /* Check to see if there is any data in the list */
146 EAPI int ecore_list_empty_is(Ecore_List * list);
148 /* Remove every node in the list without freeing the list itself */
149 EAPI int ecore_list_clear(Ecore_List * list);
150 /* Free the list and it's contents */
151 EAPI void ecore_list_destroy(Ecore_List *list);
153 /* Creating and initializing list nodes */
154 EAPI Ecore_List_Node *ecore_list_node_new(void);
155 EAPI int ecore_list_node_init(Ecore_List_Node *newNode);
157 /* Destroying nodes */
158 EAPI int ecore_list_node_destroy(Ecore_List_Node * _e_node, Ecore_Free_Cb free_func);
160 EAPI int ecore_list_free_cb_set(Ecore_List * list, Ecore_Free_Cb free_func);
162 typedef Ecore_List Ecore_DList;
163 # define ECORE_DLIST(dlist) ((Ecore_DList *)dlist)
165 typedef struct _ecore_dlist_node Ecore_DList_Node;
166 # define ECORE_DLIST_NODE(dlist) ((Ecore_DList_Node *)dlist)
168 struct _ecore_dlist_node {
169 Ecore_List_Node single;
170 Ecore_DList_Node *previous;
173 /* Creating and initializing new list structures */
174 EAPI Ecore_DList *ecore_dlist_new(void);
175 EAPI int ecore_dlist_init(Ecore_DList *list);
176 EAPI void ecore_dlist_destroy(Ecore_DList *list);
178 /* Adding items to the list */
179 EAPI int ecore_dlist_append(Ecore_DList * _e_dlist, void *_data);
180 EAPI int ecore_dlist_prepend(Ecore_DList * _e_dlist, void *_data);
181 EAPI int ecore_dlist_insert(Ecore_DList * _e_dlist, void *_data);
182 EAPI int ecore_dlist_append_list(Ecore_DList * _e_dlist, Ecore_DList * append);
183 EAPI int ecore_dlist_prepend_list(Ecore_DList * _e_dlist, Ecore_DList * prepend);
185 /* Info about list's state */
186 # define ecore_dlist_first(list) ecore_list_first(list)
187 # define ecore_dlist_last(list) ecore_list_last(list)
188 EAPI void *ecore_dlist_current(Ecore_DList *list);
189 EAPI int ecore_dlist_index(Ecore_DList *list);
190 # define ecore_dlist_count(list) ecore_list_count(list)
192 /* Removing items from the list */
193 EAPI void *ecore_dlist_remove(Ecore_DList * _e_dlist);
194 EAPI void *ecore_dlist_first_remove(Ecore_DList * _e_dlist);
195 EAPI int ecore_dlist_remove_destroy(Ecore_DList *list);
196 EAPI void *ecore_dlist_last_remove(Ecore_DList * _e_dlist);
198 /* Traversing the list */
199 # define ecore_dlist_for_each(list, function, user_data) \
200 ecore_list_for_each(list, function, user_data)
201 EAPI void *ecore_dlist_first_goto(Ecore_DList * _e_dlist);
202 EAPI void *ecore_dlist_last_goto(Ecore_DList * _e_dlist);
203 EAPI void *ecore_dlist_index_goto(Ecore_DList * _e_dlist, int index);
204 EAPI void *ecore_dlist_goto(Ecore_DList * _e_dlist, void *_data);
206 /* Traversing the list and returning data */
207 EAPI void *ecore_dlist_next(Ecore_DList * list);
208 EAPI void *ecore_dlist_previous(Ecore_DList * list);
210 /* Sorting the list */
211 EAPI int ecore_dlist_sort(Ecore_DList *list, Ecore_Compare_Cb compare,
213 EAPI int ecore_dlist_mergesort(Ecore_DList *list, Ecore_Compare_Cb compare,
215 # define ecore_dlist_heapsort(list, compare, order) \
216 ecore_list_heapsort(list, compare, order)
217 EAPI void ecore_dlist_merge(Ecore_DList *list, Ecore_DList *l2,
218 Ecore_Compare_Cb, char order);
220 /* Check to see if there is any data in the list */
221 EAPI int ecore_dlist_empty_is(Ecore_DList * _e_dlist);
223 /* Remove every node in the list without free'ing it */
224 EAPI int ecore_dlist_clear(Ecore_DList * _e_dlist);
226 /* Creating and initializing list nodes */
227 EAPI int ecore_dlist_node_init(Ecore_DList_Node * node);
228 EAPI Ecore_DList_Node *ecore_dlist_node_new(void);
230 /* Destroying nodes */
231 EAPI int ecore_dlist_node_destroy(Ecore_DList_Node * node, Ecore_Free_Cb free_func);
233 EAPI int ecore_dlist_free_cb_set(Ecore_DList * dlist, Ecore_Free_Cb free_func);
238 * Hash Table Implementation:
240 * Traditional hash table implementation. I had tried a list of tables
241 * approach to save on the realloc's but it ended up being much slower than
242 * the traditional approach.
245 typedef struct _ecore_hash_node Ecore_Hash_Node;
246 # define ECORE_HASH_NODE(hash) ((Ecore_Hash_Node *)hash)
248 struct _ecore_hash_node {
249 Ecore_Hash_Node *next; /* Pointer to the next node in the bucket list */
250 void *key; /* The key for the data node */
251 void *value; /* The value associated with this node */
254 typedef struct _ecore_hash Ecore_Hash;
255 # define ECORE_HASH(hash) ((Ecore_Hash *)hash)
258 Ecore_Hash_Node **buckets;
259 int size; /* An index into the table of primes to
261 int nodes; /* The number of nodes currently in the hash */
263 int index; /* The current index into the bucket table */
265 Ecore_Compare_Cb compare; /* The function used to compare node values */
266 Ecore_Hash_Cb hash_func; /* The callback function to determine hash */
268 Ecore_Free_Cb free_key; /* The callback function to free key */
269 Ecore_Free_Cb free_value; /* The callback function to free value */
272 /* Create and initialize a hash */
273 EAPI Ecore_Hash *ecore_hash_new(Ecore_Hash_Cb hash_func, Ecore_Compare_Cb compare);
274 EAPI int ecore_hash_init(Ecore_Hash *hash, Ecore_Hash_Cb hash_func, Ecore_Compare_Cb compare);
276 /* Functions related to freeing the data in the hash table */
277 EAPI int ecore_hash_free_key_cb_set(Ecore_Hash *hash, Ecore_Free_Cb function);
278 EAPI int ecore_hash_free_value_cb_set(Ecore_Hash *hash, Ecore_Free_Cb function);
279 EAPI void ecore_hash_destroy(Ecore_Hash *hash);
281 EAPI int ecore_hash_count(Ecore_Hash *hash);
282 EAPI int ecore_hash_for_each_node(Ecore_Hash *hash, Ecore_For_Each for_each_func,
284 EAPI Ecore_List *ecore_hash_keys(Ecore_Hash *hash);
286 /* Retrieve and store data into the hash */
287 EAPI void *ecore_hash_get(Ecore_Hash *hash, const void *key);
288 EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
289 EAPI int ecore_hash_hash_set(Ecore_Hash *hash, Ecore_Hash *set);
290 EAPI void *ecore_hash_remove(Ecore_Hash *hash, const void *key);
291 EAPI void *ecore_hash_find(Ecore_Hash *hash, Ecore_Compare_Cb compare, const void *value);
292 EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
293 EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
296 typedef struct _ecore_path_group Ecore_Path_Group;
297 # define ECORE_PATH_GROUP(group) ((Ecore_Path_Group *)(group))
299 struct _ecore_path_group
305 * Create a new path group
307 EAPI Ecore_Path_Group *ecore_path_group_new(void);
310 * Destroy a previous path group
312 EAPI void ecore_path_group_del(Ecore_Path_Group *group);
315 * Add a directory to be searched for files
317 EAPI void ecore_path_group_add(Ecore_Path_Group *group, const char *path);
320 * Remove a directory to be searched for files
322 EAPI void ecore_path_group_remove(Ecore_Path_Group *group, const char *path);
325 * Find the absolute path if it exists in the group of paths
327 EAPI char * ecore_path_group_find(Ecore_Path_Group *group, const char *name);
330 * Get a list of all the available files in a path set
332 EAPI Ecore_List * ecore_path_group_available(Ecore_Path_Group *group);
335 typedef struct _ecore_plugin Ecore_Plugin;
342 * Load the specified plugin
344 EAPI Ecore_Plugin *ecore_plugin_load(Ecore_Path_Group *group, const char *plugin, const char *version);
347 * Unload the specified plugin
349 EAPI void ecore_plugin_unload(Ecore_Plugin * plugin);
352 * Lookup the specified symbol for the plugin
354 EAPI void *ecore_plugin_symbol_get(Ecore_Plugin * plugin, const char *symbol_name);
356 EAPI Ecore_List *ecore_plugin_available_get(Ecore_Path_Group *group);
359 typedef struct _ecore_heap Ecore_Sheap;
360 # define ECORE_HEAP(heap) ((Ecore_Sheap *)heap)
369 /* Callback for comparing node values, default is direct comparison */
370 Ecore_Compare_Cb compare;
372 /* Callback for freeing node data, default is NULL */
373 Ecore_Free_Cb free_func;
376 EAPI Ecore_Sheap *ecore_sheap_new(Ecore_Compare_Cb compare, int size);
377 EAPI void ecore_sheap_destroy(Ecore_Sheap *heap);
378 EAPI int ecore_sheap_init(Ecore_Sheap *heap, Ecore_Compare_Cb compare, int size);
379 EAPI int ecore_sheap_free_cb_set(Ecore_Sheap *heap, Ecore_Free_Cb free_func);
380 EAPI int ecore_sheap_insert(Ecore_Sheap *heap, void *data);
381 EAPI void *ecore_sheap_extract(Ecore_Sheap *heap);
382 EAPI void *ecore_sheap_extreme(Ecore_Sheap *heap);
383 EAPI int ecore_sheap_change(Ecore_Sheap *heap, void *item, void *newval);
384 EAPI int ecore_sheap_compare_set(Ecore_Sheap *heap, Ecore_Compare_Cb compare);
385 EAPI void ecore_sheap_order_set(Ecore_Sheap *heap, char order);
386 EAPI void ecore_sheap_sort(Ecore_Sheap *heap);
388 EAPI void *ecore_sheap_item(Ecore_Sheap *heap, int i);
391 typedef struct _ecore_string Ecore_String;
392 struct _ecore_string {
397 EAPI int ecore_string_init(void);
398 EAPI void ecore_string_shutdown(void);
399 EAPI const char *ecore_string_instance(const char *string);
400 EAPI void ecore_string_release(const char *string);
401 EAPI void ecore_string_hash_dump_graph(void);
402 EAPI void ecore_string_hash_dump_stats(void);
405 typedef struct _Ecore_Tree_Node Ecore_Tree_Node;
406 # define ECORE_TREE_NODE(object) ((Ecore_Tree_Node *)object)
407 struct _Ecore_Tree_Node {
409 /* The actual data for each node */
413 /* Pointers to surrounding nodes */
414 Ecore_Tree_Node *parent;
415 Ecore_Tree_Node *left_child;
416 Ecore_Tree_Node *right_child;
418 /* Book keeping information for quicker balancing of the tree */
423 typedef struct _Ecore_Tree Ecore_Tree;
424 # define ECORE_TREE(object) ((Ecore_Tree *)object)
426 /* Nodes of the tree */
427 Ecore_Tree_Node *tree;
429 /* Callback for comparing node values, default is direct comparison */
430 Ecore_Compare_Cb compare_func;
432 /* Callback for freeing node data, default is NULL */
433 Ecore_Free_Cb free_value;
434 /* Callback for freeing node key, default is NULL */
435 Ecore_Free_Cb free_key;
438 /* Some basic tree functions */
439 /* Allocate and initialize a new tree */
440 EAPI Ecore_Tree *ecore_tree_new(Ecore_Compare_Cb compare_func);
441 /* Initialize a new tree */
442 EAPI int ecore_tree_init(Ecore_Tree * tree, Ecore_Compare_Cb compare_func);
445 EAPI int ecore_tree_destroy(Ecore_Tree * tree);
446 /* Check to see if the tree has any nodes in it */
447 EAPI int ecore_tree_empty_is(Ecore_Tree * tree);
449 /* Retrieve the value associated with key */
450 EAPI void *ecore_tree_get(Ecore_Tree * tree, const void *key);
451 EAPI Ecore_Tree_Node *ecore_tree_get_node(Ecore_Tree * tree, const void *key);
452 /* Retrieve the value of node with key greater than or equal to key */
453 EAPI void *ecore_tree_closest_larger_get(Ecore_Tree * tree, const void *key);
454 /* Retrieve the value of node with key less than or equal to key */
455 EAPI void *ecore_tree_closest_smaller_get(Ecore_Tree * tree, const void *key);
457 /* Set the value associated with key to value */
458 EAPI int ecore_tree_set(Ecore_Tree * tree, void *key, void *value);
459 /* Remove the key from the tree */
460 EAPI int ecore_tree_remove(Ecore_Tree * tree, const void *key);
462 /* Add a node to the tree */
463 EAPI int ecore_tree_node_add(Ecore_Tree * tree, Ecore_Tree_Node * node);
464 /* Remove a node from the tree */
465 EAPI int ecore_tree_node_remove(Ecore_Tree * tree, Ecore_Tree_Node * node);
467 /* For each node in the tree perform the for_each_func function */
468 /* For this one pass in the node */
469 EAPI int ecore_tree_for_each_node(Ecore_Tree * tree, Ecore_For_Each for_each_func,
471 /* And here pass in the node's value */
472 EAPI int ecore_tree_for_each_node_value(Ecore_Tree * tree,
473 Ecore_For_Each for_each_func,
476 /* Some basic node functions */
477 /* Initialize a node */
478 EAPI int ecore_tree_node_init(Ecore_Tree_Node * new_node);
479 /* Allocate and initialize a new node */
480 EAPI Ecore_Tree_Node *ecore_tree_node_new(void);
481 /* Free the desired node */
482 EAPI int ecore_tree_node_destroy(Ecore_Tree_Node * node,
483 Ecore_Free_Cb free_value, Ecore_Free_Cb free_key);
485 /* Set the node's key to key */
486 EAPI int ecore_tree_node_key_set(Ecore_Tree_Node * node, void *key);
487 /* Retrieve the key in node */
488 EAPI void *ecore_tree_node_key_get(Ecore_Tree_Node * node);
490 /* Set the node's value to value */
491 EAPI int ecore_tree_node_value_set(Ecore_Tree_Node * node, void *value);
492 /* Retrieve the value in node */
493 EAPI void *ecore_tree_node_value_get(Ecore_Tree_Node * node);
495 /* Add a function to free the data stored in nodes */
496 EAPI int ecore_tree_free_value_cb_set(Ecore_Tree * tree, Ecore_Free_Cb free_value);
497 /* Add a function to free the keys stored in nodes */
498 EAPI int ecore_tree_free_key_cb_set(Ecore_Tree * tree, Ecore_Free_Cb free_key);
501 EAPI Ecore_Strbuf * ecore_strbuf_new(void);
502 EAPI void ecore_strbuf_free(Ecore_Strbuf *buf);
503 EAPI void ecore_strbuf_append(Ecore_Strbuf *buf, const char *str);
504 EAPI void ecore_strbuf_append_char(Ecore_Strbuf *buf, char c);
505 EAPI void ecore_strbuf_insert(Ecore_Strbuf *buf, const char *str,
507 # define ecore_strbuf_prepend(buf, str) ecore_strbuf_insert(buf, str, 0)
508 EAPI const char * ecore_strbuf_string_get(Ecore_Strbuf *buf);
509 EAPI size_t ecore_strbuf_length_get(Ecore_Strbuf *buf);
510 EAPI int ecore_strbuf_replace(Ecore_Strbuf *buf, const char *str,
511 const char *with, unsigned int n);
512 # define ecore_strbuf_replace_first(buf, str, with) \
513 ecore_strbuf_replace(buf, str, with, 1)
514 EAPI int ecore_strbuf_replace_all(Ecore_Strbuf *buf, const char *str,
520 #endif /* _ECORE_DATA_H */