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:
Art Yerkes 2003-04-16 05:18:57 +00:00
commit 3acd792de3
4 changed files with 95 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 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

View 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:
*/

View 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

View 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"))) ^ " >>")