Strings test, tests in, out, inout string and char * types.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4687 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b4831c6e0b
commit
3acd792de3
4 changed files with 95 additions and 0 deletions
28
Examples/ocaml/strings_test/Makefile
Normal file
28
Examples/ocaml/strings_test/Makefile
Normal 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 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
|
||||||
37
Examples/ocaml/strings_test/example.h
Normal file
37
Examples/ocaml/strings_test/example.h
Normal file
|
|
@ -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:
|
||||||
|
*/
|
||||||
14
Examples/ocaml/strings_test/example.i
Normal file
14
Examples/ocaml/strings_test/example.i
Normal file
|
|
@ -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
|
||||||
16
Examples/ocaml/strings_test/runme.ml
Normal file
16
Examples/ocaml/strings_test/runme.ml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
(* This example is meant to reach every case in cstring.i *)
|
||||||
|
|
||||||
|
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"))) ^ " >>")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue