swip4-ify.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5235 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a967f0fdc9
commit
a45bfa9624
1 changed files with 20 additions and 26 deletions
|
|
@ -3,39 +3,33 @@
|
||||||
open Swig
|
open Swig
|
||||||
open Example
|
open Example
|
||||||
|
|
||||||
(* repeatedly invoke a procedure with v and an index as arguments *)
|
let with_vector v f =
|
||||||
let with_vector v proc size =
|
for i = 0 to ((v -> size()) as int) - 1 do
|
||||||
let rec with_vector_item =
|
f v i
|
||||||
(fun v i -> if (i < size) then
|
done
|
||||||
begin
|
|
||||||
proc v i ;
|
|
||||||
with_vector_item v (succ i)
|
|
||||||
end) in
|
|
||||||
with_vector_item v 0
|
|
||||||
|
|
||||||
let with_vector v proc =
|
|
||||||
with_vector v proc (get_int ((invoke v) "size" (C_void)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let dbl_vector_ref v i =
|
|
||||||
match ((invoke v) "[]" (C_int i)) with
|
|
||||||
C_float f | C_double f -> f | _ -> 0.0
|
|
||||||
|
|
||||||
let print_DoubleVector v =
|
let print_DoubleVector v =
|
||||||
begin
|
begin
|
||||||
with_vector v
|
with_vector v
|
||||||
(fun v i ->
|
(fun v i ->
|
||||||
(print_float (dbl_vector_ref v i)) ;
|
print_float ((v '[i to int]) as float) ;
|
||||||
(print_string " ")) ;
|
print_string " ") ;
|
||||||
print_endline
|
print_endline
|
||||||
end
|
end
|
||||||
|
|
||||||
let fill_int_vector_from_array a v i =
|
|
||||||
(invoke v) "set" (C_list [ C_int i ; C_int a.(i) ])
|
|
||||||
|
|
||||||
(* Call average with a Ocaml array... *)
|
(* Call average with a Ocaml array... *)
|
||||||
|
|
||||||
let y = new_IntVector (C_uint (Int32.of_int 4))
|
let v = new_DoubleVector '()
|
||||||
let _ = with_vector y (fill_int_vector_from_array [| 1;2;3;4 |])
|
let rec fill_dv v x =
|
||||||
let _ = (print_float (get_float (_average y)) ; print_newline ())
|
if x < 0.0001 then v else
|
||||||
|
begin
|
||||||
|
v -> push_back ((x to float)) ;
|
||||||
|
fill_dv v (x *. x)
|
||||||
|
end
|
||||||
|
let _ = fill_dv v 0.999
|
||||||
|
let _ = print_DoubleVector v ; print_endline ""
|
||||||
|
let u = new_IntVector '()
|
||||||
|
let _ = for i = 1 to 4 do
|
||||||
|
u -> push_back ((i to int))
|
||||||
|
done
|
||||||
|
let _ = (print_float ((_average u) as float) ; print_newline ())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue