SimGrid  3.20
Versatile Simulation of Distributed Systems

Detailed Description

Don't get impressed, there is a lot of functions here, but traversing a dictionary is immediate with the
xbt_dict_foreach macro.

You only need the other functions in rare cases (they are not used directly in SG itself).

Here is an example (assuming that the dictionary contains strings, i.e., that the data argument of xbt_dict_set was always a null-terminated char*):

xbt_dict_cursor_t cursor=NULL;
 char *key,*data;

 xbt_dict_foreach(dict,cursor,key,data) {
    printf("   - Seen:  %s->%s\n",key,data);
 }
\warning Do not add or remove entries to the cache while traversing !!

Macros

#define xbt_dict_foreach(dict, cursor, key, data)
 

Typedefs

typedef struct s_xbt_dict_cursorxbt_dict_cursor_t
 Cursor on dictionaries (opaque type) More...
 

Functions

static xbt_dictelm_t xbt_dict_cursor_get_elm (xbt_dict_cursor_t cursor)
 
xbt_dict_cursor_t xbt_dict_cursor_new (const xbt_dict_t dict)
 Creator. More...
 
void xbt_dict_cursor_free (xbt_dict_cursor_t *cursor)
 Destructor. More...
 
void xbt_dict_cursor_rewind (xbt_dict_cursor_t cursor)
 Reinitialize the cursor. More...
 
char * xbt_dict_cursor_get_key (xbt_dict_cursor_t cursor)
 Get current key. More...
 
voidxbt_dict_cursor_get_data (xbt_dict_cursor_t cursor)
 Get current data. More...
 
void xbt_dict_cursor_set_data (xbt_dict_cursor_t cursor, void *data, void_f_pvoid_t free_ctn)
 
void xbt_dict_cursor_first (const xbt_dict_t dict, xbt_dict_cursor_t *cursor)
 Create the cursor if it does not exists. More...
 
void xbt_dict_cursor_step (xbt_dict_cursor_t cursor)
 Move to the next element. More...
 
int xbt_dict_cursor_get_or_free (xbt_dict_cursor_t *cursor, char **key, void **data)
 Get current data, or free the cursor if there is no data left. More...
 

Macro Definition Documentation

◆ xbt_dict_foreach

#define xbt_dict_foreach (   dict,
  cursor,
  key,
  data 
)
Parameters
dicta xbt_dict_t iterator
cursoran xbt_dict_cursor_t used as cursor
keya char*
dataa void** output
Note
An example of usage:
xbt_dict_cursor_t cursor = NULL;
char *key;
char *data;
xbt_dict_foreach(head, cursor, key, data) {
printf("Key %s with data %s\n",key,data);
}

Typedef Documentation

◆ xbt_dict_cursor_t

Cursor on dictionaries (opaque type)

Function Documentation

◆ xbt_dict_cursor_get_elm()

static xbt_dictelm_t xbt_dict_cursor_get_elm ( xbt_dict_cursor_t  cursor)
inlinestatic

◆ xbt_dict_cursor_new()

xbt_dict_cursor_t xbt_dict_cursor_new ( const xbt_dict_t  dict)
inline

Creator.

Parameters
dictthe dict

◆ xbt_dict_cursor_free()

void xbt_dict_cursor_free ( xbt_dict_cursor_t cursor)
inline

Destructor.

Parameters
cursorpoor victim

◆ xbt_dict_cursor_rewind()

void xbt_dict_cursor_rewind ( xbt_dict_cursor_t  cursor)
inline

Reinitialize the cursor.

Mandatory after removal or add in dict.

◆ xbt_dict_cursor_get_key()

char* xbt_dict_cursor_get_key ( xbt_dict_cursor_t  cursor)
inline

Get current key.

Parameters
cursorthe cursor
Returns
the current key

◆ xbt_dict_cursor_get_data()

void* xbt_dict_cursor_get_data ( xbt_dict_cursor_t  cursor)
inline

Get current data.

Parameters
cursorthe cursor
Returns
the current data

◆ xbt_dict_cursor_set_data()

void xbt_dict_cursor_set_data ( xbt_dict_cursor_t  cursor,
void data,
void_f_pvoid_t  free_ctn 
)

◆ xbt_dict_cursor_first()

void xbt_dict_cursor_first ( const xbt_dict_t  dict,
xbt_dict_cursor_t cursor 
)
inline

Create the cursor if it does not exists.

Rewind it in any case.

Parameters
dicton what to let the cursor iterate
[out]cursordest address

◆ xbt_dict_cursor_step()

void xbt_dict_cursor_step ( xbt_dict_cursor_t  cursor)
inline

Move to the next element.

◆ xbt_dict_cursor_get_or_free()

int xbt_dict_cursor_get_or_free ( xbt_dict_cursor_t cursor,
char **  key,
void **  data 
)
inline

Get current data, or free the cursor if there is no data left.

Returns
true if it's ok, false if there is no more data