Refactor/simply bessel example and update Changes
[Math-GSL.git] / gsl_typemaps.i
blob42a3afd108e712b34d973e3fd7d8389679dab040
2 %typemap(in) double const [] {
3 AV *tempav;
4 I32 len;
5 int i;
6 SV **tv;
7 if (!SvROK($input))
8 croak("Math::GSL : $input is not a reference!");
9 if (SvTYPE(SvRV($input)) != SVt_PVAV)
10 croak("Math::GSL : $input is not an array ref!");
12 tempav = (AV*)SvRV($input);
13 len = av_len(tempav);
14 $1 = (double *) malloc((len+1)*sizeof(double));
15 for (i = 0; i <= len; i++) {
16 tv = av_fetch(tempav, i, 0);
17 $1[i] = (double) SvNV(*tv);
21 %apply double const [] { size_t *p };
23 %apply double const [] { double *data, double *dest, double *f_in, double *f_out, double data[], const double * src };
24 %apply double const [] { double x[], double a[], double b[] };
25 %apply double const [] { const double * x, const double * y, const double * w };
26 %apply double const [] { const double x_array[], const double xrange[], const double yrange[]};
27 %apply double const [] { double * base, const double * base};
28 %apply double const [] { const double xrange[], const double yrange[] };
29 %apply double const [] { const double * array };
30 %apply double const [] { const double data2[], const double w[] };
31 %apply double const [] { float const *A, float const *B, float const *C, float *C};
33 %apply double * OUTPUT { double *abserr, double *result };
35 static HV * Callbacks = (HV*)NULL;
36 /* this function returns the value
37 of evaluating the function pointer
38 stored in func with argument x
40 double callthis(double x , int func, void *params){
41 SV ** sv;
42 double y;
43 dSP;
45 //fprintf(stderr, "LOOKUP CALLBACK\n");
46 sv = hv_fetch(Callbacks, (char*)func, sizeof(func), FALSE );
47 if (sv == (SV**)NULL) {
48 fprintf(stderr, "Math::GSL(callthis): %d not in Callbacks!\n", func);
49 return;
52 PUSHMARK(SP);
53 XPUSHs(sv_2mortal(newSVnv((double)x)));
54 PUTBACK;
55 call_sv(*sv, G_SCALAR);
56 y = POPn;
57 return y;
60 %typemap(in) gsl_function * {
61 gsl_function F;
62 int count;
63 SV ** callback;
64 double x;
66 if (!SvROK($input)) {
67 croak("Math::GSL : $1_name is not a reference value!");
69 if (Callbacks == (HV*)NULL)
70 Callbacks = newHV();
71 //fprintf(stderr,"STORE CALLBACK: %d\n", (int)$input);
72 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
74 F.params = &$input;
75 F.function = &callthis;
76 $1 = &F;