Derive-C
Loading...
Searching...
No Matches
staticvec.c File Reference
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <derive-c/structures/staticvec/template.h>
Include dependency graph for staticvec.c:

Go to the source code of this file.

Macros

#define MAX_CAPACITY   8
#define T   unsigned char
#define SELF   staticvec_chars
#define INPLACE_CAPACITY   MAX_CAPACITY

Functions

void push_example ()
void iter_example ()
int main ()

Macro Definition Documentation

◆ INPLACE_CAPACITY

#define INPLACE_CAPACITY   MAX_CAPACITY

Definition at line 13 of file staticvec.c.

◆ MAX_CAPACITY

#define MAX_CAPACITY   8
Examples
structures/staticvec.c.

Definition at line 9 of file staticvec.c.

◆ SELF

#define SELF   staticvec_chars

Definition at line 12 of file staticvec.c.

◆ T

#define T   unsigned char

Definition at line 11 of file staticvec.c.

Function Documentation

◆ iter_example()

void iter_example ( )
Examples
structures/staticvec.c.

Definition at line 39 of file staticvec.c.

39 {
40 staticvec_chars vec = staticvec_chars_new();
41
42 // Push characters into the static vector
43 for (unsigned char i = 0; i < MAX_CAPACITY; i++) {
44 staticvec_chars_push(&vec, 'a' + i);
45 }
46
47 // Iterate over the vector and print the items
48 staticvec_chars_iter_const iter = staticvec_chars_get_iter_const(&vec);
49 unsigned char const* item = NULL;
50 while (item = staticvec_chars_iter_const_next(&iter), item != NULL) {
51 printf("%u ", *item);
52 }
53 printf("\n");
54
55 staticvec_chars_delete(&vec);
56}
#define MAX_CAPACITY
Definition staticvec.c:9
Here is the caller graph for this function:

◆ main()

int main ( )

Definition at line 58 of file staticvec.c.

58 {
61}
void iter_example()
Definition staticvec.c:39
void push_example()
Definition staticvec.c:16
Here is the call graph for this function:

◆ push_example()

void push_example ( )
Examples
structures/staticvec.c.

Definition at line 16 of file staticvec.c.

16 {
17 staticvec_chars vec = staticvec_chars_new();
18
19 // Push characters into the static vector
20 for (unsigned char i = 0; i < MAX_CAPACITY; i++) {
21 staticvec_chars_push(&vec, i);
22 }
23
24 // Cannot push past the in-place capacity
25 assert(!staticvec_chars_try_push(&vec, 8));
26
27 // Check that the first 8 characters are in place
28 for (unsigned char i = 0; i < MAX_CAPACITY; i++) {
29 assert(*staticvec_chars_read(&vec, i) == i);
30 }
31
32 // The next two should be NULL since they exceed the in-place capacity
33 assert(staticvec_chars_try_read(&vec, MAX_CAPACITY) == NULL);
34 assert(staticvec_chars_try_read(&vec, MAX_CAPACITY + 1) == NULL);
35
36 staticvec_chars_delete(&vec);
37}
Here is the caller graph for this function: