Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS =
TARGET = example
INTERFACE = example.i
PROGFILE = runme.ml
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
build: static top
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_static_cpp
dynamic:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_static_cpp
top:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_static_cpp_toplevel
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean

View File

@@ -0,0 +1,41 @@
/* -*- mode: c++ -*- */
/* File : example.h -- Tests all string typemaps */
#include <sys/time.h>
#include <time.h>
void takes_std_string( std::string in ) {
cout << "takes_std_string( \"" << in << "\" );" << endl;
}
std::string gives_std_string() {
struct timeval tv;
gettimeofday(&tv, NULL);
return std::string( asctime( localtime( &tv.tv_sec ) ) );
}
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 *&inout ) {
char *pout = strchr( inout, '.' );
if( pout ) inout = pout + 1;
else inout = "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,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"))) ^ " >>")