Added stl example.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4602 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-03-21 16:25:30 +00:00
commit 2949c006d4
4 changed files with 68 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,15 @@
/* File : example.h -- stolen from the guile std_vector example */
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
double vec_write(std::vector<string> v) {
int n = 0;
for( std::vector<string>::iterator i = v.begin();
i != v.end();
i++ )
printf( "%04d: %s\n", ++n, i->c_str() );
}

View file

@ -0,0 +1,13 @@
%module example
%{
#include "example.h"
%}
%include stl.i
%feature("director");
namespace std {
%template(StringVector) std::vector<string>;
};
%include example.h

View file

@ -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