This commit is contained in:
FluorescentCIAAfricanAmerican
2020-04-22 12:56:21 -04:00
commit 3bf9df6b27
15370 changed files with 5489726 additions and 0 deletions
@@ -0,0 +1,138 @@
# ---------------------------------------------------------------
# SWIG Perl5 Makefile
#
# This file can be used to build various Perl5 extensions with SWIG.
# By default this file is set up for dynamic loading, but it can
# be easily customized for static extensions by modifying various
# portions of the file.
#
# SRCS = C source files
# CXXSRCS = C++ source files
# OBJCSRCS = Objective-C source files
# OBJS = Additional .o files (compiled previously)
# INTERFACE = SWIG interface file
# TARGET = Name of target module or executable
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module@SO@ # Use this kind of target for dynamic loading
#TARGET = myperl # Use this target for static linking
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
CXX = @CXX@
OBJC = @CC@ -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDES =
LIBS =
# SWIG Options
# SWIG = location of the SWIG executable
# SWIGOPT = SWIG compiler options
# SWIGCC = Compiler used to compile the wrapper file
SWIG = $(exec_prefix)/bin/swig
SWIGOPT = -perl5
SWIGCC = $(CC)
# SWIG Library files. Uncomment this to staticly rebuild Perl
#SWIGLIB = -static -lperlmain.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED = @CCSHARED@
BUILD = @LDSHARED@
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (possibly needed if using Perl-Tk)
XLIB = @XLIBSW@
XINCLUDE = @XINCLUDES@
# Perl installation
PERL_INCLUDE = -I@PERL5EXT@
PERL_LIB = -L@PERL5EXT@ -lperl
PERL_FLAGS = -Dbool=char -Dexplicit=
# Tcl installation. If using Tk you might need this
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB = @TCLLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options (uncomment only one these)
#TK_LIB = $(TCL_LIB) -ltcl -ltk $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PERL_LIB) $(TK_LIB) $(LIBS) $(SYSLIBS) # Static linking
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDES) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDES) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDES) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(PERL_INCLUDE) $(PERL_FLAGS) $(WRAPFILE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)
@@ -0,0 +1,21 @@
# File : Makefile.pl
# MakeMaker file for a SWIG module. Use this file if you are
# producing a module for general use or distribution.
#
# 1. Modify the file as appropriate. Replace $module with the
# real name of your module and wrapper file.
# 2. Run perl as 'perl Makefile.pl'
# 3. Type 'make' to build your module
# 4. Type 'make install' to install your module.
#
# See "Programming Perl", 2nd. Ed, for more gory details than
# you ever wanted to know.
use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => '$module', # Name of your module
'LIBS' => [''], # Custom libraries (if any)
'OBJECT' => '$module_wrap.o' # Object files
);
@@ -0,0 +1 @@
%include <typemaps/attribute.swg>
@@ -0,0 +1,2 @@
%include <typemaps/carrays.swg>
@@ -0,0 +1 @@
%include <typemaps/cdata.swg>
@@ -0,0 +1 @@
%include <typemaps/cmalloc.swg>
+12
View File
@@ -0,0 +1,12 @@
%warnfilter(SWIGWARN_PARSE_KEYWORD) java::lang::ref;
%{
#undef STATIC
%}
%include <gcj/cni.i>
%{
#undef TRUE
#define TRUE 1
%}
%include <jstring.i>
@@ -0,0 +1 @@
%include <typemaps/cpointer.swg>
@@ -0,0 +1 @@
%include <typemaps/cstring.swg>
@@ -0,0 +1,5 @@
%include <typemaps/exception.swg>
%insert("runtime") {
%define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; ))
}
@@ -0,0 +1,2 @@
# see top-level Makefile.in
Makefile.pl noembed.h
@@ -0,0 +1 @@
%include <typemaps/factory.swg>
@@ -0,0 +1,48 @@
%include <typemaps/valtypes.swg>
%fragment(SWIG_AsVal_frag(jstring),"header") {
SWIGINTERN int
SWIG_AsVal_dec(jstring)(SV *obj, jstring *val)
{
if (SvPOK(obj)) {
if (val) {
STRLEN len = 0;
char *cstr = SvPV(obj, len);
*val = JvNewStringLatin1(cstr, len);
}
return SWIG_OK;
}
return SWIG_ERROR;
}
}
%fragment(SWIG_From_frag(jstring),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(jstring)(jstring val)
{
SV *obj = sv_newmortal();
if (!val) {
sv_setsv(obj, &PL_sv_undef);
} else {
jsize len = JvGetStringUTFLength(val);
if (!len) {
sv_setsv(obj, &PL_sv_undef);
} else {
char *tmp = %new_array(len, char);
JvGetStringUTFRegion(val, 0, len, tmp);
sv_setpvn(obj, tmp, len);
SvUTF8_on(obj);
%delete_array(tmp);
}
}
return obj;
}
}
%typemaps_asvalfrom(%checkcode(STRING),
%arg(SWIG_AsVal(jstring)),
%arg(SWIG_From(jstring)),
%arg(SWIG_AsVal_frag(jstring)),
%arg(SWIG_From_frag(jstring)),
java::lang::String *);
@@ -0,0 +1,93 @@
/* Workaround perl5 global namespace pollution. Note that undefining library
* functions like fopen will not solve the problem on all platforms as fopen
* might be a macro on Windows but not necessarily on other operating systems. */
#ifdef do_open
#undef do_open
#endif
#ifdef do_close
#undef do_close
#endif
#ifdef scalar
#undef scalar
#endif
#ifdef list
#undef list
#endif
#ifdef apply
#undef apply
#endif
#ifdef convert
#undef convert
#endif
#ifdef Error
#undef Error
#endif
#ifdef form
#undef form
#endif
#ifdef vform
#undef vform
#endif
#ifdef LABEL
#undef LABEL
#endif
#ifdef METHOD
#undef METHOD
#endif
#ifdef Move
#undef Move
#endif
#ifdef yylex
#undef yylex
#endif
#ifdef yyparse
#undef yyparse
#endif
#ifdef yyerror
#undef yyerror
#endif
#ifdef invert
#undef invert
#endif
#ifdef ref
#undef ref
#endif
#ifdef read
#undef read
#endif
#ifdef write
#undef write
#endif
#ifdef eof
#undef eof
#endif
#ifdef bool
#undef bool
#endif
#ifdef close
#undef close
#endif
#ifdef rewind
#undef rewind
#endif
#ifdef free
#undef free
#endif
#ifdef malloc
#undef malloc
#endif
#ifdef calloc
#undef calloc
#endif
#ifdef Stat
#undef Stat
#endif
#ifdef check
#undef check
#endif
#ifdef seekdir
#undef seekdir
#endif
#ifdef open
#undef open
#endif
@@ -0,0 +1,42 @@
/* ------------------------------------------------------------
* perl.swg
*
* Perl configuration module.
* ------------------------------------------------------------ */
/* ------------------------------------------------------------
* Inner macros
* ------------------------------------------------------------ */
%include <perlmacros.swg>
/* ------------------------------------------------------------
* The runtime part
* ------------------------------------------------------------ */
%include <perlruntime.swg>
/* ------------------------------------------------------------
* Special user directives
* ------------------------------------------------------------ */
%include <perluserdir.swg>
/* ------------------------------------------------------------
* Typemap specializations
* ------------------------------------------------------------ */
%include <perltypemaps.swg>
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */
%include <perlopers.swg>
/* ------------------------------------------------------------
* Warnings for Perl keywords
* ------------------------------------------------------------ */
%include <perlkw.swg>
/* ------------------------------------------------------------
* The Perl initialization function
* ------------------------------------------------------------ */
%include <perlinit.swg>
@@ -0,0 +1,49 @@
/* -----------------------------------------------------------------------------
* error manipulation
* ----------------------------------------------------------------------------- */
SWIGINTERN const char*
SWIG_Perl_ErrorType(int code) {
const char* type = 0;
switch(code) {
case SWIG_MemoryError:
type = "MemoryError";
break;
case SWIG_IOError:
type = "IOError";
break;
case SWIG_RuntimeError:
type = "RuntimeError";
break;
case SWIG_IndexError:
type = "IndexError";
break;
case SWIG_TypeError:
type = "TypeError";
break;
case SWIG_DivisionByZero:
type = "ZeroDivisionError";
break;
case SWIG_OverflowError:
type = "OverflowError";
break;
case SWIG_SyntaxError:
type = "SyntaxError";
break;
case SWIG_ValueError:
type = "ValueError";
break;
case SWIG_SystemError:
type = "SystemError";
break;
case SWIG_AttributeError:
type = "AttributeError";
break;
default:
type = "RuntimeError";
}
return type;
}
@@ -0,0 +1,23 @@
/*
Create a file with this name, 'perlfragments.swg', in your working
directory and add all the %fragments you want to take precedence
over the ones defined by default by swig.
For example, if you add:
%fragment(SWIG_AsVal_frag(int),"header") {
SWIGINTERNINLINE int
SWIG_AsVal(int)(PyObject *obj, int *val)
{
<your code here>;
}
}
this will replace the code used to retrieve an integer value for all
the typemaps that need it, including:
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
*/
@@ -0,0 +1,102 @@
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Add in functionality missing in older versions of Perl. Much of this is based on Devel-PPPort on cpan. */
/* Add PERL_REVISION, PERL_VERSION, PERL_SUBVERSION if missing */
#ifndef PERL_REVISION
# if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION))
# define PERL_PATCHLEVEL_H_IMPLICIT
# include <patchlevel.h>
# endif
# if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL)))
# include <could_not_find_Perl_patchlevel.h>
# endif
# ifndef PERL_REVISION
# define PERL_REVISION (5)
# define PERL_VERSION PATCHLEVEL
# define PERL_SUBVERSION SUBVERSION
# endif
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
#ifndef SvIOK_UV
# define SvIOK_UV(sv) (SvIOK(sv) && (SvUVX(sv) == SvIVX(sv)))
#endif
#ifndef SvUOK
# define SvUOK(sv) SvIOK_UV(sv)
#endif
#if ((PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5)))
# define PL_sv_undef sv_undef
# define PL_na na
# define PL_errgv errgv
# define PL_sv_no sv_no
# define PL_sv_yes sv_yes
# define PL_markstack_ptr markstack_ptr
#endif
#ifndef IVSIZE
# ifdef LONGSIZE
# define IVSIZE LONGSIZE
# else
# define IVSIZE 4 /* A bold guess, but the best we can make. */
# endif
#endif
#ifndef INT2PTR
# if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
# define PTRV UV
# define INT2PTR(any,d) (any)(d)
# else
# if PTRSIZE == LONGSIZE
# define PTRV unsigned long
# else
# define PTRV unsigned
# endif
# define INT2PTR(any,d) (any)(PTRV)(d)
# endif
# define NUM2PTR(any,d) (any)(PTRV)(d)
# define PTR2IV(p) INT2PTR(IV,p)
# define PTR2UV(p) INT2PTR(UV,p)
# define PTR2NV(p) NUM2PTR(NV,p)
# if PTRSIZE == LONGSIZE
# define PTR2ul(p) (unsigned long)(p)
# else
# define PTR2ul(p) INT2PTR(unsigned long,p)
# endif
#endif /* !INT2PTR */
#ifndef SvPV_nolen
# define SvPV_nolen(x) SvPV(x,PL_na)
#endif
#ifndef get_sv
# define get_sv perl_get_sv
#endif
#ifndef ERRSV
# define ERRSV get_sv("@",FALSE)
#endif
#ifndef pTHX_
#define pTHX_
#endif
#include <string.h>
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,76 @@
/* Export the SWIG initialization function */
%header %{
#ifdef __cplusplus
extern "C"
#endif
#ifndef PERL_OBJECT
#ifndef MULTIPLICITY
SWIGEXPORT void SWIG_init (CV* cv);
#else
SWIGEXPORT void SWIG_init (pTHXo_ CV* cv);
#endif
#else
SWIGEXPORT void SWIG_init (CV *cv, CPerlObj *);
#endif
%}
/* Module initialization function */
%insert(init) "swiginit.swg"
%init %{
#ifdef __cplusplus
extern "C"
#endif
XS(SWIG_init) {
dXSARGS;
int i;
SWIG_InitializeModule(0);
/* Install commands */
for (i = 0; swig_commands[i].name; i++) {
newXS((char*) swig_commands[i].name,swig_commands[i].wrapper, (char*)__FILE__);
}
/* Install variables */
for (i = 0; swig_variables[i].name; i++) {
SV *sv;
sv = get_sv((char*) swig_variables[i].name, TRUE | 0x2);
if (swig_variables[i].type) {
SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0);
} else {
sv_setiv(sv,(IV) 0);
}
swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get);
}
/* Install constant */
for (i = 0; swig_constants[i].type; i++) {
SV *sv;
sv = get_sv((char*)swig_constants[i].name, TRUE | 0x2);
switch(swig_constants[i].type) {
case SWIG_INT:
sv_setiv(sv, (IV) swig_constants[i].lvalue);
break;
case SWIG_FLOAT:
sv_setnv(sv, (double) swig_constants[i].dvalue);
break;
case SWIG_STRING:
sv_setpv(sv, (char *) swig_constants[i].pvalue);
break;
case SWIG_POINTER:
SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0);
break;
case SWIG_BINARY:
SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype));
break;
default:
break;
}
SvREADONLY_on(sv);
}
%}
@@ -0,0 +1,251 @@
/* Warnings for Perl keywords */
#define PERLKW(x) %keywordwarn(`x` " is a perl keyword") `x`
#define PERLBN(x) %builtinwarn(`x` " conflicts with a built-in name in perl") "::" `x`
/*
From http://www.rocketaware.com/perl/perlfunc/
*/
/* Functions for SCALARs or strings*/
PERLBN(chomp);
PERLBN(chop);
PERLBN(chr);
PERLBN(crypt);
PERLBN(hex);
PERLBN(index);
PERLBN(lc);
PERLBN(lcfirst);
PERLBN(length);
PERLBN(oct);
PERLBN(ord);
PERLBN(pack);
PERLBN(reverse);
PERLBN(rindex);
PERLBN(sprintf);
PERLBN(substr);
PERLBN(uc);
PERLBN(ucfirst);
/* Regular expressions and pattern matching */
PERLBN(m);
PERLBN(pos);
PERLBN(quotemeta);
PERLBN(split);
PERLBN(study);
/* Numeric functions */
PERLBN(abs);
PERLBN(atan2);
PERLBN(cos);
PERLBN(exp);
PERLBN(hex);
PERLBN(int);
PERLBN(log);
PERLBN(oct);
PERLBN(rand);
PERLBN(sin);
PERLBN(sqrt);
PERLBN(srand);
/* Functions for real @ARRAYs*/
PERLBN(pop);
PERLBN(push);
PERLBN(shift);
PERLBN(splice);
PERLBN(unshift);
/* Functions for list data*/
PERLBN(grep);
PERLBN(join);
PERLBN(map);
PERLBN(qw);
PERLBN(reverse);
PERLBN(sort);
PERLBN(unpack);
/* Functions for real %HASHes*/
PERLBN(delete);
PERLBN(each);
PERLBN(exists);
PERLBN(keys);
PERLBN(values);
/* Input and output functions*/
PERLBN(binmode);
PERLBN(close);
PERLBN(closedir);
PERLBN(dbmclose);
PERLBN(dbmopen);
PERLBN(die);
PERLBN(eof);
PERLBN(fileno);
PERLBN(flock);
PERLBN(format);
PERLBN(getc);
PERLBN(print);
PERLBN(printf);
PERLBN(read);
PERLBN(readdir);
PERLBN(rewinddir);
PERLBN(seek);
PERLBN(seekdir);
PERLBN(select);
PERLBN(syscall);
PERLBN(sysread);
PERLBN(sysseek);
PERLBN(syswrite);
PERLBN(tell);
PERLBN(telldir);
PERLBN(truncate);
PERLBN(warn);
PERLBN(write);
/* Functions for fixed length data or records*/
PERLBN(pack);
PERLBN(read);
PERLBN(syscall);
PERLBN(sysread);
PERLBN(syswrite);
PERLBN(unpack);
PERLBN(vec);
/* Functions for filehandles, files, or directories */
PERLBN(chdir);
PERLBN(chmod);
PERLBN(chown);
PERLBN(chroot);
PERLBN(fcntl);
PERLBN(glob);
PERLBN(ioctl);
PERLBN(link);
PERLBN(lstat);
PERLBN(mkdir);
PERLBN(open);
PERLBN(opendir);
PERLBN(readlink);
PERLBN(rename);
PERLBN(rmdir);
PERLBN(stat);
PERLBN(symlink);
PERLBN(umask);
PERLBN(unlink);
PERLBN(utime);
/* Keywords related to the control flow of your perl program */
PERLKW(caller);
PERLKW(continue);
PERLKW(die);
PERLKW(do);
PERLKW(dump);
PERLKW(eval);
PERLKW(exit);
PERLKW(goto);
PERLKW(last);
PERLKW(next);
PERLKW(redo);
PERLKW(return);
PERLKW(sub);
PERLKW(wantarray);
/* Keywords related to scoping */
PERLKW(caller);
PERLKW(import);
PERLKW(local);
PERLKW(my);
PERLKW(package);
PERLKW(use);
/* Miscellaneous functions */
PERLBN("defined");
PERLBN(dump);
PERLBN(eval);
PERLBN(formline);
PERLBN(local);
PERLBN(my);
PERLBN(reset);
PERLBN(scalar);
PERLBN(undef);
PERLBN(wantarray);
/* Functions for processes and process groups */
PERLBN(alarm);
PERLBN(exec);
PERLBN(fork);
PERLBN(getpgrp);
PERLBN(getppid);
PERLBN(getpriority);
PERLBN(kill);
PERLBN(pipe);
PERLBN(setpgrp);
PERLBN(setpriority);
PERLBN(sleep);
PERLBN(system);
PERLBN(times);
PERLBN(wait);
PERLBN(waitpid);
/* Keywords related to perl modules */
PERLKW(do);
PERLKW(import);
PERLKW(no);
PERLKW(package);
PERLKW(require);
PERLKW(use);
/* Keywords related to classes and object-orientedness */
PERLKW(bless);
PERLKW(dbmclose);
PERLKW(dbmopen);
PERLKW(package);
PERLKW(ref);
PERLKW(tie);
PERLKW(tied);
PERLKW(untie);
PERLKW(use);
/* Functions new in perl5 */
PERLBN(abs);
PERLBN(bless);
PERLBN(chomp);
PERLBN(chr);
PERLBN(exists);
PERLBN(formline);
PERLBN(glob);
PERLBN(import);
PERLBN(lc);
PERLBN(lcfirst);
PERLBN(map);
PERLBN(my);
PERLBN(no);
PERLBN(prototype);
PERLBN(qx);
PERLBN(qw);
PERLBN(readline);
PERLBN(readpipe);
PERLBN(ref);
PERLBN(sub);
PERLBN(sysopen);
PERLBN(tie);
PERLBN(tied);
PERLBN(uc);
PERLBN(ucfirst);
PERLBN(untie);
PERLBN(use);
#undef PERLKW
#undef PERLBN
@@ -0,0 +1,2 @@
%include <typemaps/swigmacros.swg>
@@ -0,0 +1,85 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* perlmain.i
*
* Code to statically rebuild perl5.
* ----------------------------------------------------------------------------- */
#ifdef AUTODOC
%subsection "perlmain.i"
%text %{
This module provides support for building a new version of the
Perl executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions.
This module may only build a stripped down version of the
Perl executable. Thus, it may be necessary (or desirable)
to hand-edit this file for your particular application. To
do this, simply copy this file from swig_lib/perl5/perlmain.i
to your working directory and make the appropriate modifications.
This library file works with Perl 5.003. It may work with earlier
versions, but it hasn't been tested. As far as I know, this
library is C++ safe.
%}
#endif
%{
static void xs_init _((pTHX));
static PerlInterpreter *my_perl;
int perl_eval(char *string) {
char *argv[2];
argv[0] = string;
argv[1] = (char *) 0;
return perl_call_argv("eval",0,argv);
}
int
main(int argc, char **argv, char **env)
{
int exitstatus;
my_perl = perl_alloc();
if (!my_perl)
exit(1);
perl_construct( my_perl );
exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL );
if (exitstatus)
exit( exitstatus );
/* Initialize all of the module variables */
exitstatus = perl_run( my_perl );
perl_destruct( my_perl );
perl_free( my_perl );
exit( exitstatus );
}
/* Register any extra external extensions */
/* Do not delete this line--writemain depends on it */
/* EXTERN_C void boot_DynaLoader _((CV* cv)); */
static void
xs_init(pTHX)
{
/* dXSUB_SYS; */
char *file = __FILE__;
{
/* newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); */
newXS(SWIG_name, SWIG_init, file);
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
}
}
%}
@@ -0,0 +1,56 @@
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */
#ifdef __cplusplus
// These are auto-supported by the Perl-module
%rename(__plusplus__) *::operator++;
%rename(__minmin__) *::operator--;
%rename(__add__) *::operator+;
%rename(__sub__) *::operator-;
%rename(__neg__) *::operator-();
%rename(__neg__) *::operator-() const;
%rename(__mul__) *::operator*;
%rename(__div__) *::operator/;
%rename(__eq__) *::operator==;
%rename(__ne__) *::operator!=;
%rename(__mod__) *::operator%;
%rename(__gt__) *::operator>;
%rename(__lt__) *::operator<;
%rename(__not__) *::operator!;
// These are renamed, but no 'use overload...' is added
%rename(__lshift__) *::operator<<;
%rename(__rshift__) *::operator>>;
%rename(__and__) *::operator&;
%rename(__or__) *::operator|;
%rename(__xor__) *::operator^;
%rename(__invert__) *::operator~;
%rename(__le__) *::operator<=;
%rename(__ge__) *::operator>=;
%rename(__call__) *::operator();
/* Ignored operators */
%ignoreoperator(LAND) operator&&;
%ignoreoperator(LOR) operator||;
%ignoreoperator(PLUS) operator+();
%ignoreoperator(PLUS) operator+() const;
%ignoreoperator(PLUSEQ) operator+=;
%ignoreoperator(MINUSEQ) operator-=;
%ignoreoperator(MULEQ) operator*=;
%ignoreoperator(DIVEQ) operator/=;
%ignoreoperator(MODEQ) operator%=;
%ignoreoperator(LSHIFTEQ) operator<<=;
%ignoreoperator(RSHIFTEQ) operator>>=;
%ignoreoperator(ANDEQ) operator&=;
%ignoreoperator(OREQ) operator|=;
%ignoreoperator(XOREQ) operator^=;
%ignoreoperator(EQ) operator=;
%ignoreoperator(PLUSPLUS) operator++;
%ignoreoperator(MINUSMINUS) operator--;
%ignoreoperator(ARROWSTAR) operator->*;
%ignoreoperator(INDEX) operator[];
#endif /* __cplusplus */
@@ -0,0 +1,328 @@
/* ------------------------------------------------------------
* Primitive Types
* ------------------------------------------------------------ */
/* bool */
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(bool)(bool value)
{
SV *obj = sv_newmortal();
if (value) {
sv_setsv(obj, &PL_sv_yes);
} else {
sv_setsv(obj, &PL_sv_no);
}
return obj;
}
}
%fragment(SWIG_AsVal_frag(bool),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(bool)(SV *obj, bool* val)
{
if (obj == &PL_sv_yes) {
if (val) *val = true;
return SWIG_OK;
} else if (obj == &PL_sv_no) {
if (val) *val = false;
return SWIG_OK;
} else {
if (val) *val = SvTRUE(obj) ? true: false;
return SWIG_AddCast(SWIG_OK);
}
return SWIG_TypeError;
}
}
/* long */
%fragment(SWIG_From_frag(long),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(long)(long value)
{
SV *obj = sv_newmortal();
sv_setiv(obj, (IV) value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(long)(SV *obj, long* val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
long v;
errno = 0;
v = strtol(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
if (val) *val = (long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
}
/* unsigned long */
%fragment(SWIG_From_frag(unsigned long),"header",
fragment=SWIG_AsVal_frag(double)) {
SWIGINTERNINLINE SV *
SWIG_From_dec(unsigned long)(unsigned long value)
{
SV *obj = sv_newmortal();
sv_setuv(obj, (UV) value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(unsigned long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
{
if (SvUOK(obj)) {
if (val) *val = SvUV(obj);
return SWIG_OK;
} else if (SvIOK(obj)) {
long v = SvIV(obj);
if (v >= 0) {
if (val) *val = v;
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
unsigned long v;
errno = 0;
v = strtoul(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
if (val) *val = (unsigned long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
}
/* long long */
%fragment(SWIG_From_frag(long long),"header",
fragment=SWIG_From_frag(long),
fragment="<limits.h>",
fragment="<stdio.h>") {
SWIGINTERNINLINE SV *
SWIG_From_dec(long long)(long long value)
{
if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) {
return SWIG_From(long)(%numeric_cast(value,long));
} else {
char temp[256];
SV *obj = sv_newmortal();
sprintf(temp, "%lld", value);
sv_setpv(obj, temp);
return obj;
}
}
}
%fragment(SWIG_AsVal_frag(long long),"header",
fragment="<limits.h>",
fragment="<stdlib.h>",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(long long)(SV *obj, long long *val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
long long v;
errno = 0;
v = strtoll(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
const double mant_max = 1LL << DBL_MANT_DIG;
const double mant_min = -mant_max;
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) {
if (val) *val = (long long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
}
/* unsigned long long */
%fragment(SWIG_From_frag(unsigned long long),"header",
fragment=SWIG_From_frag(long long),
fragment="<limits.h>",
fragment="<stdio.h>") {
SWIGINTERNINLINE SV *
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
if (value < (unsigned long long) LONG_MAX) {
return SWIG_From(long long)(%numeric_cast(value, long long));
} else {
char temp[256];
SV *obj = sv_newmortal();
sprintf(temp, "%llu", value);
sv_setpv(obj, temp);
return obj;
}
}
}
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
fragment="<limits.h>",
fragment="<stdlib.h>",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
{
if (SvUOK(obj)) {
if (val) *val = SvUV(obj);
return SWIG_OK;
} else if (SvIOK(obj)) {
long v = SvIV(obj);
if (v >= 0) {
if (val) *val = v;
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
unsigned long long v;
errno = 0;
v = strtoull(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
const double mant_max = 1LL << DBL_MANT_DIG;
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
if (val) *val = (unsigned long long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
}
/* double */
%fragment(SWIG_From_frag(double),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(double)(double value)
{
SV *obj = sv_newmortal();
sv_setnv(obj, value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(double),"header") {
SWIGINTERN int
SWIG_AsVal_dec(double)(SV *obj, double *val)
{
if (SvNIOK(obj)) {
if (val) *val = SvNV(obj);
return SWIG_OK;
} else if (SvIOK(obj)) {
if (val) *val = (double) SvIV(obj);
return SWIG_AddCast(SWIG_OK);
} else {
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
double v = strtod(nptr, &endptr);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
}
return SWIG_TypeError;
}
}
@@ -0,0 +1,467 @@
/* -----------------------------------------------------------------------------
* perlrun.swg
*
* This file contains the runtime support for Perl modules
* and includes code for managing global variables and pointer
* type checking.
* ----------------------------------------------------------------------------- */
#ifdef PERL_OBJECT
#define SWIG_PERL_OBJECT_DECL CPerlObj *SWIGUNUSEDPARM(pPerl),
#define SWIG_PERL_OBJECT_CALL pPerl,
#else
#define SWIG_PERL_OBJECT_DECL
#define SWIG_PERL_OBJECT_CALL
#endif
/* Common SWIG API */
/* for raw pointers */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags)
/* for raw packed data */
#define SWIG_ConvertPacked(obj, p, s, type) SWIG_Perl_ConvertPacked(SWIG_PERL_OBJECT_CALL obj, p, s, type)
#define SWIG_NewPackedObj(p, s, type) SWIG_Perl_NewPackedObj(SWIG_PERL_OBJECT_CALL p, s, type)
/* for class or struct pointers */
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
/* for C or C++ function pointers */
#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
/* for C++ member pointers, ie, member methods */
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_NewPackedObj(ptr, sz, type)
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_Perl_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer)
/* Error manipulation */
#define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code)
#define SWIG_Error(code, msg) sv_setpvf(GvSV(PL_errgv),"%s %s\n", SWIG_ErrorType(code), msg)
#define SWIG_fail goto fail
/* Perl-specific SWIG API */
#define SWIG_MakePtr(sv, ptr, type, flags) SWIG_Perl_MakePtr(SWIG_PERL_OBJECT_CALL sv, ptr, type, flags)
#define SWIG_MakePackedObj(sv, p, s, type) SWIG_Perl_MakePackedObj(SWIG_PERL_OBJECT_CALL sv, p, s, type)
#define SWIG_SetError(str) SWIG_Error(SWIG_RuntimeError, str)
#define SWIG_PERL_DECL_ARGS_1(arg1) (SWIG_PERL_OBJECT_DECL arg1)
#define SWIG_PERL_CALL_ARGS_1(arg1) (SWIG_PERL_OBJECT_CALL arg1)
#define SWIG_PERL_DECL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_DECL arg1, arg2)
#define SWIG_PERL_CALL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_CALL arg1, arg2)
/* -----------------------------------------------------------------------------
* pointers/data manipulation
* ----------------------------------------------------------------------------- */
/* For backward compatibility only */
#define SWIG_POINTER_EXCEPTION 0
#ifdef __cplusplus
extern "C" {
#endif
#define SWIG_OWNER SWIG_POINTER_OWN
#define SWIG_SHADOW SWIG_OWNER << 1
#define SWIG_MAYBE_PERL_OBJECT SWIG_PERL_OBJECT_DECL
/* SWIG Perl macros */
/* Macro to declare an XS function */
#ifndef XSPROTO
# define XSPROTO(name) void name(pTHX_ CV* cv)
#endif
/* Macro to call an XS function */
#ifdef PERL_OBJECT
# define SWIG_CALLXS(_name) _name(cv,pPerl)
#else
# ifndef MULTIPLICITY
# define SWIG_CALLXS(_name) _name(cv)
# else
# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
# endif
#endif
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
#ifdef __cplusplus
extern "C" {
#endif
typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
#define SWIGCLASS_STATIC
#else /* PERL_OBJECT */
#define MAGIC_PPERL
#define SWIGCLASS_STATIC static SWIGUNUSED
#ifndef MULTIPLICITY
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#else /* MULTIPLICITY */
#define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#endif /* MULTIPLICITY */
#endif /* PERL_OBJECT */
/* Workaround for bug in perl 5.6.x croak and earlier */
#if (PERL_VERSION < 8)
# ifdef PERL_OBJECT
# define SWIG_croak_null() SWIG_Perl_croak_null(pPerl)
static void SWIG_Perl_croak_null(CPerlObj *pPerl)
# else
static void SWIG_croak_null()
# endif
{
SV *err=ERRSV;
# if (PERL_VERSION < 6)
croak("%_", err);
# else
if (SvOK(err) && !SvROK(err)) croak("%_", err);
croak(Nullch);
# endif
}
#else
# define SWIG_croak_null() croak(Nullch)
#endif
/*
Define how strict is the cast between strings and integers/doubles
when overloading between these types occurs.
The default is making it as strict as possible by using SWIG_AddCast
when needed.
You can use -DSWIG_PERL_NO_STRICT_STR2NUM at compilation time to
disable the SWIG_AddCast, making the casting between string and
numbers less strict.
In the end, we try to solve the overloading between strings and
numerical types in the more natural way, but if you can avoid it,
well, avoid it using %rename, for example.
*/
#ifndef SWIG_PERL_NO_STRICT_STR2NUM
# ifndef SWIG_PERL_STRICT_STR2NUM
# define SWIG_PERL_STRICT_STR2NUM
# endif
#endif
#ifdef SWIG_PERL_STRICT_STR2NUM
/* string takes precedence */
#define SWIG_Str2NumCast(x) SWIG_AddCast(x)
#else
/* number takes precedence */
#define SWIG_Str2NumCast(x) x
#endif
#include <stdlib.h>
SWIGRUNTIME const char *
SWIG_Perl_TypeProxyName(const swig_type_info *type) {
if (!type) return NULL;
if (type->clientdata != NULL) {
return (const char*) type->clientdata;
}
else {
return type->name;
}
}
SWIGRUNTIME swig_cast_info *
SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) {
SWIG_TypeCheck_Template(( (!iter->type->clientdata && (strcmp((char*)iter->type->name, c) == 0))
|| (iter->type->clientdata && (strcmp((char*)iter->type->clientdata, c) == 0))), ty);
}
/* Function for getting a pointer value */
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
swig_cast_info *tc;
void *voidptr = (void *)0;
SV *tsv = 0;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
/* Check to see if this is an object */
if (sv_isobject(sv)) {
IV tmp = 0;
tsv = (SV*) SvRV(sv);
if ((SvTYPE(tsv) == SVt_PVHV)) {
MAGIC *mg;
if (SvMAGICAL(tsv)) {
mg = mg_find(tsv,'P');
if (mg) {
sv = mg->mg_obj;
if (sv_isobject(sv)) {
tsv = (SV*)SvRV(sv);
tmp = SvIV(tsv);
}
}
} else {
return SWIG_ERROR;
}
} else {
tmp = SvIV(tsv);
}
voidptr = INT2PTR(void *,tmp);
} else if (! SvOK(sv)) { /* Check for undef */
*(ptr) = (void *) 0;
return SWIG_OK;
} else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
if (!SvROK(sv)) {
*(ptr) = (void *) 0;
return SWIG_OK;
} else {
return SWIG_ERROR;
}
} else { /* Don't know what it is */
return SWIG_ERROR;
}
if (_t) {
/* Now see if the types match */
char *_c = HvNAME(SvSTASH(SvRV(sv)));
tc = SWIG_TypeProxyCheck(_c,_t);
if (!tc) {
return SWIG_ERROR;
}
{
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,voidptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
}
} else {
*ptr = voidptr;
}
/*
* DISOWN implementation: we need a perl guru to check this one.
*/
if (tsv && (flags & SWIG_POINTER_DISOWN)) {
/*
* almost copy paste code from below SWIG_POINTER_OWN setting
*/
SV *obj = sv;
HV *stash = SvSTASH(SvRV(obj));
GV *gv = *(GV**) hv_fetch(stash, "OWNER", 5, TRUE);
if (isGV(gv)) {
HV *hv = GvHVn(gv);
/*
* To set ownership (see below), a newSViv(1) entry is added.
* Hence, to remove ownership, we delete the entry.
*/
if (hv_exists_ent(hv, obj, 0)) {
hv_delete_ent(hv, obj, 0, 0);
}
}
}
return SWIG_OK;
}
SWIGRUNTIME void
SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
if (ptr && (flags & SWIG_SHADOW)) {
SV *self;
SV *obj=newSV(0);
HV *hash=newHV();
HV *stash;
sv_setref_pv(obj, (char *) SWIG_Perl_TypeProxyName(t), ptr);
stash=SvSTASH(SvRV(obj));
if (flags & SWIG_POINTER_OWN) {
HV *hv;
GV *gv=*(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
if (!isGV(gv))
gv_init(gv, stash, "OWNER", 5, FALSE);
hv=GvHVn(gv);
hv_store_ent(hv, obj, newSViv(1), 0);
}
sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0);
SvREFCNT_dec(obj);
self=newRV_noinc((SV *)hash);
sv_setsv(sv, self);
SvREFCNT_dec((SV *)self);
sv_bless(sv, stash);
}
else {
sv_setref_pv(sv, (char *) SWIG_Perl_TypeProxyName(t), ptr);
}
}
SWIGRUNTIMEINLINE SV *
SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) {
SV *result = sv_newmortal();
SWIG_MakePtr(result, ptr, t, flags);
return result;
}
SWIGRUNTIME void
SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
char result[1024];
char *r = result;
if ((2*sz + 1 + strlen(SWIG_Perl_TypeProxyName(type))) > 1000) return;
*(r++) = '_';
r = SWIG_PackData(r,ptr,sz);
strcpy(r,SWIG_Perl_TypeProxyName(type));
sv_setpv(sv, result);
}
SWIGRUNTIME SV *
SWIG_Perl_NewPackedObj(SWIG_MAYBE_PERL_OBJECT void *ptr, int sz, swig_type_info *type) {
SV *result = sv_newmortal();
SWIG_Perl_MakePackedObj(result, ptr, sz, type);
return result;
}
/* Convert a packed value value */
SWIGRUNTIME int
SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty) {
swig_cast_info *tc;
const char *c = 0;
if ((!obj) || (!SvOK(obj))) return SWIG_ERROR;
c = SvPV_nolen(obj);
/* Pointer values must start with leading underscore */
if (*c != '_') return SWIG_ERROR;
c++;
c = SWIG_UnpackData(c,ptr,sz);
if (ty) {
tc = SWIG_TypeCheck(c,ty);
if (!tc) return SWIG_ERROR;
}
return SWIG_OK;
}
/* Macros for low-level exception handling */
#define SWIG_croak(x) { SWIG_Error(SWIG_RuntimeError, x); SWIG_fail; }
typedef XSPROTO(SwigPerlWrapper);
typedef SwigPerlWrapper *SwigPerlWrapperPtr;
/* Structure for command table */
typedef struct {
const char *name;
SwigPerlWrapperPtr wrapper;
} swig_command_info;
/* Information for constant table */
#define SWIG_INT 1
#define SWIG_FLOAT 2
#define SWIG_STRING 3
#define SWIG_POINTER 4
#define SWIG_BINARY 5
/* Constant information structure */
typedef struct swig_constant_info {
int type;
const char *name;
long lvalue;
double dvalue;
void *pvalue;
swig_type_info **ptype;
} swig_constant_info;
/* Structure for variable table */
typedef struct {
const char *name;
SwigMagicFunc set;
SwigMagicFunc get;
swig_type_info **type;
} swig_variable_info;
/* Magic variable code */
#ifndef PERL_OBJECT
#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c)
#ifndef MULTIPLICITY
SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *))
#else
SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *))
#endif
#else
# define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
SWIGRUNTIME void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *))
#endif
{
MAGIC *mg;
sv_magic(sv,sv,'U',(char *) name,strlen(name));
mg = mg_find(sv,'U');
mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL));
mg->mg_virtual->svt_get = (SwigMagicFunc) get;
mg->mg_virtual->svt_set = (SwigMagicFunc) set;
mg->mg_virtual->svt_len = 0;
mg->mg_virtual->svt_clear = 0;
mg->mg_virtual->svt_free = 0;
}
SWIGRUNTIME swig_module_info *
SWIG_Perl_GetModule(void) {
static void *type_pointer = (void *)0;
SV *pointer;
/* first check if pointer already created */
if (!type_pointer) {
pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE);
if (pointer && SvOK(pointer)) {
type_pointer = INT2PTR(swig_type_info **, SvIV(pointer));
}
}
return (swig_module_info *) type_pointer;
}
SWIGRUNTIME void
SWIG_Perl_SetModule(swig_module_info *module) {
SV *pointer;
/* create a new pointer */
pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE);
sv_setiv(pointer, PTR2IV(module));
}
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,8 @@
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "swigerrors.swg" // SWIG errors
%runtime "perlhead.swg" // Perl includes and fixes
%runtime "perlerrors.swg" // Perl errors
%runtime "perlrun.swg" // Perl runtime functions
%runtime "noembed.h" // undefine Perl5 macros
@@ -0,0 +1,54 @@
/* ------------------------------------------------------------
* utility methods for char strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
SWIGINTERN int
SWIG_AsCharPtrAndSize(SV *obj, char** cptr, size_t* psize, int *alloc)
{
if (SvPOK(obj)) {
STRLEN len = 0;
char *cstr = SvPV(obj, len);
size_t size = len + 1;
if (cptr) {
if (alloc) {
if (*alloc == SWIG_NEWOBJ) {
*cptr = %new_copy_array(cstr, size, char);
} else {
*cptr = cstr;
*alloc = SWIG_OLDOBJ;
}
}
}
if (psize) *psize = size;
return SWIG_OK;
} else {
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
if (pchar_descriptor) {
char* vptr = 0;
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_descriptor, 0) == SWIG_OK) {
if (cptr) *cptr = vptr;
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
if (alloc) *alloc = SWIG_OLDOBJ;
return SWIG_OK;
}
}
}
return SWIG_TypeError;
}
}
%fragment("SWIG_FromCharPtrAndSize","header") {
SWIGINTERNINLINE SV *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
SV *obj = sv_newmortal();
if (carray) {
sv_setpvn(obj, carray, size);
} else {
sv_setsv(obj, &PL_sv_undef);
}
return obj;
}
}
@@ -0,0 +1,91 @@
/* ------------------------------------------------------------
* Typemap specializations for Perl
* ------------------------------------------------------------ */
/* ------------------------------------------------------------
* Fragment section
* ------------------------------------------------------------ */
/*
in Perl we need to pass the CPerlObj value, sometimes, so, we define
the decl/call macros as needed.
*/
#define SWIG_AS_DECL_ARGS SWIG_PERL_DECL_ARGS_2
#define SWIG_AS_CALL_ARGS SWIG_PERL_CALL_ARGS_2
#define SWIG_FROM_DECL_ARGS SWIG_PERL_DECL_ARGS_1
#define SWIG_FROM_CALL_ARGS SWIG_PERL_CALL_ARGS_1
/* Include fundamental fragemt definitions */
%include <typemaps/fragments.swg>
/* Look for user fragments file. */
%include <perlfragments.swg>
/* Perl fragments for primitive types */
%include <perlprimtypes.swg>
/* Perl fragments for char* strings */
%include <perlstrings.swg>
/* ------------------------------------------------------------
* Unified typemap section
* ------------------------------------------------------------ */
/* No director supported in Perl */
#ifdef SWIG_DIRECTOR_TYPEMAPS
#undef SWIG_DIRECTOR_TYPEMAPS
#endif
/* Perl types */
#define SWIG_Object SV *
/* Perl $shadow flag */
#define %newpointer_flags $shadow
#define %newinstance_flags $shadow
/* Complete overload of the output/constant/exception macros */
/* output */
%define %set_output(obj) $result = obj; argvi++ %enddef
/* append output */
%define %append_output(obj) if (argvi >= items) EXTEND(sp,1); %set_output(obj) %enddef
/* variable output */
%define %set_varoutput(obj) sv_setsv($result,obj) %enddef
/* constant */
%define %set_constant(name, obj) %begin_block
SV *sv = get_sv((char*) SWIG_prefix name, TRUE | 0x2);
sv_setsv(sv, obj);
SvREADONLY_on(sv);
%end_block %enddef
/* raise exception */
%define %raise(obj, type, desc) sv_setsv(GvSV(PL_errgv), obj); SWIG_fail %enddef
/* Include the unified typemap library */
%include <typemaps/swigtypemaps.swg>
/* ------------------------------------------------------------
* Perl extra typemaps
* ------------------------------------------------------------ */
%typemap(varout,type="$1_descriptor") SWIGTYPE *, SWIGTYPE []
"sv_setiv(SvRV($result),PTR2IV($1));";
%typemap(varout,type="$1_descriptor") SWIGTYPE &
"sv_setiv(SvRV($result),PTR2IV(&$1));";
%typemap(varout,type="$&1_descriptor") SWIGTYPE
"sv_setiv(SvRV($result), PTR2IV(&$1));";
%typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) {
SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor);
}
@@ -0,0 +1,2 @@
#define %perlcode %insert("perl")
@@ -0,0 +1,235 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* reference.i
*
* Accept Perl references as pointers
* ----------------------------------------------------------------------------- */
/*
The following methods make Perl references work like simple C
pointers. References can only be used for simple input/output
values, not C arrays however. It should also be noted that
REFERENCES are specific to Perl and not supported in other
scripting languages at this time.
int *REFERENCE
short *REFERENCE
long *REFERENCE
unsigned int *REFERENCE
unsigned short *REFERENCE
unsigned long *REFERENCE
unsigned char *REFERENCE
float *REFERENCE
double *REFERENCE
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include reference.i
void neg(double *REFERENCE);
or you can use the %apply directive :
%include reference.i
%apply double *REFERENCE { double *x };
void neg(double *x);
Unlike the INOUT mapping described in typemaps.i, this approach directly
modifies the value of a Perl reference. Thus, you could use it
as follows :
$x = 3;
neg(\$x);
print "$x\n"; # Should print out -3.
*/
%typemap(in) double *REFERENCE (double dvalue), double &REFERENCE(double dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
printf("Received %d\n", SvTYPE(tempsv));
SWIG_croak("Expected a double reference.");
}
dvalue = SvNV(tempsv);
$1 = &dvalue;
}
%typemap(in) float *REFERENCE (float dvalue), float &REFERENCE(float dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
SWIG_croak("expected a double reference");
}
dvalue = (float) SvNV(tempsv);
$1 = &dvalue;
}
%typemap(in) int *REFERENCE (int dvalue), int &REFERENCE (int dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) short *REFERENCE (short dvalue), short &REFERENCE(short dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (short) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) long *REFERENCE (long dvalue), long &REFERENCE(long dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (long) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned int *REFERENCE (unsigned int dvalue), unsigned int &REFERENCE(unsigned int dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned int) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned short *REFERENCE (unsigned short dvalue), unsigned short &REFERENCE(unsigned short dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned short) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned long *REFERENCE (unsigned long dvalue), unsigned long &REFERENCE(unsigned long dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned long) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned char *REFERENCE (unsigned char dvalue), unsigned char &REFERENCE(unsigned char dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned char) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) signed char *REFERENCE (signed char dvalue), signed char &REFERENCE(signed char dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (signed char) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) bool *REFERENCE (bool dvalue), bool &REFERENCE(bool dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (bool) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(argout) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
SV *tempsv;
tempsv = SvRV($arg);
if (!$1) SWIG_croak("expected a reference");
sv_setnv(tempsv, (double) *$1);
}
%typemap(argout) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, unsigned char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
SV *tempsv;
tempsv = SvRV($input);
if (!$1) SWIG_croak("expected a reference");
sv_setiv(tempsv, (IV) *$1);
}
%typemap(argout) unsigned int *REFERENCE, unsigned int &REFERENCE,
unsigned short *REFERENCE, unsigned short &REFERENCE,
unsigned long *REFERENCE, unsigned long &REFERENCE,
unsigned char *REFERENCE, unsigned char &REFERENCE
{
SV *tempsv;
tempsv = SvRV($input);
if (!$1) SWIG_croak("expected a reference");
sv_setuv(tempsv, (UV) *$1);
}
@@ -0,0 +1,29 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_common.i
*
* SWIG typemaps for STL - common utilities
* ----------------------------------------------------------------------------- */
%include <std/std_except.i>
%apply size_t { std::size_t };
%{
#include <string>
double SwigSvToNumber(SV* sv) {
return SvIOK(sv) ? double(SvIVX(sv)) : SvNVX(sv);
}
std::string SwigSvToString(SV* sv) {
STRLEN len;
char *ptr = SvPV(sv, len);
return std::string(ptr, len);
}
void SwigSvFromString(SV* sv, const std::string& s) {
sv_setpvn(sv,s.data(),s.size());
}
%}
@@ -0,0 +1 @@
%include <std/_std_deque.i>
@@ -0,0 +1 @@
%include <typemaps/std_except.swg>
@@ -0,0 +1,368 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_list.i
*
* SWIG typemaps for std::list types
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <exception.i>
// containers
// ------------------------------------------------------------------------
// std::list
//
// The aim of all that follows would be to integrate std::list with
// Perl as much as possible, namely, to allow the user to pass and
// be returned Perl arrays.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::list<T>), f(const std::list<T>&), f(const std::list<T>*):
// the parameter being read-only, either a Perl sequence or a
// previously wrapped std::list<T> can be passed.
// -- f(std::list<T>&), f(std::list<T>*):
// the parameter must be modified; therefore, only a wrapped std::list
// can be passed.
// -- std::list<T> f():
// the list is returned by copy; therefore, a Perl sequence of T:s
// is returned which is most easily used in other Perl functions
// -- std::list<T>& f(), std::list<T>* f(), const std::list<T>& f(),
// const std::list<T>* f():
// the list is returned by reference; therefore, a wrapped std::list
// is returned
// ------------------------------------------------------------------------
%{
#include <list>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class T> class list {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1) {
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
$1.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const list<T>& (std::list<T> temp,
std::list<T>* v),
const list<T>* (std::list<T> temp,
std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
temp.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) list<T> {
std::list<T>::const_iterator i;
unsigned int j;
int len = $1.size();
SV **svs = new SV*[len];
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
T* ptr = new T(*i);
svs[j] = sv_newmortal();
SWIG_MakePtr(svs[j], (void*) ptr,
$descriptor(T *), $shadow|$owner);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
const list<T>* {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
list();
list(const list<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
};
// specializations for built-ins
%define specialize_std_list(T,CHECK_T,TO_T,FROM_T)
template<> class list<T> {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
$1.push_back(TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const list<T>& (std::list<T> temp,
std::list<T>* v),
const list<T>* (std::list<T> temp,
std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
temp.push_back(TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) list<T> {
std::list<T>::const_iterator i;
unsigned int j;
int len = $1.size();
SV **svs = new SV*[len];
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
svs[j] = sv_newmortal();
FROM_T(svs[j], *i);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
const list<T>* {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
list();
list(const list<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
};
%enddef
specialize_std_list(bool,SvIOK,SvIVX,sv_setiv);
specialize_std_list(char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(float,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(double,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(std::string,SvPOK,SvPVX,SwigSvFromString);
}
+175
View File
@@ -0,0 +1,175 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_map.i
*
* SWIG typemaps for std::map
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class K, class T> class map {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
// specializations for built-ins
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
template<class T> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, const T& x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
template<class K> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, T x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
template<> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, T x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
// add specializations here
}
@@ -0,0 +1,37 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_pair.i
*
* SWIG typemaps for std::pair
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <exception.i>
// ------------------------------------------------------------------------
// std::pair
// ------------------------------------------------------------------------
%{
#include <utility>
%}
namespace std {
template<class T, class U> struct pair {
pair();
pair(T t, U u);
pair(const pair& p);
template <class U1, class U2> pair(const pair<U1, U2> &p);
T first;
U second;
};
// add specializations here
}
@@ -0,0 +1,2 @@
%include <perlstrings.swg>
%include <typemaps/std_string.swg>
@@ -0,0 +1,571 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_vector.i
*
* SWIG typemaps for std::vector types
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::vector
//
// The aim of all that follows would be to integrate std::vector with
// Perl as much as possible, namely, to allow the user to pass and
// be returned Perl arrays.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
// the parameter being read-only, either a Perl sequence or a
// previously wrapped std::vector<T> can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*):
// the parameter must be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T> f():
// the vector is returned by copy; therefore, a Perl sequence of T:s
// is returned which is most easily used in other Perl functions
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
// const std::vector<T>* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// ------------------------------------------------------------------------
%{
#include <vector>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class T> class vector {
%typemap(in) vector<T> (std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1) {
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
$1.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
temp.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T> {
int len = $1.size();
SV **svs = new SV*[len];
for (unsigned int i=0; i<len; i++) {
T* ptr = new T($1[i]);
svs[i] = sv_newmortal();
SWIG_MakePtr(svs[i], (void*) ptr,
$descriptor(T *), $shadow|$owner);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
SV **tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>* {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
SV **tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T& get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
// specializations for pointers
template<class T> class vector<T*> {
%typemap(in) vector<T*> (std::vector<T*>* v) {
int res = SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0);
if (SWIG_IsOK(res)){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
void *v;
SV **tv = av_fetch(av, i, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res)) {
$1.push_back(%static_cast(v, T *));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T *>& (std::vector<T *> temp,std::vector<T *>* v),
const vector<T *>* (std::vector<T *> temp,std::vector<T *>* v) {
int res = SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
void *v;
SV **tv = av_fetch(av, i, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res)) {
temp.push_back(%static_cast(v, T *));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T *> {
size_t len = $1.size();
SV **svs = new SV*[len];
for (size_t i=0; i<len; i++) {
T *x = (($1_type &)$1)[i];
svs[i] = sv_newmortal();
sv_setsv(svs[i], SWIG_NewPointerObj(x, $descriptor(T *), 0));
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T *> {
{
/* wrapped vector? */
std::vector<T *>* v;
int res = SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
void *v;
SV **tv = av_fetch(av, 0, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T *>&,const vector<T *>* {
{
/* wrapped vector? */
std::vector<T *> *v;
int res = SWIG_ConvertPtr($input,%as_voidptrptr(&v), $1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
void *v;
SV **tv = av_fetch(av, 0, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
vector(unsigned int size = 0);
vector(unsigned int size, T *value);
vector(const vector<T *> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T *x);
%extend {
T *pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T *x = self->back();
self->pop_back();
return x;
}
T *get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T *x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
// specializations for built-ins
%define specialize_std_vector(T,CHECK_T,TO_T,FROM_T)
template<> class vector<T> {
%typemap(in) vector<T> (std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
$1.push_back((T)TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
temp.push_back((T)TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T> {
size_t len = $1.size();
SV **svs = new SV*[len];
for (size_t i=0; i<len; i++) {
svs[i] = sv_newmortal();
FROM_T(svs[i], $1[i]);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
SV **tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>* {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
SV **tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
vector(unsigned int size = 0);
vector(unsigned int size, T value);
vector(const vector<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
%enddef
specialize_std_vector(bool,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(char,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(int,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(short,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(long,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned char,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned int,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned short,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned long,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(float,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_vector(double,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_vector(std::string,SvPOK,SwigSvToString,SwigSvFromString);
}
+14
View File
@@ -0,0 +1,14 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* stl.i
*
* Initial STL definition. extended as needed in each language
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>
@@ -0,0 +1,374 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* typemaps.i
*
* The SWIG typemap library provides a language independent mechanism for
* supporting output arguments, input values, and other C function
* calling mechanisms. The primary use of the library is to provide a
* better interface to certain C function--especially those involving
* pointers.
* ----------------------------------------------------------------------------- */
#if !defined(SWIG_USE_OLD_TYPEMAPS)
%include <typemaps/typemaps.swg>
#else
// INPUT typemaps.
// These remap a C pointer to be an "INPUT" value which is passed by value
// instead of reference.
/*
The following methods can be applied to turn a pointer into a simple
"input" value. That is, instead of passing a pointer to an object,
you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
long long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
unsigned long long *INPUT
unsigned char *INPUT
bool *INPUT
float *INPUT
double *INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include typemaps.i
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
*/
%define INPUT_TYPEMAP(type, converter)
%typemap(in) type *INPUT(type temp), type &INPUT(type temp) {
temp = (type) converter($input);
$1 = &temp;
}
%typemap(typecheck) type *INPUT = type;
%typemap(typecheck) type &INPUT = type;
%enddef
INPUT_TYPEMAP(float, SvNV);
INPUT_TYPEMAP(double, SvNV);
INPUT_TYPEMAP(int, SvIV);
INPUT_TYPEMAP(long, SvIV);
INPUT_TYPEMAP(short, SvIV);
INPUT_TYPEMAP(signed char, SvIV);
INPUT_TYPEMAP(unsigned int, SvUV);
INPUT_TYPEMAP(unsigned long, SvUV);
INPUT_TYPEMAP(unsigned short, SvUV);
INPUT_TYPEMAP(unsigned char, SvUV);
%typemap(in) bool *INPUT(bool temp), bool &INPUT(bool temp) {
temp = SvIV($input) ? true : false;
$1 = &temp;
}
%typemap(typecheck) bool *INPUT = bool;
%typemap(typecheck) bool &INPUT = bool;
%typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) {
temp = strtoll(SvPV_nolen($input), 0, 0);
$1 = &temp;
}
%typemap(typecheck) long long *INPUT = long long;
%typemap(typecheck) long long &INPUT = long long;
%typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) {
temp = strtoull(SvPV_nolen($input), 0, 0);
$1 = &temp;
}
%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
#undef INPUT_TYPEMAP
// OUTPUT typemaps. These typemaps are used for parameters that
// are output only. The output value is appended to the result as
// a list element.
/*
The following methods can be applied to turn a pointer into an "output"
value. When calling a function, no input value would be given for
a parameter, but an output value would be returned. In the case of
multiple output values, functions will return a Perl array.
int *OUTPUT
short *OUTPUT
long *OUTPUT
long long *OUTPUT
unsigned int *OUTPUT
unsigned short *OUTPUT
unsigned long *OUTPUT
unsigned long long *OUTPUT
unsigned char *OUTPUT
bool *OUTPUT
float *OUTPUT
double *OUTPUT
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
returns the integer part in one of its parameters).:
double modf(double x, double *ip);
You could wrap it with SWIG as follows :
%include typemaps.i
double modf(double x, double *OUTPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *OUTPUT { double *ip };
double modf(double x, double *ip);
The Perl output of the function would be an array containing both
output values.
*/
// Force the argument to be ignored.
%typemap(in,numinputs=0) int *OUTPUT(int temp), int &OUTPUT(int temp),
short *OUTPUT(short temp), short &OUTPUT(short temp),
long *OUTPUT(long temp), long &OUTPUT(long temp),
unsigned int *OUTPUT(unsigned int temp), unsigned int &OUTPUT(unsigned int temp),
unsigned short *OUTPUT(unsigned short temp), unsigned short &OUTPUT(unsigned short temp),
unsigned long *OUTPUT(unsigned long temp), unsigned long &OUTPUT(unsigned long temp),
unsigned char *OUTPUT(unsigned char temp), unsigned char &OUTPUT(unsigned char temp),
signed char *OUTPUT(signed char temp), signed char &OUTPUT(signed char temp),
bool *OUTPUT(bool temp), bool &OUTPUT(bool temp),
float *OUTPUT(float temp), float &OUTPUT(float temp),
double *OUTPUT(double temp), double &OUTPUT(double temp),
long long *OUTPUT($*1_ltype temp), long long &OUTPUT($*1_ltype temp),
unsigned long long *OUTPUT($*1_ltype temp), unsigned long long &OUTPUT($*1_ltype temp)
"$1 = &temp;";
%typemap(argout) int *OUTPUT, int &OUTPUT,
short *OUTPUT, short &OUTPUT,
long *OUTPUT, long &OUTPUT,
signed char *OUTPUT, signed char &OUTPUT,
bool *OUTPUT, bool &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setiv($result,(IV) *($1));
argvi++;
}
%typemap(argout) unsigned int *OUTPUT, unsigned int &OUTPUT,
unsigned short *OUTPUT, unsigned short &OUTPUT,
unsigned long *OUTPUT, unsigned long &OUTPUT,
unsigned char *OUTPUT, unsigned char &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setuv($result,(UV) *($1));
argvi++;
}
%typemap(argout) float *OUTPUT, float &OUTPUT,
double *OUTPUT, double &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setnv($result,(double) *($1));
argvi++;
}
%typemap(argout) long long *OUTPUT, long long &OUTPUT {
char temp[256];
if (argvi >= items) {
EXTEND(sp,1);
}
sprintf(temp,"%lld", (long long)*($1));
$result = sv_newmortal();
sv_setpv($result,temp);
argvi++;
}
%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT {
char temp[256];
if (argvi >= items) {
EXTEND(sp,1);
}
sprintf(temp,"%llu", (unsigned long long)*($1));
$result = sv_newmortal();
sv_setpv($result,temp);
argvi++;
}
// INOUT
// Mappings for an argument that is both an input and output
// parameter
/*
The following methods can be applied to make a function parameter both
an input and output value. This combines the behavior of both the
"INPUT" and "OUTPUT" methods described earlier. Output values are
returned in the form of a Perl array.
int *INOUT
short *INOUT
long *INOUT
long long *INOUT
unsigned int *INOUT
unsigned short *INOUT
unsigned long *INOUT
unsigned long long *INOUT
unsigned char *INOUT
bool *INOUT
float *INOUT
double *INOUT
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include typemaps.i
void neg(double *INOUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INOUT { double *x };
void neg(double *x);
Unlike C, this mapping does not directly modify the input value.
Rather, the modified input value shows up as the return value of the
function. Thus, to apply this function to a Perl variable you might
do this :
$x = neg($x);
*/
%typemap(in) int *INOUT = int *INPUT;
%typemap(in) short *INOUT = short *INPUT;
%typemap(in) long *INOUT = long *INPUT;
%typemap(in) unsigned *INOUT = unsigned *INPUT;
%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
%typemap(in) signed char *INOUT = signed char *INPUT;
%typemap(in) bool *INOUT = bool *INPUT;
%typemap(in) float *INOUT = float *INPUT;
%typemap(in) double *INOUT = double *INPUT;
%typemap(in) long long *INOUT = long long *INPUT;
%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
%typemap(in) int &INOUT = int &INPUT;
%typemap(in) short &INOUT = short &INPUT;
%typemap(in) long &INOUT = long &INPUT;
%typemap(in) unsigned &INOUT = unsigned &INPUT;
%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
%typemap(in) signed char &INOUT = signed char &INPUT;
%typemap(in) bool &INOUT = bool &INPUT;
%typemap(in) float &INOUT = float &INPUT;
%typemap(in) double &INOUT = double &INPUT;
%typemap(in) long long &INOUT = long long &INPUT;
%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
%typemap(argout) int *INOUT = int *OUTPUT;
%typemap(argout) short *INOUT = short *OUTPUT;
%typemap(argout) long *INOUT = long *OUTPUT;
%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
%typemap(argout) bool *INOUT = bool *OUTPUT;
%typemap(argout) float *INOUT = float *OUTPUT;
%typemap(argout) double *INOUT = double *OUTPUT;
%typemap(argout) long long *INOUT = long long *OUTPUT;
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
%typemap(argout) int &INOUT = int &OUTPUT;
%typemap(argout) short &INOUT = short &OUTPUT;
%typemap(argout) long &INOUT = long &OUTPUT;
%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
%typemap(argout) signed char &INOUT = signed char &OUTPUT;
%typemap(argout) bool &INOUT = bool &OUTPUT;
%typemap(argout) float &INOUT = float &OUTPUT;
%typemap(argout) double &INOUT = double &OUTPUT;
%typemap(argout) long long &INOUT = long long &OUTPUT;
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
/* Overloading information */
%typemap(typecheck) double *INOUT = double;
%typemap(typecheck) bool *INOUT = bool;
%typemap(typecheck) signed char *INOUT = signed char;
%typemap(typecheck) unsigned char *INOUT = unsigned char;
%typemap(typecheck) unsigned long *INOUT = unsigned long;
%typemap(typecheck) unsigned short *INOUT = unsigned short;
%typemap(typecheck) unsigned int *INOUT = unsigned int;
%typemap(typecheck) long *INOUT = long;
%typemap(typecheck) short *INOUT = short;
%typemap(typecheck) int *INOUT = int;
%typemap(typecheck) float *INOUT = float;
%typemap(typecheck) long long *INOUT = long long;
%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
%typemap(typecheck) double &INOUT = double;
%typemap(typecheck) bool &INOUT = bool;
%typemap(typecheck) signed char &INOUT = signed char;
%typemap(typecheck) unsigned char &INOUT = unsigned char;
%typemap(typecheck) unsigned long &INOUT = unsigned long;
%typemap(typecheck) unsigned short &INOUT = unsigned short;
%typemap(typecheck) unsigned int &INOUT = unsigned int;
%typemap(typecheck) long &INOUT = long;
%typemap(typecheck) short &INOUT = short;
%typemap(typecheck) int &INOUT = int;
%typemap(typecheck) float &INOUT = float;
%typemap(typecheck) long long &INOUT = long long;
%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
#endif
// --------------------------------------------------------------------
// Special types
// --------------------------------------------------------------------
%include <reference.i>