SimGrid  3.13
Versatile Simulation of Distributed Systems

Cursors are used to iterate over the structure. More...

Classes

struct  xbt_dynar_s
 

Macros

#define xbt_dynar_foreach(_dynar, _cursor, _data)
 Iterates over the whole dynar. More...
 
#define xbt_dynar_foreach_ptr(_dynar, _cursor, _ptr)
 

Typedefs

typedef struct xbt_dynar_s s_xbt_dynar_t
 

Functions

void xbt_dynar_cursor_rm (xbt_dynar_t dynar, unsigned int *const cursor)
 Removes and free the entry pointed by the cursor. More...
 
static int _xbt_dynar_cursor_get (const xbt_dynar_t dynar, unsigned int idx, void *const dst)
 

Detailed Description

Cursors are used to iterate over the structure.

Never add elements to the DynArr during the traversal. To remove elements, use the xbt_dynar_cursor_rm() function.

Do not call these function directly, but only within the xbt_dynar_foreach macro.

Macro Definition Documentation

#define xbt_dynar_foreach (   _dynar,
  _cursor,
  _data 
)

Iterates over the whole dynar.

Parameters
_dynarwhat to iterate over
_cursoran integer used as cursor
_data

Here is an example of usage:

1 xbt_dynar_t dyn;
2 unsigned int cpt;
3 string *str;
4 xbt_dynar_foreach (dyn,cpt,str) {
5  printf("Seen %s\n",str);
6 }

Note that underneath, that's a simple for loop with no real black magic involved. It's perfectly safe to interrupt a foreach with a break or a return statement.

#define xbt_dynar_foreach_ptr (   _dynar,
  _cursor,
  _ptr 
)
Value:
for ((_cursor) = 0 ; \
(_ptr = _cursor < _dynar->used ? xbt_dynar_get_ptr(_dynar,_cursor) : NULL) ; \
(_cursor)++ )
void * xbt_dynar_get_ptr(const xbt_dynar_t dynar, const unsigned long idx)
Retrieve a pointer to the Nth element of a dynar.
Definition: dynar.c:237

Typedef Documentation

typedef struct xbt_dynar_s s_xbt_dynar_t

Function Documentation

void xbt_dynar_cursor_rm ( xbt_dynar_t  dynar,
unsigned int *const  cursor 
)
inline

Removes and free the entry pointed by the cursor.

This function can be used while traversing without problem.

static int _xbt_dynar_cursor_get ( const xbt_dynar_t  dynar,
unsigned int  idx,
void *const  dst 
)
inlinestatic