Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tiny conflict resolution
[simgrid.git] / include / xbt / lib.h
1 /* xbt/lib.h - api to a generic library                                     */
2
3 /* Copyright (c) 2011. 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_get_or_null(xbt_lib_t lib, const char *name,
30                                        int level);
31 XBT_PUBLIC(xbt_dictelm_t) xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key);
32 XBT_PUBLIC(void *) xbt_lib_get_level(xbt_dictelm_t elm, int level);
33
34 #define xbt_lib_length(lib) xbt_dict_length((lib)->dict)
35
36 /** @def xbt_lib_foreach
37     @hideinitializer */
38 #define xbt_lib_foreach(lib, cursor, key, data)         \
39   xbt_dict_foreach((lib)->dict, cursor, key, data)
40
41 SG_END_DECL()
42 #endif                          /* _XBT_LIB_H */