File: charvec.h

package info (click to toggle)
sim4 0.0.20121010-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,744 kB
  • ctags: 505
  • sloc: ansic: 5,807; makefile: 23; sh: 15
file content (37 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* genvec charvec char ; 1999-10-05 22:59:09 */
#ifndef HAS_GEN_charvec_H
#define HAS_GEN_charvec_H

#include <stdlib.h>
#include <string.h>
#include <assert.h>

typedef struct charvec {
    char *a;
    unsigned int len;
    unsigned int max;
    void *((*alloc)(void*, size_t));
    void (*free)(void*);
} charvec_t;

#define charvec_INIT(a,f)  {0, 0, 0, a, f}

charvec_t* charvec_new(void* ((*)(void*, size_t)), void ((*)(void*)));
charvec_t* charvec_free(charvec_t *t);
int charvec_init(charvec_t *t, void* ((*)(void*,size_t)), void((*)(void*)));
int charvec_fini(charvec_t *t);
int charvec_need(charvec_t *t, unsigned int n);
int charvec_more(charvec_t *t, unsigned int n);
int charvec_append(charvec_t *t, char e);
int charvec_fit(charvec_t *t);

#ifndef GENVEC_INBOUNDS
#define GENVEC_INBOUNDS(t,n) ((0<=(n))&&((n)<(t)->len))
#endif

#ifndef GENVEC_GET
#define GENVEC_GET(t,n) (assert(GENVEC_INBOUNDS(t,n)) , (t)->a[n])
#endif

#endif