Derive-C
Loading...
Searching...
No Matches
staticvec.c File Reference
#include <assert.h>
#include <stdint.h>
#include <derive-c/macros/iterators.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 14 of file staticvec.c.

◆ MAX_CAPACITY

#define MAX_CAPACITY   8

Definition at line 10 of file staticvec.c.

◆ SELF

#define SELF   staticvec_chars

Definition at line 13 of file staticvec.c.

◆ T

#define T   unsigned char

Definition at line 12 of file staticvec.c.

Function Documentation

◆ iter_example()

void iter_example ( )
Examples
structures/staticvec.c.

Definition at line 40 of file staticvec.c.

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

◆ main()

int main ( )

Definition at line 59 of file staticvec.c.

59 {
62}
void iter_example()
Definition staticvec.c:40
void push_example()
Definition staticvec.c:17
Here is the call graph for this function:

◆ push_example()

void push_example ( )
Examples
structures/staticvec.c.

Definition at line 17 of file staticvec.c.

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