diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
|---|---|---|
| committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
| commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
| tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/ocaml/strings_test | |
| download | swig-tarball-master.tar.gz | |
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/ocaml/strings_test')
| -rw-r--r-- | Examples/ocaml/strings_test/Makefile | 28 | ||||
| -rw-r--r-- | Examples/ocaml/strings_test/example.h | 37 | ||||
| -rw-r--r-- | Examples/ocaml/strings_test/example.i | 14 | ||||
| -rw-r--r-- | Examples/ocaml/strings_test/runme.ml | 17 |
4 files changed, 96 insertions, 0 deletions
diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile new file mode 100644 index 0000000..8d1f96e --- /dev/null +++ b/Examples/ocaml/strings_test/Makefile @@ -0,0 +1,28 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = +TARGET = example +INTERFACE = example.i +PROGFILE = runme.ml + +all default:: static top + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +dynamic:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +top:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp_toplevel + +clean:: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + +check: all diff --git a/Examples/ocaml/strings_test/example.h b/Examples/ocaml/strings_test/example.h new file mode 100644 index 0000000..3417981 --- /dev/null +++ b/Examples/ocaml/strings_test/example.h @@ -0,0 +1,37 @@ +/* -*- mode: c++ -*- */ +/* File : example.h -- Tests all string typemaps */ + +void takes_std_string( std::string in ) { + cout << "takes_std_string( \"" << in << "\" );" << endl; +} + +std::string gives_std_string() { + time_t t; + + return std::string( asctime( localtime( &t ) ) ); +} + +void takes_char_ptr( char *p ) { + cout << "takes_char_ptr( \"" << p << "\" );" << endl; +} + +char *gives_char_ptr() { + return "foo"; +} + +void takes_and_gives_std_string( std::string &inout ) { + inout.insert( inout.begin(), '[' ); + inout.insert( inout.end(), ']' ); +} + +void takes_and_gives_char_ptr( char *&ptr ) { + char *pout = strchr( ptr, '.' ); + if( pout ) ptr = pout + 1; + else ptr = "foo"; +} + +/* + * Local-Variables: + * c-indentation-style: "stroustrup" + * End: + */ diff --git a/Examples/ocaml/strings_test/example.i b/Examples/ocaml/strings_test/example.i new file mode 100644 index 0000000..be9eabf --- /dev/null +++ b/Examples/ocaml/strings_test/example.i @@ -0,0 +1,14 @@ +%module example +%{ +#include <iostream> +#include <string> + +using std::cin; +using std::cout; +using std::endl; +using std::string; + +#include "example.h" +%} + +%include example.h diff --git a/Examples/ocaml/strings_test/runme.ml b/Examples/ocaml/strings_test/runme.ml new file mode 100644 index 0000000..0eb5637 --- /dev/null +++ b/Examples/ocaml/strings_test/runme.ml @@ -0,0 +1,17 @@ +(* This example is meant to reach every case in cstring.i *) + +open Swig +open Example + +let _ = _takes_std_string (C_string "foo") +let _ = print_endline + ("_gives_std_string <<" ^ (get_string (_gives_std_string C_void)) ^ " >>") +let _ = _takes_char_ptr (C_string "bar") +let _ = print_endline + ("_gives_char_ptr << " ^ (get_string (_gives_char_ptr C_void)) ^ " >>") +let _ = print_endline + ("_takes_and_gives_std_string << " ^ + (get_string (_takes_and_gives_std_string (C_string "foo"))) ^ " >>") +let _ = print_endline + ("_takes_and_gives_char_ptr << " ^ + (get_string (_takes_and_gives_char_ptr (C_string "bar.bar"))) ^ " >>") |
