Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New XBT module: file
[simgrid.git] / include / xbt / lib.h
1 /* xbt/lib.h - api to a generic library                                     */
2
3 /* Copyright (c) 2011, 2013-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef _XBT_LIB_H
10 #define _XBT_LIB_H
11
12 #include <xbt/dict.h>
13
14 SG_BEGIN_DECL()
15
16 typedef struct s_xbt_lib {
17   xbt_dict_t dict;
18   int levels;
19   void_f_pvoid_t *free_f;       /* This is actually a table */
20 } s_xbt_lib_t, *xbt_lib_t;
21
22 #define xbt_lib_cursor_t xbt_dict_cursor_t
23
24 XBT_PUBLIC(xbt_lib_t) xbt_lib_new(void);
25 XBT_PUBLIC(void) xbt_lib_free(xbt_lib_t * lib);
26 XBT_PUBLIC(int) xbt_lib_add_level(xbt_lib_t lib, void_f_pvoid_t free_f);
27 XBT_PUBLIC(void) xbt_lib_set(xbt_lib_t lib, const char *name, int level,
28                              void *obj);
29 XBT_PUBLIC(void) xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback);
30 XBT_PUBLIC(void *) xbt_lib_get_or_null(xbt_lib_t lib, const char *name,
31                                        int level);
32 XBT_PUBLIC(xbt_dictelm_t) xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key);
33 XBT_PUBLIC(void *) xbt_lib_get_level(xbt_dictelm_t elm, int level);
34 XBT_PUBLIC(void) xbt_lib_remove(xbt_lib_t lib, const char *key);
35
36 #define xbt_lib_length(lib) xbt_dict_length((lib)->dict)
37
38 /** @def xbt_lib_foreach
39     @hideinitializer */
40 #define xbt_lib_foreach(lib, cursor, key, data)         \
41   xbt_dict_foreach((lib)->dict, cursor, key, data)
42
43 SG_END_DECL()
44 #endif                          /* _XBT_LIB_H */