swig/Examples/c/std_vector/runme.c
Vadim Zeitlin d89a95a48c Use std/std_vector.i instead of a poor copy in c/std_vector.i
At the very least, this gives us a working vector<bool> and allows
"li_std_vector" unit test to pass. It is also just nice to reuse the existing
typemaps instead of having another copy of them.

As C doesn't have UTL, some parts of std_vector.i had to be excluded from it
however.
2016-09-15 01:27:41 +02:00

42 lines
993 B
C

#include <stdio.h>
#include "example_wrap.h"
int main() {
Klass *klass = Klass_new();
Vint *vint = Klass_vi_get(klass);
VA *va = Klass_va_get(klass);
printf("Vector of ints:\n");
printf("size=%d\ncapacity=%d\n\n", Vint_size(vint), Vint_capacity(vint));
int i;
for (i = 0; i < 10; i++)
Vint_push_back(vint, i*i);
printf("size=%d\ncapacity=%d\n\n", Vint_size(vint), Vint_capacity(vint));
for (i = 0; i < Vint_size(vint); i++)
printf("%d%c", Vint_get(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
Vint_clear(vint);
Vint_reserve(vint, 100);
printf("\nsize=%d\ncapacity=%d\n", Vint_size(vint), Vint_capacity(vint));
printf("\nVector of objects:\n");
for (i = 0; i < 10; i++) {
A *a = A_new_std_string_i("hello", i);
VA_push_back(va, a);
A_delete(a);
}
for (i = 0; i < VA_size(va); i++) {
A *a = VA_get(va, i);
printf("%s %d\n", A_name_get(a), A_value_get(a));
}
Klass_delete(klass);
SWIG_exit(0);
}