SysIo  1.9.0
Embedded Library and tools
vector.h
1 
8 #ifndef _SYSIO_VECTOR_H_
9 #define _SYSIO_VECTOR_H_
10 
11 #include <sysio/defs.h>
12 #ifdef __cplusplus
13  extern "C" {
14 #endif
15 /* ========================================================================== */
16 
24 /* macros =================================================================== */
25 
26 /* types ==================================================================== */
27 
31 typedef void * (*vVectorElmtNew) (void);
32 
36 typedef void (*vVectorElmtDestroy) (void *data);
37 
42 typedef int (*iVectorElmtMatch) (const void *key1, const void *key2);
43 
47 typedef const void * (*pvVectorElmtKey) (const void * element);
48 
49 /* structures =============================================================== */
54 typedef struct xVector {
55  void** data;
56  int size;
57  int alloc;
58  int growth;
59  union {
60  uint16_t flag;
61  struct {
62  uint16_t malloc: 1;
63  };
64  };
65  vVectorElmtNew fnew;
66  vVectorElmtDestroy fdestroy;
67  pvVectorElmtKey fkey;
68  iVectorElmtMatch fmatch;
69 } xVector;
70 
71 /* internal public functions ================================================ */
72 
84 int iVectorInit (xVector * vector, int growth, vVectorElmtNew fnew, vVectorElmtDestroy fdestroy);
85 
93 int iVectorInitSearch (xVector *vector, pvVectorElmtKey fkey, iVectorElmtMatch fmatch);
94 
100 int iVectorSize (const xVector * vector);
101 
113 int iVectorResize (xVector * vector, int new_size);
114 
124 void vVectorDestroy (xVector * vector);
125 
134 int iVectorClear (xVector * vector);
135 
147 int iVectorAppend (xVector * vector, void * data);
148 
154 void * pvVectorGet (const xVector * vector, int index);
155 
166 int iVectorRemove (xVector * vector, int index);
167 
183 int iVectorReplace (xVector * vector, int index, void * data);
184 
191 void * pvVectorFindFirst (const xVector * vector, const void * key);
192 
199 int iVectorFindFirstIndex (const xVector * vector, const void * key);
200 
206 /* ========================================================================== */
207 #ifdef __cplusplus
208  }
209 #endif
210 #endif /*_SYSIO_VECTOR_H_ defined */
void * pvVectorFindFirst(const xVector *vector, const void *key)
Chercher le premier élément correspondant à une clé
void ** data
Definition: vector.h:55
int growth
Definition: vector.h:58
int(* iVectorElmtMatch)(const void *key1, const void *key2)
Fonction de comparaison de 2 clés.
Definition: vector.h:42
int iVectorInitSearch(xVector *vector, pvVectorElmtKey fkey, iVectorElmtMatch fmatch)
Initialise les fonctions de recherche.
void(* vVectorElmtDestroy)(void *data)
Fonction qui libère la mémoire allouée à une donnée de le vecteur.
Definition: vector.h:36
int iVectorAppend(xVector *vector, void *data)
Ajout en fin de tableau.
int iVectorRemove(xVector *vector, int index)
Retire un élément.
const void *(* pvVectorElmtKey)(const void *element)
Retourne la clé d&#39;un élément.
Definition: vector.h:47
void *(* vVectorElmtNew)(void)
Fonction qui retourne un élément alloué avec une valeur par défaut.
Definition: vector.h:31
int iVectorReplace(xVector *vector, int index, void *data)
Modifie l&#39;élément pointé par une case.
int iVectorSize(const xVector *vector)
Taille du tableau en nombre d&#39;éléments.
int iVectorFindFirstIndex(const xVector *vector, const void *key)
Chercher l&#39;index du premier élément correspondant à une clé
int alloc
Definition: vector.h:57
int iVectorResize(xVector *vector, int new_size)
Modifie la taille.
void vVectorDestroy(xVector *vector)
Destruction d&#39;un tableau dynamique.
void * pvVectorGet(const xVector *vector, int index)
Pointeur sur l&#39;élément.
int size
Definition: vector.h:56
int iVectorClear(xVector *vector)
Vide un tableau dynamique.
int iVectorInit(xVector *vector, int growth, vVectorElmtNew fnew, vVectorElmtDestroy fdestroy)
Initialise un tableau dynamique.
Definition: vector.h:54