X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/30a925489c6e4d4a92042ef80de375c56ccb562b..13667460824c1a4d55d44f96adaee6eeda2394f4:/include/xbt/dynar.h diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index 8aa9d0db01..86751e859d 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -1,18 +1,17 @@ /* dynar - a generic dynamic array */ -/* Copyright (c) 2004-2007, 2009-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-2017. 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. */ -#ifndef _XBT_DYNAR_H -#define _XBT_DYNAR_H +#ifndef XBT_DYNAR_H +#define XBT_DYNAR_H #include /* memcpy */ -#include "xbt/base.h" /* SG_BEGIN_DECL */ -#include "xbt/function_types.h" +#include /* SG_BEGIN_DECL */ +#include SG_BEGIN_DECL() @@ -20,13 +19,15 @@ SG_BEGIN_DECL() * @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_ppvoid_t or void_f_pvoid_t). + * 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.c + * \dontinclude dynar.cpp * * \skip Vars_decl * \skip dyn @@ -39,7 +40,7 @@ SG_BEGIN_DECL() * \until xbt_dynar_free * * \section XBT_dynar_exptr Example with pointed data - * + * * \skip test_dynar_string * \skip dynar_t * \until s2 @@ -64,9 +65,11 @@ SG_BEGIN_DECL() 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); +XBT_PUBLIC(void) xbt_dynar_init(xbt_dynar_t dynar, const unsigned long elmsize, 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_data(xbt_dynar_t dynar); XBT_PUBLIC(void) xbt_dynar_shrink(xbt_dynar_t dynar, int empty_slots); XBT_PUBLIC(void) xbt_dynar_dump(xbt_dynar_t dynar); @@ -144,7 +147,7 @@ XBT_PUBLIC(void *) xbt_dynar_pop_ptr(xbt_dynar_t const dynar); * @{ */ - /** @brief Quick retrieval of scalar content + /** @brief Quick retrieval of scalar content * @hideinitializer */ # define xbt_dynar_get_as(dynar,idx,type) \ (*(type*)xbt_dynar_get_ptr((dynar),(idx))) @@ -152,19 +155,19 @@ XBT_PUBLIC(void *) xbt_dynar_pop_ptr(xbt_dynar_t const dynar); * @hideinitializer */ # define xbt_dynar_set_as(dynar,idx,type,val) \ (*(type*)xbt_dynar_set_at_ptr((dynar),(idx))) = val - /** @brief Quick retrieval of scalar content + /** @brief Quick retrieval of scalar content * @hideinitializer */ # define xbt_dynar_getlast_as(dynar,type) \ (*(type*)xbt_dynar_get_ptr((dynar),xbt_dynar_length(dynar)-1)) - /** @brief Quick retrieval of scalar content + /** @brief Quick retrieval of scalar content * @hideinitializer */ # define xbt_dynar_getfirst_as(dynar,type) \ (*(type*)xbt_dynar_get_ptr((dynar),0)) - /** @brief Quick insertion of scalar content + /** @brief Quick insertion of scalar content * @hideinitializer */ # define xbt_dynar_insert_at_as(dynar,idx,type,value) \ *(type*)xbt_dynar_insert_at_ptr(dynar,idx)=value - /** @brief Quick insertion of scalar content + /** @brief Quick insertion of scalar content * @hideinitializer */ # define xbt_dynar_push_as(dynar,type,value) \ *(type*)xbt_dynar_push_ptr(dynar)=value @@ -187,7 +190,7 @@ 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: * This was made public to allow: * - the inlining of the foreach elements @@ -219,8 +222,8 @@ static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int id return TRUE; } -/** @brief Iterates over the whole dynar. - * +/** @brief Iterates over the whole dynar. + * * @param _dynar what to iterate over * @param _cursor an integer used as cursor * @param _data @@ -235,7 +238,7 @@ xbt_dynar_foreach (dyn,cpt,str) { printf("Seen %s\n",str); } \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. */ @@ -258,15 +261,4 @@ xbt_dynar_foreach (dyn,cpt,str) { /** @} */ SG_END_DECL() -#ifdef __cplusplus -namespace simgrid { -namespace xbt { - inline void destroy(xbt_dynar_t s) - { - xbt_dynar_free(&s); - } -} -} -#endif - -#endif /* _XBT_DYNAR_H */ +#endif /* XBT_DYNAR_H */