/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
- * @brief DynArr are dynamically sized vector which may contain any type of variables.
- *
- * These are the SimGrid version of the dynamically size arrays, which all C programmer recode one day or another.
- *
- * For performance concerns, the content of DynArr must be homogeneous (in contrary to dictionnaries -- see the
- * \ref XBT_dict section). You thus have to provide the function which will be used to free the content at
- * structure creation (of type void_f_pvoid_t).
- *
- * @deprecated If you are using C++, you might want to use `std::vector` instead.
- *
- * \section XBT_dynar_exscal Example with scalar
- * \dontinclude dynar.cpp
- *
- * \skip Vars_decl
- * \skip dyn
- * \until iptr
- * \skip Populate_ints
- * \skip dyn
- * \until end_of_traversal
- * \skip shifting
- * \skip val
- * \until xbt_dynar_free
- *
- * \section XBT_dynar_exptr Example with pointed data
- *
- * \skip test_dynar_string
- * \skip dynar_t
- * \until s2
- * \skip Populate_str
- * \skip dyn
- * \until }
- * \skip macro
- * \until dynar_free
- * \skip end_of_doxygen
- * \until }
- *
- * 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.
- */
+ * @brief DynArr are dynamically sized vector which may contain any type of variables.
+ *
+ * These are the SimGrid version of the dynamically size arrays, which all C programmer recode one day or another.
+ *
+ * For performance concerns, the content of DynArr must be homogeneous (in contrary to dictionnaries -- see the
+ * @ref XBT_dict section). You thus have to provide the function which will be used to free the content at
+ * structure creation (of type void_f_pvoid_t).
+ *
+ * @deprecated If you are using C++, you might want to use `std::vector` instead.
+ *
+ * @section XBT_dynar_exscal Example with scalar
+ * @dontinclude dynar.cpp
+ *
+ * @skip Vars_decl
+ * @skip dyn
+ * @until iptr
+ * @skip Populate_ints
+ * @skip dyn
+ * @until end_of_traversal
+ * @skip shifting
+ * @skip val
+ * @until xbt_dynar_free
+ *
+ * @section XBT_dynar_exptr Example with pointed data
+ *
+ * @skip test_dynar_string
+ * @skip dynar_t
+ * @until s2
+ * @skip Populate_str
+ * @skip dyn
+ * @until }
+ * @skip macro
+ * @until dynar_free
+ * @skip end_of_doxygen
+ * @until }
+ *
+ * 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.
+ */
typedef struct xbt_dynar_s *xbt_dynar_t;
XBT_PUBLIC xbt_dynar_t xbt_dynar_new(const unsigned long elm_size, void_f_pvoid_t const free_f);
typedef struct xbt_dynar_s *xbt_dynar_t;
XBT_PUBLIC xbt_dynar_t xbt_dynar_new(const unsigned long elm_size, void_f_pvoid_t const free_f);
* This was made public to allow:
* - the inlining of the foreach elements
* - sending such beasts over the network
*
* This was made public to allow:
* - the inlining of the foreach elements
* - sending such beasts over the network
*
static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int idx, void* const dst)
{
if (!dynar) /* iterating over a NULL dynar is a no-op */
static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int idx, void* const dst)
{
if (!dynar) /* iterating over a NULL dynar is a no-op */
if (idx >= dynar->used) {
//XBT_DEBUG("Cursor on %p already on last elem", (void *) dynar);
if (idx >= dynar->used) {
//XBT_DEBUG("Cursor on %p already on last elem", (void *) dynar);
}
// XBT_DEBUG("Cash out cursor on %p at %u", (void *) dynar, *idx);
memcpy(dst, ((char *) dynar->data) + idx * dynar->elmsize, dynar->elmsize);
}
// XBT_DEBUG("Cash out cursor on %p at %u", (void *) dynar, *idx);
memcpy(dst, ((char *) dynar->data) + idx * dynar->elmsize, dynar->elmsize);
*
* 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.
*
* 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.