X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d2666c49067a3e25b5fa42a49b81cf8cc629ab78..5ab070a2054636f5dcf5f0b56d691b089c5d16e4:/include/xbt/dynar.h diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index 095187f380..b7529f34b1 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -1,6 +1,6 @@ /* dynar - a generic dynamic array */ -/* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -16,52 +16,52 @@ SG_BEGIN_DECL() /** @addtogroup XBT_dynar - * @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. + */ /** @defgroup XBT_dynar_cons Dynar constructor and destructor * @ingroup XBT_dynar * * @{ */ - /** \brief Dynar data type (opaque type) */ +/** @brief Dynar data type (opaque type) */ 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); @@ -92,7 +92,6 @@ 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 xbt_dynar_t xbt_dynar_sort_strings(xbt_dynar_t dynar); XBT_PUBLIC int xbt_dynar_compare(xbt_dynar_t d1, xbt_dynar_t d2, int (*compar)(const void*, const void*)); XBT_PUBLIC void* xbt_dynar_to_array(xbt_dynar_t dynar); @@ -190,12 +189,12 @@ XBT_PUBLIC void* xbt_dynar_pop_ptr(xbt_dynar_t const dynar); XBT_PUBLIC void xbt_dynar_cursor_rm(xbt_dynar_t dynar, unsigned int* const cursor); /* - * \warning DO NOT USE THIS STRUCTURE DIRECTLY! Instead, use the public interface: + * @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() + * @see xbt_dynar_length() */ typedef struct xbt_dynar_s { unsigned long size; @@ -210,11 +209,8 @@ static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int id if (!dynar) /* iterating over a NULL dynar is a no-op */ return 0; - if (idx >= dynar->used) { - //XBT_DEBUG("Cursor on %p already on last elem", (void *) dynar); + if (idx >= dynar->used) return 0; - } - // XBT_DEBUG("Cash out cursor on %p at %u", (void *) dynar, *idx); memcpy(dst, ((char *) dynar->data) + idx * dynar->elmsize, dynar->elmsize); @@ -229,14 +225,14 @@ static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int id * @hideinitializer * * Here is an example of usage: - * \code + * @code xbt_dynar_t dyn; unsigned int cpt; string *str; xbt_dynar_foreach (dyn,cpt,str) { printf("Seen %s\n",str); } -\endcode +@endcode * * 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. @@ -260,16 +256,4 @@ xbt_dynar_foreach (dyn,cpt,str) { /** @} */ SG_END_DECL() -#ifdef __cplusplus -namespace simgrid { -namespace xbt { -/** Dynar of `T*` which `delete` its values */ -template inline xbt_dynar_t newDeleteDynar() -{ - return xbt_dynar_new(sizeof(T*), [](void* p) { delete *(T**)p; }); -} -} -} -#endif - #endif /* XBT_DYNAR_H */