File: glpk_java_arrays.i

package info (click to toggle)
glpk-java 1.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,580 kB
  • sloc: sh: 3,609; java: 1,794; xml: 259; makefile: 154; ansic: 35
file content (90 lines) | stat: -rw-r--r-- 2,041 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* File glpk_java_arrays.i
 *
 * Handling of arrays.
 */

%define %glp_array_functions(TYPE,NAME)
%typemap (out) TYPE* new_##NAME {
    if ($1 == NULL) {
        glp_java_throw_outofmemory(jenv, "$name: calloc failed, "
        "C-runtime heap is full.");
    }
    *(TYPE **)&$result = $1;
}
%{
static TYPE *new_##NAME(int nelements) {
  return (TYPE *) calloc(nelements,sizeof(TYPE));
}

static void delete_##NAME(TYPE *ary) { 
  if (ary != NULL) {
    free(ary);
  }
}

static TYPE NAME##_getitem(TYPE *ary, int index) {
  if (ary != NULL) {
    return ary[index];
  } else {
    return (TYPE) 0;
  }
}
static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
  if (ary != NULL) {
    ary[index] = value;
  }
}
%}

%javamethodmodifiers new_##NAME(int nelements) "
/**
 * Creates a new array of TYPE.
 * <p>The memory is allocated with calloc(). To free the memory you will have
 * to call delete&#95;NAME.
 *
 * An OutOfMemoryError error indicates that the C-runtime heap of the process
 * (not the Java object heap) is full.
 *
 * @param nelements number of elements
 * @return array
 */
public";
TYPE *new_##NAME(int nelements);

%javamethodmodifiers delete_##NAME(TYPE *ary) "
/**
 * Deletes an array of TYPE.
 * <p>The memory is deallocated with free().
 *
 * @param ary array
 */
public";
void delete_##NAME(TYPE *ary);

%javamethodmodifiers NAME##_getitem(TYPE *ary, int index) "
/**
 * Retrieves an element of an array of TYPE.
 * <p>BEWARE: The validity of the index is not checked.
 *
 * @param ary array
 * @param index index of the element
 * @return array element
 */
public";
TYPE NAME##_getitem(TYPE *ary, int index);

%javamethodmodifiers NAME##_setitem(TYPE* ary, int index, TYPE value) "
/**
 * Sets the value of an element of an array of TYPE.
 * <p>BEWARE: The validity of the index is not checked.
 *
 * @param ary array
 * @param index index of the element
 * @param value new value
 */
public";
void NAME##_setitem(TYPE *ary, int index, TYPE value);

%enddef
/* Old Swig versions require a LF after enddef */