PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 0ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/test-suite/java_lib_various.i

#
Swig | 51 lines | 39 code | 11 blank | 1 comment | 0 complexity | 6a2edcdc7ec5497086cbbcd07b4adf5b MD5 | raw file
 1/* Java various.i library tests */
 2%module java_lib_various
 3
 4%include "various.i"
 5
 6%apply char **STRING_ARRAY { char **received };
 7%apply char **STRING_ARRAY { char **get_names };
 8%apply char **STRING_ARRAY { char **languages };
 9%apply char *BYTE { char *chars };
10%apply char **STRING_OUT { char **string_ptr };
11%typemap(freearg) char **languages "" // don't delete memory when setting global variable
12
13%{
14char *langs[] = { (char *)"Hungarian", (char *)"Afrikaans", (char *)"Norwegian", NULL };
15%}
16
17%inline %{
18char **languages = &langs[0];
19%}
20
21%inline %{
22
23int check_animals(char **received) {
24    const char *expected[] = {"Cat","Dog","Cow","Goat", 0};
25    int strings_match = 1;
26    int i=0;
27    while (expected[i]) {
28        if (strcmp(received[i], expected[i]) != 0)
29            strings_match = 0;
30        i++;
31    }
32    return strings_match;
33}
34
35char **get_names() {
36    static char *values[] = { (char *)"Dave", (char *)"Mike", (char *)"Susan", (char *)"John", (char *)"Michelle", NULL};
37    return &values[0];
38}
39
40void charout(char *chars) {
41    if(chars != NULL)
42        sprintf(chars, "by jove");
43}
44
45void char_ptr_ptr_out(char **string_ptr) {
46    static char ret[] = "returned string";
47    *string_ptr = ret;
48}
49
50%}
51