From 2949c006d482ec4de2cb808134e017a4ebe34b47 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Fri, 21 Mar 2003 16:25:30 +0000 Subject: [PATCH] Added stl example. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4602 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/ocaml/stl/Makefile | 28 ++++++++++++++++++++++++++++ SWIG/Examples/ocaml/stl/example.h | 15 +++++++++++++++ SWIG/Examples/ocaml/stl/example.i | 13 +++++++++++++ SWIG/Examples/ocaml/stl/runme.ml | 12 ++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 SWIG/Examples/ocaml/stl/Makefile create mode 100644 SWIG/Examples/ocaml/stl/example.h create mode 100644 SWIG/Examples/ocaml/stl/example.i create mode 100644 SWIG/Examples/ocaml/stl/runme.ml diff --git a/SWIG/Examples/ocaml/stl/Makefile b/SWIG/Examples/ocaml/stl/Makefile new file mode 100644 index 000000000..52759144b --- /dev/null +++ b/SWIG/Examples/ocaml/stl/Makefile @@ -0,0 +1,28 @@ +TOP = ../.. +SWIG = $(TOP)/../swig -I/usr/include/g++-3 +SRCS = +TARGET = example +INTERFACE = example.i +PROGFILE = runme.ml + +all default:: static + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +director:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp_director + +dynamic:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + +check: all diff --git a/SWIG/Examples/ocaml/stl/example.h b/SWIG/Examples/ocaml/stl/example.h new file mode 100644 index 000000000..5bf09962e --- /dev/null +++ b/SWIG/Examples/ocaml/stl/example.h @@ -0,0 +1,15 @@ +/* File : example.h -- stolen from the guile std_vector example */ + +#include +#include +#include +#include +#include + +double vec_write(std::vector v) { + int n = 0; + for( std::vector::iterator i = v.begin(); + i != v.end(); + i++ ) + printf( "%04d: %s\n", ++n, i->c_str() ); +} diff --git a/SWIG/Examples/ocaml/stl/example.i b/SWIG/Examples/ocaml/stl/example.i new file mode 100644 index 000000000..3bbea0f47 --- /dev/null +++ b/SWIG/Examples/ocaml/stl/example.i @@ -0,0 +1,13 @@ +%module example +%{ +#include "example.h" +%} + +%include stl.i + +%feature("director"); +namespace std { + %template(StringVector) std::vector; +}; + +%include example.h diff --git a/SWIG/Examples/ocaml/stl/runme.ml b/SWIG/Examples/ocaml/stl/runme.ml new file mode 100644 index 000000000..82ac7a044 --- /dev/null +++ b/SWIG/Examples/ocaml/stl/runme.ml @@ -0,0 +1,12 @@ +(* This example was mostly lifted from the guile example directory *) + +open Example + +let v = new_StringVector C_void + +let _ = + for i = 0 to (Array.length Sys.argv) - 1 do + (invoke v) "push_back" (C_string Sys.argv.(i)) + done + +let _ = _vec_write v