surfaces-unies/src/darray.h

51 lines
1.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* \file darray.h
* \brief Implémentation de \ref darray et déclaration des fonctions pour ce
* type
*/
#ifndef SRC_DARRAY_H_
#define SRC_DARRAY_H_
#include "errorcodes.h"
#include <stdint.h>
#include <stdlib.h>
/**
* \struct darray
* \brief Tableau dynamique
*
* Les objets `darray` offrent la possibilité davoir des tableaux à taille
* variable en C, similairement aux objets `vector` en C++.
*/
typedef struct {
void *begin; /*!< Pointeur sur le premier élément du tableau */
void *end; /*!< Pointeur sur lélément situé immédiatement après le dernier
élément du tableau */
uint64_t element_size; /*!< Taille des éléments stockés dans le tableau */
uint64_t capacity; /*!< Capacité maximale du tableau actuel */
} darray;
/// \brief Créé un nouvel objet \ref darray vide
darray *darrayNew(uint64_t element_size);
/// \brief Augmente la capacité d'un \ref darray
void darrayExtend(darray *self);
/// \brief Insère un élément à lendroit pointé dans un \ref darray
void darrayInsert(darray *self, void *pos, void *elem);
/// \brief Supprime lélément pointé dans lobjet \ref darray
void darrayErase(darray *self, void *pos);
/// \brief Retourne lélément du \ref darray au idx-ème index
void *darrayGet(darray *self, uint64_t idx);
/// \brief Insère un élément à la fin de lélément \ref darray
void darrayPushBack(darray *self, void *elem);
/// \brief Supprime le dernier élément de lélément \ref darray
void darrayPopBack(darray *self);
/// \brief Détruit lélément \ref darray
void darrayDelete(darray *self);
/// \brief Renvoie la taille de lélément \ref darray
uint64_t darraySize(darray *self);
/// \brief Renvoie la taille de lélément \ref darray
uint64_t darrayElemSize(darray *self);
#endif /* SRC_DARRAY_H_ */