-/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2007, 2009-2015. The SimGrid Team.
+ * Note that if you use dynars to store pointed data, the
+ * xbt_dynar_search(), xbt_dynar_search_or_negative() and
+ * xbt_dynar_member() won't be for you. Instead of comparing
+ * your pointed elements, they compare the pointer to them. See
+ * the documentation of xbt_dynar_search() for more info.
+ *
XBT_PUBLIC(xbt_dynar_t) xbt_dynar_new(const unsigned long elm_size,
void_f_pvoid_t const free_f);
XBT_PUBLIC(xbt_dynar_t) xbt_dynar_new(const unsigned long elm_size,
void_f_pvoid_t const free_f);
XBT_PUBLIC(void) xbt_dynar_free(xbt_dynar_t * dynar);
XBT_PUBLIC(void) xbt_dynar_free_voidp(void *dynar);
XBT_PUBLIC(void) xbt_dynar_free_container(xbt_dynar_t * dynar);
XBT_PUBLIC(void) xbt_dynar_free(xbt_dynar_t * dynar);
XBT_PUBLIC(void) xbt_dynar_free_voidp(void *dynar);
XBT_PUBLIC(void) xbt_dynar_free_container(xbt_dynar_t * dynar);
const int idx, const void *src);
XBT_PUBLIC(void) xbt_dynar_remove_at(xbt_dynar_t const dynar,
const int idx, void *const dst);
const int idx, const void *src);
XBT_PUBLIC(void) xbt_dynar_remove_at(xbt_dynar_t const dynar,
const int idx, void *const dst);
XBT_PUBLIC(unsigned int) xbt_dynar_search(xbt_dynar_t const dynar, void *elem);
XBT_PUBLIC(signed int) xbt_dynar_search_or_negative(xbt_dynar_t const dynar, void *const elem);
XBT_PUBLIC(int) xbt_dynar_member(xbt_dynar_t const dynar, void *elem);
XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar,
int_f_cpvoid_cpvoid_t compar_fn);
XBT_PUBLIC(unsigned int) xbt_dynar_search(xbt_dynar_t const dynar, void *elem);
XBT_PUBLIC(signed int) xbt_dynar_search_or_negative(xbt_dynar_t const dynar, void *const elem);
XBT_PUBLIC(int) xbt_dynar_member(xbt_dynar_t const dynar, void *elem);
XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar,
int_f_cpvoid_cpvoid_t compar_fn);
XBT_PUBLIC(void) xbt_dynar_three_way_partition(xbt_dynar_t const dynar,
int_f_pvoid_t color);
XBT_PUBLIC(int) xbt_dynar_compare(xbt_dynar_t d1, xbt_dynar_t d2,
XBT_PUBLIC(void) xbt_dynar_three_way_partition(xbt_dynar_t const dynar,
int_f_pvoid_t color);
XBT_PUBLIC(int) xbt_dynar_compare(xbt_dynar_t d1, xbt_dynar_t d2,
* DynArr during the traversal. To remove elements, use the
* xbt_dynar_cursor_rm() function.
*
* DynArr during the traversal. To remove elements, use the
* xbt_dynar_cursor_rm() function.
*
- * Do not call these functions directly, but only the xbt_dynar_foreach macro.
- *
- * For synchronized dynars, the dynar will be locked during the whole
- * loop and it will get unlocked automatically if you traverse all
- * elements. If you want to break the loop before the end, make sure
- * to call xbt_dynar_cursor_unlock() before the <tt>break;</tt>
+ * Do not call these function directly, but only within the xbt_dynar_foreach
+ * macro.
*
* @{
*/
XBT_PUBLIC(void) xbt_dynar_cursor_rm(xbt_dynar_t dynar,
unsigned int *const cursor);
*
* @{
*/
XBT_PUBLIC(void) xbt_dynar_cursor_rm(xbt_dynar_t dynar,
unsigned int *const cursor);
-/* do not use this structure internals directly, but use the public interface
- * This was made public to allow:
- * - the inlining of the foreach elements
- * - sending such beasts over the network
+/*
+ * \warning DO NOT USE THIS STRUCTURE DIRECTLY! Instead, use the public interface:
+ * This was made public to allow:
+ * - the inlining of the foreach elements
+ * - sending such beasts over the network
+ *
+ * \see xbt_dynar_length()
-static XBT_INLINE void
-_xbt_dynar_cursor_first(const xbt_dynar_t dynar,
- unsigned int *const cursor)
-{
- /* iterating over a NULL dynar is a no-op (but we don't want to have uninitialized counters) */
-
- //XBT_DEBUG("Set cursor on %p to the first position", (void *) dynar);
- *cursor = 0;
-}
-
static XBT_INLINE int
_xbt_dynar_cursor_get(const xbt_dynar_t dynar,
unsigned int idx, void *const dst)
static XBT_INLINE int
_xbt_dynar_cursor_get(const xbt_dynar_t dynar,
unsigned int idx, void *const dst)
- for (_xbt_dynar_cursor_first(_dynar,&(_cursor)) ; \
- _xbt_dynar_cursor_get(_dynar,_cursor,&_data) ; \
+ for ( (_cursor) = 0 ; \
+ _xbt_dynar_cursor_get(_dynar,_cursor,&_data) ; \
+ (_cursor)++ )
+
+#ifndef __cplusplus
+#define xbt_dynar_foreach_ptr(_dynar,_cursor,_ptr) \
+ for ((_cursor) = 0 ; \
+ (_ptr = _cursor < _dynar->used ? xbt_dynar_get_ptr(_dynar,_cursor) : NULL) ; \