update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1,119 @@
# ---------------------------------------------------------------
# SWIG Python Makefile
#
# This file can be used to build various Python 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 = mypython # 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 = -python
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIBS = -lembed.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
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@
PY_LIB = @PYLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options
BUILD_LIBS = $(LIBS) # Dynamic loading
# 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) $(WRAPFILE) $(INCLUDES) $(PY_INCLUDE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIBS) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,104 @@
/* -----------------------------------------------------------------------------
*
* User interfaces: include these ones as needed
*
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Special types and user helpers
* ----------------------------------------------------------------------------- */
argcargv.i Handler for (int argc, char **argv)
attribute.i Convert a pair of set/get methods into a "native" python attribute
ccomplex.i C99 complex type
complex.i C99 or C++ complex type
cstring.i Various forms of C character string handling
cwstring.i Various forms of C wchar_t string handling
embed.i embedding the Python interpreter in something else
file.i FILE C type
implicit.i Allow the use of implicit C++ constructors
wchar.i wchar_t C type
/* -----------------------------------------------------------------------------
* C++ STD + STL
* ----------------------------------------------------------------------------- */
std_alloc.i allocator
std_basic_string.i basic string
std_char_traits.i char traits
std_complex.i complex
std_deque.i deque
std_except.i exceptions
std_ios.i ios
std_iostream.i istream/ostream
std_list.i list
std_map.i map
std_multimap.i multimap
std_multiset.i multiset
std_pair.i pair
std_set.i set
std_sstream.i string stream
std_streambuf.i streambuf
std_string.i string
std_vector.i vector
std_wios.i wios
std_wiostream.i wistream/wostream
std_wsstream.i wstring stream
std_wstreambuf.i wstreambuf
std_wstring.i wstring
/* -----------------------------------------------------------------------------
/*
* Implementation files: don't look at them unless you are really drunk
*
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Basic files
* ----------------------------------------------------------------------------- */
python.swg Main language file, it just includes what is needed.
pyuserdir.swg User visible directives (%pythonnondynamic, etc)
pymacros.swg Internal macros used for typemaps
pyfragments.swg Allow the user to overload the default fragments
pyopers.swg Python operations (+=, *=, etc)
pythonkw.swg Python keywords and special names
pyinit.swg Python Init method
/* -----------------------------------------------------------------------------
* The runtime part
* ----------------------------------------------------------------------------- */
pyruntime.swg Main runtime file definition
pyapi.swg SWIG/Python API declarations
pyrun.swg Python run-time code
/* -----------------------------------------------------------------------------
* Internal typemap specializations
* ----------------------------------------------------------------------------- */
pyswigtype.swg SWIGTYPE
pystrings.swg Char strings (char *)
pywstrings.swg Wchar Strings (wchar_t *)
pyprimtypes.swg Primitive types (shot,int,double,etc)
pycomplex.swg PyComplex and helper for C/C++ complex types
pydocs.swg Typemaps documentation
/* -----------------------------------------------------------------------------
* C++ STD + STL
* ----------------------------------------------------------------------------- */
pycontainer.swg python container iterators
std_common.i general common code for the STD/STL implementation
std_container.i general common code for the STD/STL containers
/*-----------------------------------------------------------------------------
* Backward compatibility and deprecated
* ----------------------------------------------------------------------------- */
std_vectora.i vector + allocator (allocators are now supported in STD/STL)
typemaps.i old in/out typemaps (doesn't need to be included)
defarg.swg for processing default arguments with shadow classes

View File

@@ -0,0 +1,92 @@
/* ------------------------------------------------------------
* --- Argc & Argv ---
* ------------------------------------------------------------ */
%fragment("SWIG_AsArgcArgv","header",fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsArgcArgv(PyObject *input,
swig_type_info *ppchar_info,
size_t *argc, char ***argv, int *owner)
{
void *vptr;
int res = SWIG_ConvertPtr(input, &vptr, ppchar_info, 0);
if (!SWIG_IsOK(res)) {
int list = 0;
PyErr_Clear();
list = PyList_Check(input);
if (list || PyTuple_Check(input)) {
size_t i = 0;
size_t size = list ? PyList_Size(input) : PyTuple_Size(input);
if (argc) *argc = size;
if (argv) {
*argv = %new_array(size + 1, char*);
for (; i < size; ++i) {
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,i);
char *cptr = 0; size_t sz = 0; int alloc = 0;
res = SWIG_AsCharPtrAndSize(obj, &cptr, &sz, &alloc);
if (SWIG_IsOK(res)) {
if (cptr && sz) {
(*argv)[i] = (alloc == SWIG_NEWOBJ) ? cptr : %new_copy_array(cptr, sz, char);
} else {
(*argv)[i] = 0;
}
} else {
return SWIG_TypeError;
}
}
(*argv)[i] = 0;
if (owner) *owner = 1;
} else {
for (; i < size; ++i) {
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,i);
res = SWIG_AsCharPtrAndSize(obj, 0, 0, 0);
if (!SWIG_IsOK(res)) return SWIG_TypeError;
}
if (owner) *owner = 0;
}
return SWIG_OK;
} else {
return SWIG_TypeError;
}
} else {
/* seems dangerous, but the user asked for it... */
size_t i = 0;
if (argv) { while (*argv[i] != 0) ++i;}
if (argc) *argc = i;
if (owner) *owner = 0;
return SWIG_OK;
}
}
}
/*
This typemap works with either a char **, a python list or a python
tuple
*/
%typemap(in,noblock=0,fragment="SWIG_AsArgcArgv") (int ARGC, char **ARGV) (int res,char **argv = 0, size_t argc = 0, int owner= 0) {
res = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &argv, &owner);
if (!SWIG_IsOK(res)) {
$1 = 0; $2 = 0;
%argument_fail(SWIG_TypeError, "int ARGC, char **ARGV", $symname, $argnum);
} else {
$1 = %static_cast(argc,$1_ltype);
$2 = %static_cast(argv, $2_ltype);
}
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
int res = SWIG_AsArgcArgv($input, $descriptor(char**), 0, 0, 0);
$1 = SWIG_IsOK(res);
}
%typemap(freearg,noblock=1) (int ARGC, char **ARGV) {
if (owner$argnum) {
size_t i = argc$argnum;
while (i) {
%delete_array(argv$argnum[--i]);
}
%delete_array(argv$argnum);
}
}

View File

@@ -0,0 +1 @@
%include <typemaps/attribute.swg>

View File

@@ -0,0 +1,411 @@
%include <shared_ptr.i>
// Set SHARED_PTR_DISOWN to $disown if required, for example
// #define SHARED_PTR_DISOWN $disown
#if !defined(SHARED_PTR_DISOWN)
#define SHARED_PTR_DISOWN 0
#endif
%fragment("SWIG_null_deleter_python", "header", fragment="SWIG_null_deleter") {
%#define SWIG_NO_NULL_DELETER_SWIG_BUILTIN_INIT
}
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Typemap customisations...
// plain value
%typemap(in) CONST TYPE (void *argp, int res = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (!argp) {
%argument_nullref("$type", $symname, $argnum);
} else {
$1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
}
}
%typemap(out) CONST TYPE {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
if (!argp) {
%variable_nullref("$type", "$name");
} else {
$1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
}
}
%typemap(varout) CONST TYPE {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) CONST TYPE (void *swig_argp, int swig_res = 0) {
int newmem = 0;
swig_res = SWIG_ConvertPtrAndOwn($input, &swig_argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(swig_res)) {
%dirout_fail(swig_res, "$type");
}
if (!swig_argp) {
%dirout_nullref("$type");
} else {
$result = *(%reinterpret_cast(swig_argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(swig_argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
}
}
// plain pointer
// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance
%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE * {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0;
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1, fragment="SWIG_null_deleter_python") CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) CONST TYPE * %{
#error "directorout typemap for plain pointer not implemented"
%}
// plain reference
%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (!argp) { %argument_nullref("$type", $symname, $argnum); }
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
$1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE & {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
if (!argp) {
%variable_nullref("$type", "$name");
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = *%const_cast(tempshared.get(), $1_ltype);
} else {
$1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1, fragment="SWIG_null_deleter_python") CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) CONST TYPE & %{
#error "directorout typemap for plain reference not implemented"
%}
// plain pointer by reference
// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance
%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
temp = %const_cast(tempshared.get(), $*1_ltype);
} else {
temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype);
}
$1 = &temp;
}
%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) TYPE *CONST& %{
#error "varin typemap not implemented"
%}
%typemap(varout) TYPE *CONST& %{
#error "varout typemap not implemented"
%}
%typemap(directorin,noblock=1, fragment="SWIG_null_deleter_python") TYPE *CONST& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) TYPE *CONST& %{
#error "directorout typemap for plain pointer by reference not implemented"
%}
// shared_ptr by value
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (argp) $1 = *(%reinterpret_cast(argp, $&ltype));
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
int newmem = 0;
void *argp = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
$1 = argp ? *(%reinterpret_cast(argp, $&ltype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >();
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *swig_argp, int swig_res = 0) {
int newmem = 0;
swig_res = SWIG_ConvertPtrAndOwn($input, &swig_argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(swig_res)) {
%dirout_fail(swig_res, "$type");
}
if (swig_argp) {
$result = *(%reinterpret_cast(swig_argp, $&ltype));
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(swig_argp, $&ltype);
}
}
// shared_ptr by reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
delete %reinterpret_cast(argp, $ltype);
$1 = &tempshared;
} else {
$1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
}
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "varout typemap not implemented"
%}
%typemap(directorin,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "directorout typemap for shared_ptr ref not implemented"
%}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
delete %reinterpret_cast(argp, $ltype);
$1 = &tempshared;
} else {
$1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
}
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
if ($owner) delete $1;
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "varout typemap not implemented"
%}
%typemap(directorin,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "directorout typemap for pointer to shared_ptr not implemented"
%}
// shared_ptr by pointer reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (argp) tempshared = *%reinterpret_cast(argp, $*ltype);
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype);
temp = &tempshared;
$1 = &temp;
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "varout typemap not implemented"
%}
%typemap(directorin,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "directorout typemap for pointer ref to shared_ptr not implemented"
%}
// Typecheck typemaps
// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting
// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain.
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1)
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0);
$1 = SWIG_CheckState(res);
}
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%typemap(doctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{TYPE%}
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View File

@@ -0,0 +1,740 @@
#ifdef __cplusplus
extern "C" {
#endif
SWIGINTERN Py_hash_t
SwigPyObject_hash(PyObject *obj) {
SwigPyObject *sobj = (SwigPyObject *)obj;
void *ptr = sobj->ptr;
return (Py_hash_t)ptr;
}
SWIGINTERN Py_hash_t
SWIG_PyNumber_AsPyHash(PyObject *obj) {
Py_hash_t result = -1;
#if PY_VERSION_HEX < 0x03020000
if (PyInt_Check(obj))
result = PyInt_AsLong(obj);
else if (PyLong_Check(obj))
result = PyLong_AsLong(obj);
#else
if (PyNumber_Check(obj))
result = PyNumber_AsSsize_t(obj, NULL);
#endif
else
PyErr_Format(PyExc_TypeError, "Wrong type for hash function");
return PyErr_Occurred() ? -1 : result;
}
SWIGINTERN int
SwigPyBuiltin_BadInit(PyObject *self, PyObject *SWIGUNUSEDPARM(args), PyObject *SWIGUNUSEDPARM(kwds)) {
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
return -1;
}
SWIGINTERN void
SwigPyBuiltin_BadDealloc(PyObject *obj) {
SwigPyObject *sobj = (SwigPyObject *)obj;
if (sobj->own) {
PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", obj->ob_type->tp_name);
}
}
typedef struct {
PyCFunction get;
PyCFunction set;
} SwigPyGetSet;
SWIGINTERN PyObject *
SwigPyBuiltin_GetterClosure (PyObject *obj, void *closure) {
SwigPyGetSet *getset;
PyObject *tuple, *result;
if (!closure)
return SWIG_Py_Void();
getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
tuple = PyTuple_New(0);
assert(tuple);
result = (*getset->get)(obj, tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject *
SwigPyBuiltin_FunpackGetterClosure (PyObject *obj, void *closure) {
SwigPyGetSet *getset;
PyObject *result;
if (!closure)
return SWIG_Py_Void();
getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
result = (*getset->get)(obj, NULL);
return result;
}
SWIGINTERN int
SwigPyBuiltin_SetterClosure (PyObject *obj, PyObject *val, void *closure) {
SwigPyGetSet *getset;
PyObject *tuple, *result;
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
tuple = PyTuple_New(1);
assert(tuple);
Py_INCREF(val);
PyTuple_SET_ITEM(tuple, 0, val);
result = (*getset->set)(obj, tuple);
Py_DECREF(tuple);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN int
SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) {
SwigPyGetSet *getset;
PyObject *result;
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
result = (*getset->set)(obj, val);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN void
SwigPyStaticVar_dealloc(PyDescrObject *descr) {
_PyObject_GC_UNTRACK(descr);
Py_XDECREF(PyDescr_TYPE(descr));
Py_XDECREF(PyDescr_NAME(descr));
PyObject_GC_Del(descr);
}
SWIGINTERN PyObject *
SwigPyStaticVar_repr(PyGetSetDescrObject *descr) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromFormat("<class attribute '%S' of type '%s'>", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
return PyString_FromFormat("<class attribute '%s' of type '%s'>", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
}
SWIGINTERN int
SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) {
PyDescrObject *descr;
descr = (PyDescrObject *)self;
Py_VISIT((PyObject*) PyDescr_TYPE(descr));
return 0;
}
SWIGINTERN PyObject *
SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *SWIGUNUSEDPARM(type)) {
if (descr->d_getset->get != NULL)
return descr->d_getset->get(obj, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not readable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
return NULL;
}
SWIGINTERN int
SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) {
if (descr->d_getset->set != NULL)
return descr->d_getset->set(obj, value, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not writable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
return -1;
}
SWIGINTERN int
SwigPyObjectType_setattro(PyObject *typeobject, PyObject *name, PyObject *value) {
PyObject *attribute;
PyTypeObject *type;
descrsetfunc local_set;
assert(PyType_Check(typeobject));
type = (PyTypeObject *)typeobject;
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
local_set = attribute->ob_type->tp_descr_set;
if (local_set != NULL)
return local_set(attribute, (PyObject *)type, value);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
} else {
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
}
return -1;
}
SWIGINTERN PyTypeObject*
SwigPyStaticVar_Type(void) {
static PyTypeObject staticvar_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
#endif
"swig_static_var_getset_descriptor", /* tp_name */
sizeof(PyGetSetDescrObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)SwigPyStaticVar_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
0, /* tp_doc */
SwigPyStaticVar_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
(descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
0, /* tp_version_tag */
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
0, /* tp_prev */
0 /* tp_next */
#endif
};
staticvar_type = tmp;
type_init = 1;
if (PyType_Ready(&staticvar_type) < 0)
return NULL;
}
return &staticvar_type;
}
SWIGINTERN PyTypeObject*
SwigPyObjectType(void) {
static char swigpyobjecttype_doc[] = "Metaclass for SWIG wrapped types";
static PyTypeObject swigpyobjecttype_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
#endif
"SwigPyObjectType", /* tp_name */
PyType_Type.tp_basicsize, /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
SwigPyObjectType_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
swigpyobjecttype_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
0, /* tp_version_tag */
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
0, /* tp_prev */
0 /* tp_next */
#endif
};
swigpyobjecttype_type = tmp;
type_init = 1;
swigpyobjecttype_type.tp_base = &PyType_Type;
if (PyType_Ready(&swigpyobjecttype_type) < 0)
return NULL;
}
return &swigpyobjecttype_type;
}
SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {
PyGetSetDescrObject *descr;
descr = (PyGetSetDescrObject *)PyType_GenericAlloc(SwigPyStaticVar_Type(), 0);
assert(descr);
Py_XINCREF(type);
PyDescr_TYPE(descr) = type;
PyDescr_NAME(descr) = PyString_InternFromString(getset->name);
descr->d_getset = getset;
if (PyDescr_NAME(descr) == NULL) {
Py_DECREF(descr);
descr = NULL;
}
return descr;
}
SWIGINTERN void
SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) {
Py_ssize_t base_count = 0;
PyTypeObject **b;
PyObject *tuple;
Py_ssize_t i;
if (!bases[0]) {
bases[0] = SwigPyObject_type();
bases[1] = NULL;
}
type->tp_base = bases[0];
Py_INCREF((PyObject *)bases[0]);
for (b = bases; *b != NULL; ++b)
++base_count;
tuple = PyTuple_New(base_count);
for (i = 0; i < base_count; ++i) {
Py_INCREF((PyObject *)bases[i]);
PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]);
}
type->tp_bases = tuple;
}
SWIGINTERN PyObject *
SwigPyBuiltin_ThisClosure (PyObject *self, void *SWIGUNUSEDPARM(closure)) {
PyObject *result;
result = (PyObject *)SWIG_Python_GetSwigThis(self);
Py_XINCREF(result);
return result;
}
SWIGINTERN void
SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
{
#if PY_VERSION_HEX >= 0x03000000
type->ob_base.ob_base.ob_type = metatype;
#else
type->ob_type = metatype;
#endif
}
/* Start of callback function macros for use in PyTypeObject */
typedef PyObject *(*SwigPyWrapperFunction)(PyObject *, PyObject *);
#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_unaryfunc_closure(PyObject *a) { \
return SwigPyBuiltin_unaryfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_unaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \
SWIGINTERN void \
wrapper##_destructor_closure(PyObject *a) { \
SwigPyBuiltin_destructor_closure(wrapper, #wrapper, a); \
}
SWIGINTERN void
SwigPyBuiltin_destructor_closure(SwigPyWrapperFunction wrapper, const char *wrappername, PyObject *a) {
SwigPyObject *sobj;
sobj = (SwigPyObject *)a;
Py_XDECREF(sobj->dict);
if (sobj->own) {
PyObject *o;
PyObject *type = 0, *value = 0, *traceback = 0;
PyErr_Fetch(&type, &value, &traceback);
o = wrapper(a, NULL);
if (!o) {
PyObject *deallocname = PyString_FromString(wrappername);
PyErr_WriteUnraisable(deallocname);
Py_DECREF(deallocname);
}
PyErr_Restore(type, value, traceback);
Py_XDECREF(o);
}
if (PyType_IS_GC(a->ob_type)) {
PyObject_GC_Del(a);
} else {
PyObject_Del(a);
}
}
#define SWIGPY_INQUIRY_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_inquiry_closure(PyObject *a) { \
return SwigPyBuiltin_inquiry_closure(wrapper, a); \
}
SWIGINTERN int
SwigPyBuiltin_inquiry_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *pyresult;
int result;
pyresult = wrapper(a, NULL);
result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0;
Py_XDECREF(pyresult);
return result;
}
#define SWIGPY_GETITERFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_getiterfunc_closure(PyObject *a) { \
return SwigPyBuiltin_getiterfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_getiterfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_binaryfunc_closure(PyObject *a, PyObject *b) { \
return SwigPyBuiltin_binaryfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_binaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b) {
PyObject *tuple, *result;
tuple = PyTuple_New(1);
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
typedef ternaryfunc ternarycallfunc;
#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ternaryfunc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_ternaryfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ternaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
PyObject *tuple, *result;
tuple = PyTuple_New(2);
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ternarycallfunc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_ternarycallfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ternarycallfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
(void) c;
return wrapper(a, b);
}
#define SWIGPY_LENFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_ssize_t \
wrapper##_lenfunc_closure(PyObject *a) { \
return SwigPyBuiltin_lenfunc_closure(wrapper, a); \
}
SWIGINTERN Py_ssize_t
SwigPyBuiltin_lenfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *resultobj;
Py_ssize_t result;
resultobj = wrapper(a, NULL);
result = PyNumber_AsSsize_t(resultobj, NULL);
Py_DECREF(resultobj);
return result;
}
#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizessizeargfunc_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \
return SwigPyBuiltin_ssizessizeargfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ssizessizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, Py_ssize_t c) {
PyObject *tuple, *result;
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_ssizessizeobjargproc_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
return SwigPyBuiltin_ssizessizeobjargproc_closure(wrapper, a, b, c, d); \
}
SWIGINTERN int
SwigPyBuiltin_ssizessizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(d ? 3 : 2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));
if (d) {
Py_INCREF(d);
PyTuple_SET_ITEM(tuple, 2, d);
}
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_DECREF(tuple);
Py_XDECREF(resultobj);
return result;
}
#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizeargfunc_closure(PyObject *a, Py_ssize_t b) { \
return SwigPyBuiltin_funpack_ssizeargfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_funpack_ssizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b) {
PyObject *tuple, *result;
tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizeargfunc_closure(PyObject *a, Py_ssize_t b) { \
return SwigPyBuiltin_ssizeargfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ssizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b) {
PyObject *arg, *result;
arg = _PyLong_FromSsize_t(b);
result = wrapper(a, arg);
Py_DECREF(arg);
return result;
}
#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_ssizeobjargproc_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \
return SwigPyBuiltin_ssizeobjargproc_closure(wrapper, a, b, c); \
}
SWIGINTERN int
SwigPyBuiltin_ssizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, PyObject *c) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_OBJOBJPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_objobjproc_closure(PyObject *a, PyObject *b) { \
return SwigPyBuiltin_objobjproc_closure(wrapper, a, b); \
}
SWIGINTERN int
SwigPyBuiltin_objobjproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b) {
int result;
PyObject *pyresult;
PyObject *tuple;
tuple = PyTuple_New(1);
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
pyresult = wrapper(a, tuple);
result = pyresult ? (PyObject_IsTrue(pyresult) ? 1 : 0) : -1;
Py_XDECREF(pyresult);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_FUNPACK_OBJOBJPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_objobjproc_closure(PyObject *a, PyObject *b) { \
return SwigPyBuiltin_funpack_objobjproc_closure(wrapper, a, b); \
}
SWIGINTERN int
SwigPyBuiltin_funpack_objobjproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b) {
int result;
PyObject *pyresult;
pyresult = wrapper(a, b);
result = pyresult ? (PyObject_IsTrue(pyresult) ? 1 : 0) : -1;
Py_XDECREF(pyresult);
return result;
}
#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_objobjargproc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_objobjargproc_closure(wrapper, a, b, c); \
}
SWIGINTERN int
SwigPyBuiltin_objobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(c ? 2 : 1);
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
if (c) {
Py_INCREF(c);
PyTuple_SET_ITEM(tuple, 1, c);
}
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_reprfunc_closure(PyObject *a) { \
return SwigPyBuiltin_reprfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_reprfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_hash_t \
wrapper##_hashfunc_closure(PyObject *a) { \
return SwigPyBuiltin_hashfunc_closure(wrapper, a); \
}
SWIGINTERN Py_hash_t
SwigPyBuiltin_hashfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *pyresult;
Py_hash_t result;
pyresult = wrapper(a, NULL);
if (!pyresult)
return -1;
result = SWIG_PyNumber_AsPyHash(pyresult);
Py_DECREF(pyresult);
return result;
}
#define SWIGPY_ITERNEXTFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_iternextfunc_closure(PyObject *a) { \
return SwigPyBuiltin_iternextfunc_closure(wrapper, a);\
}
SWIGINTERN PyObject *
SwigPyBuiltin_iternextfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
/* End of callback function macros for use in PyTypeObject */
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,13 @@
%define %array_class(TYPE,NAME)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "sq_item", functype="ssizeargfunc") NAME::__getitem__;
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
#endif
%array_class_wrap(TYPE,NAME,__getitem__,__setitem__)
%enddef
%include <typemaps/carrays.swg>

View File

@@ -0,0 +1,26 @@
/* -----------------------------------------------------------------------------
* ccomplex.i
*
* C complex typemaps
* ISO C99: 7.3 Complex arithmetic <complex.h>
* ----------------------------------------------------------------------------- */
%include <pycomplex.swg>
%{
#include <complex.h>
%}
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View File

@@ -0,0 +1 @@
%include <typemaps/cdata.swg>

View File

@@ -0,0 +1 @@
%include <typemaps/cmalloc.swg>

View File

@@ -0,0 +1,6 @@
#ifdef __cplusplus
%include <std_complex.i>
#else
%include <ccomplex.i>
#endif

View File

@@ -0,0 +1 @@
%include <typemaps/cpointer.swg>

View File

@@ -0,0 +1 @@
%include <typemaps/cstring.swg>

View File

@@ -0,0 +1,3 @@
%include <pywstrings.swg>
%include <typemaps/cwstring.swg>

View File

@@ -0,0 +1,37 @@
/* This file defines an internal function for processing default arguments
with proxy classes.
There seems to be no straightforward way to write proxy functions
involving default arguments. For example :
def foo(arg1,arg2,*args):
proxyc.foo(arg1,arg2,args)
This fails because args is now a tuple and SWIG doesn't know what to
do with it.
This file allows a different approach :
def foo(arg1,arg2,*args):
proxyc.__call_defarg(proxyc.foo,(arg1,arg2,)+args)
Basically, we form a new tuple from the object, call this special
__call_defarg method and it passes control to the real wrapper function.
An ugly hack, but it works.
*/
SWIGINTERN PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
PyObject *func;
PyObject *parms;
if (!PyArg_ParseTuple(args, "OO", &func, &parms))
return NULL;
if (!PyCallable_Check(func)) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
return PyEval_CallObject(func,parms);
}

View File

@@ -0,0 +1,429 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes so that Python proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#ifndef SWIG_DIRECTOR_PYTHON_HEADER_
#define SWIG_DIRECTOR_PYTHON_HEADER_
#include <string>
#include <iostream>
#include <exception>
#include <vector>
#include <map>
/*
Use -DSWIG_PYTHON_DIRECTOR_NO_VTABLE if you don't want to generate a 'virtual
table', and avoid multiple GetAttr calls to retrieve the python
methods.
*/
#ifndef SWIG_PYTHON_DIRECTOR_NO_VTABLE
#ifndef SWIG_PYTHON_DIRECTOR_VTABLE
#define SWIG_PYTHON_DIRECTOR_VTABLE
#endif
#endif
/*
Use -DSWIG_DIRECTOR_NO_UEH if you prefer to avoid the use of the
Undefined Exception Handler provided by swig.
*/
#ifndef SWIG_DIRECTOR_NO_UEH
#ifndef SWIG_DIRECTOR_UEH
#define SWIG_DIRECTOR_UEH
#endif
#endif
/*
Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the
native C++ RTTI and dynamic_cast<>. But be aware that directors
could stop working when using this option.
*/
#ifdef SWIG_DIRECTOR_NORTTI
/*
When we don't use the native C++ RTTI, we implement a minimal one
only for Directors.
*/
# ifndef SWIG_DIRECTOR_RTDIR
# define SWIG_DIRECTOR_RTDIR
namespace Swig {
class Director;
SWIGINTERN std::map<void *, Director *>& get_rtdir_map() {
static std::map<void *, Director *> rtdir_map;
return rtdir_map;
}
SWIGINTERNINLINE void set_rtdir(void *vptr, Director *rtdir) {
get_rtdir_map()[vptr] = rtdir;
}
SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
std::map<void *, Director *>::const_iterator pos = get_rtdir_map().find(vptr);
Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0;
return rtdir;
}
}
# endif /* SWIG_DIRECTOR_RTDIR */
# define SWIG_DIRECTOR_CAST(ARG) Swig::get_rtdir(static_cast<void *>(ARG))
# define SWIG_DIRECTOR_RGTR(ARG1, ARG2) Swig::set_rtdir(static_cast<void *>(ARG1), ARG2)
#else
# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
# define SWIG_DIRECTOR_RGTR(ARG1, ARG2)
#endif /* SWIG_DIRECTOR_NORTTI */
extern "C" {
struct swig_type_info;
}
namespace Swig {
/* memory handler */
struct GCItem {
virtual ~GCItem() {}
virtual int get_own() const {
return 0;
}
};
struct GCItem_var {
GCItem_var(GCItem *item = 0) : _item(item) {
}
GCItem_var& operator=(GCItem *item) {
GCItem *tmp = _item;
_item = item;
delete tmp;
return *this;
}
~GCItem_var() {
delete _item;
}
GCItem * operator->() const {
return _item;
}
private:
GCItem *_item;
};
struct GCItem_Object : GCItem {
GCItem_Object(int own) : _own(own) {
}
virtual ~GCItem_Object() {
}
int get_own() const {
return _own;
}
private:
int _own;
};
template <typename Type>
struct GCItem_T : GCItem {
GCItem_T(Type *ptr) : _ptr(ptr) {
}
virtual ~GCItem_T() {
delete _ptr;
}
private:
Type *_ptr;
};
template <typename Type>
struct GCArray_T : GCItem {
GCArray_T(Type *ptr) : _ptr(ptr) {
}
virtual ~GCArray_T() {
delete[] _ptr;
}
private:
Type *_ptr;
};
/* base class for director exceptions */
class DirectorException : public std::exception {
protected:
std::string swig_msg;
public:
DirectorException(PyObject *error, const char *hdr ="", const char *msg ="") : swig_msg(hdr) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (msg[0]) {
swig_msg += " ";
swig_msg += msg;
}
if (!PyErr_Occurred()) {
PyErr_SetString(error, what());
}
SWIG_PYTHON_THREAD_END_BLOCK;
}
virtual ~DirectorException() throw() {
}
/* Deprecated, use what() instead */
const char *getMessage() const {
return what();
}
const char *what() const throw() {
return swig_msg.c_str();
}
static void raise(PyObject *error, const char *msg) {
throw DirectorException(error, msg);
}
static void raise(const char *msg) {
raise(PyExc_RuntimeError, msg);
}
};
/* unknown exception handler */
class UnknownExceptionHandler {
#ifdef SWIG_DIRECTOR_UEH
static void handler() {
try {
throw;
} catch (DirectorException& e) {
std::cerr << "SWIG Director exception caught:" << std::endl
<< e.what() << std::endl;
} catch (std::exception& e) {
std::cerr << "std::exception caught: "<< e.what() << std::endl;
} catch (...) {
std::cerr << "Unknown exception caught." << std::endl;
}
std::cerr << std::endl
<< "Python interpreter traceback:" << std::endl;
PyErr_Print();
std::cerr << std::endl;
std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl
<< "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl
<< std::endl
<< "Exception is being re-thrown, program will likely abort/terminate." << std::endl;
throw;
}
public:
std::unexpected_handler old;
UnknownExceptionHandler(std::unexpected_handler nh = handler) {
old = std::set_unexpected(nh);
}
~UnknownExceptionHandler() {
std::set_unexpected(old);
}
#endif
};
/* type mismatch in the return value from a python method call */
class DirectorTypeMismatchException : public DirectorException {
public:
DirectorTypeMismatchException(PyObject *error, const char *msg="")
: DirectorException(error, "SWIG director type mismatch", msg) {
}
DirectorTypeMismatchException(const char *msg="")
: DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) {
}
static void raise(PyObject *error, const char *msg) {
throw DirectorTypeMismatchException(error, msg);
}
static void raise(const char *msg) {
throw DirectorTypeMismatchException(msg);
}
};
/* any python exception that occurs during a director method call */
class DirectorMethodException : public DirectorException {
public:
DirectorMethodException(const char *msg = "")
: DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) {
}
static void raise(const char *msg) {
throw DirectorMethodException(msg);
}
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg = "")
: DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) {
}
static void raise(const char *msg) {
throw DirectorPureVirtualException(msg);
}
};
#if defined(SWIG_PYTHON_THREADS)
/* __THREAD__ is the old macro to activate some thread support */
# if !defined(__THREAD__)
# define __THREAD__ 1
# endif
#endif
#ifdef __THREAD__
# include "pythread.h"
class Guard {
PyThread_type_lock &mutex_;
public:
Guard(PyThread_type_lock & mutex) : mutex_(mutex) {
PyThread_acquire_lock(mutex_, WAIT_LOCK);
}
~Guard() {
PyThread_release_lock(mutex_);
}
};
# define SWIG_GUARD(mutex) Guard _guard(mutex)
#else
# define SWIG_GUARD(mutex)
#endif
/* director base class */
class Director {
private:
/* pointer to the wrapped python object */
PyObject *swig_self;
/* flag indicating whether the object is owned by python or c++ */
mutable bool swig_disown_flag;
/* decrement the reference count of the wrapped python object */
void swig_decref() const {
if (swig_disown_flag) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
Py_DECREF(swig_self);
SWIG_PYTHON_THREAD_END_BLOCK;
}
}
public:
/* wrap a python object. */
Director(PyObject *self) : swig_self(self), swig_disown_flag(false) {
}
/* discard our reference at destruction */
virtual ~Director() {
swig_decref();
}
/* return a pointer to the wrapped python object */
PyObject *swig_get_self() const {
return swig_self;
}
/* acquire ownership of the wrapped python object (the sense of "disown" is from python) */
void swig_disown() const {
if (!swig_disown_flag) {
swig_disown_flag=true;
swig_incref();
}
}
/* increase the reference count of the wrapped python object */
void swig_incref() const {
if (swig_disown_flag) {
Py_INCREF(swig_self);
}
}
/* methods to implement pseudo protected director members */
virtual bool swig_get_inner(const char * /* swig_protected_method_name */) const {
return true;
}
virtual void swig_set_inner(const char * /* swig_protected_method_name */, bool /* swig_val */) const {
}
/* ownership management */
private:
typedef std::map<void *, GCItem_var> swig_ownership_map;
mutable swig_ownership_map swig_owner;
#ifdef __THREAD__
static PyThread_type_lock swig_mutex_own;
#endif
public:
template <typename Type>
void swig_acquire_ownership_array(Type *vptr) const {
if (vptr) {
SWIG_GUARD(swig_mutex_own);
swig_owner[vptr] = new GCArray_T<Type>(vptr);
}
}
template <typename Type>
void swig_acquire_ownership(Type *vptr) const {
if (vptr) {
SWIG_GUARD(swig_mutex_own);
swig_owner[vptr] = new GCItem_T<Type>(vptr);
}
}
void swig_acquire_ownership_obj(void *vptr, int own) const {
if (vptr && own) {
SWIG_GUARD(swig_mutex_own);
swig_owner[vptr] = new GCItem_Object(own);
}
}
int swig_release_ownership(void *vptr) const {
int own = 0;
if (vptr) {
SWIG_GUARD(swig_mutex_own);
swig_ownership_map::iterator iter = swig_owner.find(vptr);
if (iter != swig_owner.end()) {
own = iter->second->get_own();
swig_owner.erase(iter);
}
}
return own;
}
template <typename Type>
static PyObject *swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) {
SwigPyObject *sobj = (SwigPyObject *)pyobj;
sobj->own = 0;
Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<Type *>(sobj->ptr));
if (d)
d->swig_disown();
return PyWeakref_NewProxy(pyobj, NULL);
}
};
#ifdef __THREAD__
PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock();
#endif
}
#endif

View File

@@ -0,0 +1,106 @@
//
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is deprecated and no longer actively maintained, but it still
// seems to work with Python 2.7. Status with Python 3 is unknown.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack its setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as Tkinter). Thus, you
may need to provide additional link libraries when compiling.
As far as I know, this module is C++ safe.
%}
#endif
%wrapper %{
#include <Python.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define _PyImport_Inittab swig_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef _PyImport_Inittab
/* Now define our own version of it.
Hopefully someone does not have more than 1000 built-in modules */
struct _inittab SWIG_Import_Inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
SWIG_Import_Inittab[swig_num_modules].name = name;
SWIG_Import_Inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
SWIG_Import_Inittab[swig_num_modules].name = (char *) 0;
SWIG_Import_Inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's built-in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (swig_inittab[i].name) {
swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int Py_Main(int, char **);
#ifdef __cplusplus
}
#endif
extern struct _inittab *PyImport_Inittab;
int
main(int argc, char **argv) {
swig_add_builtin();
PyImport_Inittab = SWIG_Import_Inittab;
return Py_Main(argc,argv);
}
%}

View File

@@ -0,0 +1,6 @@
%include <typemaps/exception.swg>
%insert("runtime") {
%define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; ))
}

View File

@@ -0,0 +1 @@
%include <typemaps/factory.swg>

View File

@@ -0,0 +1,41 @@
/* -----------------------------------------------------------------------------
* file.i
*
* Typemaps for FILE*
* ----------------------------------------------------------------------------- */
%types(FILE *);
/* defining basic methods */
%fragment("SWIG_AsValFilePtr","header") {
SWIGINTERN int
SWIG_AsValFilePtr(PyObject *obj, FILE **val) {
static swig_type_info* desc = 0;
void *vptr = 0;
if (!desc) desc = SWIG_TypeQuery("FILE *");
if ((SWIG_ConvertPtr(obj, &vptr, desc, 0)) == SWIG_OK) {
if (val) *val = (FILE *)vptr;
return SWIG_OK;
}
%#if PY_VERSION_HEX < 0x03000000
if (PyFile_Check(obj)) {
if (val) *val = PyFile_AsFile(obj);
return SWIG_OK;
}
%#endif
return SWIG_TypeError;
}
}
%fragment("SWIG_AsFilePtr","header",fragment="SWIG_AsValFilePtr") {
SWIGINTERNINLINE FILE*
SWIG_AsFilePtr(PyObject *obj) {
FILE *val = 0;
SWIG_AsValFilePtr(obj, &val);
return val;
}
}
/* defining the typemaps */
%typemaps_asval(%checkcode(POINTER), SWIG_AsValFilePtr, "SWIG_AsValFilePtr", FILE*);

View File

@@ -0,0 +1,7 @@
%include <std_common.i>
%include <typemaps/implicit.swg>
#warning "This file provides the %implicit directive, which is an old and fragile"
#warning "way to implement the C++ implicit conversion mechanism."
#warning "Try using the more robust '%implicitconv Type;' directive instead."

View File

@@ -0,0 +1,10 @@
%define %pythonabc(Type, Abc)
%feature("python:abc", #Abc) Type;
%enddef
%pythoncode %{import collections.abc%}
%pythonabc(std::vector, collections.abc.MutableSequence);
%pythonabc(std::list, collections.abc.MutableSequence);
%pythonabc(std::map, collections.abc.MutableMapping);
%pythonabc(std::multimap, collections.abc.MutableMapping);
%pythonabc(std::set, collections.abc.MutableSet);
%pythonabc(std::multiset, collections.abc.MutableSet);

View File

@@ -0,0 +1,30 @@
/* -----------------------------------------------------------------------------
* Python API portion that goes into the runtime
* ----------------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C" {
#endif
/* -----------------------------------------------------------------------------
* Constant declarations
* ----------------------------------------------------------------------------- */
/* Constant Types */
#define SWIG_PY_POINTER 4
#define SWIG_PY_BINARY 5
/* Constant information structure */
typedef struct swig_const_info {
int type;
const char *name;
long lvalue;
double dvalue;
void *pvalue;
swig_type_info **ptype;
} swig_const_info;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,45 @@
/*
adding backward compatibility macros
*/
#define SWIG_arg(x...) %arg(x)
#define SWIG_Mangle(x...) %mangle(x)
#define SWIG_As_frag(Type...) %fragment_name(As, Type)
#define SWIG_As_name(Type...) %symbol_name(As, Type)
#define SWIG_As(Type...) SWIG_As_name(Type) SWIG_AS_CALL_ARGS
#define SWIG_Check_frag(Type...) %fragment_name(Check, Type)
#define SWIG_Check_name(Type...) %symbol_name(Check, Type)
#define SWIG_Check(Type...) SWIG_Check_name(Type) SWIG_AS_CALL_ARGS
%define %ascheck_methods(Code, Type...)
%fragment(SWIG_As_frag(Type),"header", fragment=SWIG_AsVal_frag(Type)) {
SWIGINTERNINLINE Type
SWIG_As(Type)(PyObject* obj)
{
Type v;
int res = SWIG_AsVal(Type)(obj, &v);
if (!SWIG_IsOK(res)) {
/*
this is needed to make valgrind/purify happier.
*/
memset((void*)&v, 0, sizeof(Type));
SWIG_Error(res, "");
}
return v;
}
}
%fragment(SWIG_Check_frag(Type),"header",fragment=SWIG_AsVal_frag(Type)) {
SWIGINTERNINLINE int
SWIG_Check(Type)(PyObject* obj)
{
int res = SWIG_AsVal(Type)(obj, (Type*)0);
return SWIG_IsOK(res);
}
}
%enddef
%apply_checkctypes(%ascheck_methods)

View File

@@ -0,0 +1,121 @@
/* Implementing buffer protocol typemaps */
/* %pybuffer_mutable_binary(TYPEMAP, SIZE)
*
* Macro for functions accept mutable buffer pointer with a size.
* This can be used for both input and output. For example:
*
* %pybuffer_mutable_binary(char *buff, int size);
* void foo(char *buff, int size) {
* for(int i=0; i<size; ++i)
* buff[i]++;
* }
*/
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; void *buf = 0;
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
size = view.len;
buf = view.buf;
PyBuffer_Release(&view);
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size/sizeof($*1_type));
}
%enddef
/* %pybuffer_mutable_string(TYPEMAP)
*
* Macro for functions accept mutable zero terminated string pointer.
* This can be used for both input and output. For example:
*
* %pybuffer_mutable_string(char *str);
* void foo(char *str) {
* while(*str) {
* *str = toupper(*str);
* str++;
* }
*/
%define %pybuffer_mutable_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; void *buf = 0;
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
buf = view.buf;
PyBuffer_Release(&view);
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
}
%enddef
/* pybuffer_binary(TYPEMAP, SIZE)
*
* Macro for functions accept read only buffer pointer with a size.
* This must be used for input. For example:
*
* %pybuffer_binary(char *buff, int size);
* int foo(char *buff, int size) {
* int count = 0;
* for(int i=0; i<size; ++i)
* if (0==buff[i]) count++;
* return count;
* }
*/
%define %pybuffer_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; const void *buf = 0;
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
size = view.len;
buf = view.buf;
PyBuffer_Release(&view);
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size / sizeof($*1_type));
}
%enddef
/* %pybuffer_string(TYPEMAP)
*
* Macro for functions accept read only zero terminated string pointer.
* This can be used for input. For example:
*
* %pybuffer_string(char *str);
* int foo(char *str) {
* int count = 0;
* while(*str) {
* if (isalnum(*str))
* count++;
* str++;
* }
*/
%define %pybuffer_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; const void *buf = 0;
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
buf = view.buf;
PyBuffer_Release(&view);
if (res < 0) {
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
}
%enddef

View File

@@ -0,0 +1,157 @@
#ifdef __cplusplus
/*
SwigPtr_PyObject is used as a replacement of PyObject *, where
the INCREF/DECREF are applied as needed.
You can use SwigPtr_PyObject in a container, such as
std::vector<SwigPtr_PyObject>;
or as a member variable:
struct A {
SwigPtr_PyObject obj;
A(PyObject *o) : _obj(o) {
}
};
or as a input/output value
SwigPtr_PyObject func(SwigPtr_PyObject obj) {
SwigPtr_PyObject out = PyString_FromFormat("hello %s", PyObject_AsString(obj));
Py_DECREF(out);
return out;
}
just remember to pair the object creation with the proper DECREF,
the same as with plain PyObject *ptr, since SwigPtr_PyObject always add
one reference at construction.
SwigPtr_PyObject is 'visible' at the wrapped side, so you can do:
%template(pyvector) std::vector<swig::SwigPtr_PyObject>;
and all the proper typemaps will be used.
*/
namespace swig {
%ignore SwigPtr_PyObject;
struct SwigPtr_PyObject {};
%apply PyObject * {SwigPtr_PyObject};
%apply PyObject * const& {SwigPtr_PyObject const&};
%typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);";
/* For output */
%typemap(out,noblock=1) SwigPtr_PyObject {
$result = (PyObject *)$1;
Py_INCREF($result);
}
%typemap(out,noblock=1) SwigPtr_PyObject const & {
$result = (PyObject *)*$1;
Py_INCREF($result);
}
}
%{
namespace swig {
class SwigPtr_PyObject {
protected:
PyObject *_obj;
public:
SwigPtr_PyObject() :_obj(0)
{
}
SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj)
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
Py_XINCREF(_obj);
SWIG_PYTHON_THREAD_END_BLOCK;
}
SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj)
{
if (initial_ref) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
Py_XINCREF(_obj);
SWIG_PYTHON_THREAD_END_BLOCK;
}
}
SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item)
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
Py_XINCREF(item._obj);
Py_XDECREF(_obj);
_obj = item._obj;
SWIG_PYTHON_THREAD_END_BLOCK;
return *this;
}
~SwigPtr_PyObject()
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
Py_XDECREF(_obj);
SWIG_PYTHON_THREAD_END_BLOCK;
}
operator PyObject *() const
{
return _obj;
}
PyObject *operator->() const
{
return _obj;
}
};
}
%}
/*
SwigVar_PyObject is used to manage 'in the scope' PyObject * variables,
as in
int func () {
SwigVar_PyObject obj = PyString_FromString("hello");
}
ie, 'obj' is created and destructed in the same scope from
a python object that carries at least one reference value.
SwigVar_PyObject just take care of applying the proper Py_DECREF.
Hence, this class is purely internal and not visible at the wrapped side.
*/
namespace swig {
%ignore SwigVar_PyObject;
struct SwigVar_PyObject {};
%apply PyObject * {SwigVar_PyObject};
%apply PyObject * const& {SwigVar_PyObject const&};
}
%{
namespace swig {
struct SwigVar_PyObject : SwigPtr_PyObject {
SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { }
SwigVar_PyObject & operator = (PyObject* obj)
{
Py_XDECREF(_obj);
_obj = obj;
return *this;
}
};
}
%}
#endif

View File

@@ -0,0 +1,86 @@
/*
Defines the As/From converters for double/float complex, you need to
provide complex Type, the Name you want to use in the converters,
the complex Constructor method, and the Real and Imag complex
accessor methods.
See the std_complex.i and ccomplex.i for concrete examples.
*/
/* the common from converter */
%define %swig_fromcplx_conv(Type, Real, Imag)
%fragment(SWIG_From_frag(Type),"header")
{
SWIGINTERNINLINE PyObject*
SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
{
return PyComplex_FromDoubles(Real(c), Imag(c));
}
}
%enddef
/* the double case */
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(double))
{
SWIGINTERN int
SWIG_AsVal(Type) (PyObject *o, Type* val)
{
if (PyComplex_Check(o)) {
if (val) *val = Constructor(PyComplex_RealAsDouble(o), PyComplex_ImagAsDouble(o));
return SWIG_OK;
} else {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
if (SWIG_IsOK(res)) {
if (val) *val = Constructor(d, 0.0);
return res;
}
}
return SWIG_TypeError;
}
}
%swig_fromcplx_conv(Type, Real, Imag);
%enddef
/* the float case */
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal(Type)(PyObject *o, Type *val)
{
if (PyComplex_Check(o)) {
double re = PyComplex_RealAsDouble(o);
double im = PyComplex_ImagAsDouble(o);
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
if (val) *val = Constructor(%numeric_cast(re, float),
%numeric_cast(im, float));
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
} else {
float re;
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
if (SWIG_IsOK(res)) {
if (val) *val = Constructor(re, 0.0);
return res;
}
}
return SWIG_TypeError;
}
}
%swig_fromcplx_conv(Type, Real, Imag);
%enddef
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
%swig_cplxflt_conv(Type, Constructor, Real, Imag)
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
// Documentation for use with the autodoc feature.
#ifdef SWIG_DOC_DOXYGEN_STYLE
%typemap(doc) SWIGTYPE "@param $1_name $1_type";
%typemap(doc) SWIGTYPE * "@param $1_name $1_type";
%typemap(doc) const SWIGTYPE & "@param $1_name $1_type";
%typemap(doc) const SWIGTYPE && "@param $1_name $1_type";
%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type";
%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "@param $1_name $1_type (input/output)";
%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "@param $1_name $1_type (input)";
%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "@param $1_name $1_type (output)";
#else
%typemap(doc) SWIGTYPE "$1_name: $1_type";
%typemap(doc) SWIGTYPE * "$1_name: $1_type";
%typemap(doc) const SWIGTYPE & "$1_name: $1_type";
%typemap(doc) const SWIGTYPE && "$1_name: $1_type";
%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type";
%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "$1_name: $1_type (input/output)";
%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "$1_name: $1_type (input)";
%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "$1_name: $1_type (output)";
#endif
// Types to use in Python documentation for the parameters of the given C++ type.
%typemap(doctype) bool "boolean";
%define int_doctype_for_cppint_type(cppint_type)
%typemap(doctype) cppint_type, unsigned cppint_type "int";
%enddef
%formacro(int_doctype_for_cppint_type, short, int, long, long long)
%typemap(doctype) size_t "int";
%typemap(doctype) enum SWIGTYPE "int";
%typemap(doctype) float, double, long double "float";
%typemap(doctype) char*, std::string "string";
%typemap(doctype) SWIGTYPE "$1_basetype"
%typemap(doctype) SWIGTYPE * "$typemap(doctype, $*1_ltype)"
%typemap(doctype) SWIGTYPE & "$typemap(doctype, $*1_ltype)"

View File

@@ -0,0 +1,104 @@
/* -----------------------------------------------------------------------------
* error manipulation
* ----------------------------------------------------------------------------- */
SWIGRUNTIME PyObject*
SWIG_Python_ErrorType(int code) {
PyObject* type = 0;
switch(code) {
case SWIG_MemoryError:
type = PyExc_MemoryError;
break;
case SWIG_IOError:
type = PyExc_IOError;
break;
case SWIG_RuntimeError:
type = PyExc_RuntimeError;
break;
case SWIG_IndexError:
type = PyExc_IndexError;
break;
case SWIG_TypeError:
type = PyExc_TypeError;
break;
case SWIG_DivisionByZero:
type = PyExc_ZeroDivisionError;
break;
case SWIG_OverflowError:
type = PyExc_OverflowError;
break;
case SWIG_SyntaxError:
type = PyExc_SyntaxError;
break;
case SWIG_ValueError:
type = PyExc_ValueError;
break;
case SWIG_SystemError:
type = PyExc_SystemError;
break;
case SWIG_AttributeError:
type = PyExc_AttributeError;
break;
default:
type = PyExc_RuntimeError;
}
return type;
}
SWIGRUNTIME void
SWIG_Python_AddErrorMsg(const char* mesg)
{
PyObject *type = 0;
PyObject *value = 0;
PyObject *traceback = 0;
if (PyErr_Occurred())
PyErr_Fetch(&type, &value, &traceback);
if (value) {
PyObject *old_str = PyObject_Str(value);
const char *tmp = SWIG_Python_str_AsChar(old_str);
PyErr_Clear();
Py_XINCREF(type);
if (tmp)
PyErr_Format(type, "%s %s", tmp, mesg);
else
PyErr_Format(type, "%s", mesg);
SWIG_Python_str_DelForPy3(tmp);
Py_DECREF(old_str);
Py_DECREF(value);
} else {
PyErr_SetString(PyExc_RuntimeError, mesg);
}
}
SWIGRUNTIME int
SWIG_Python_TypeErrorOccurred(PyObject *obj)
{
PyObject *error;
if (obj)
return 0;
error = PyErr_Occurred();
return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError);
}
SWIGRUNTIME void
SWIG_Python_RaiseOrModifyTypeError(const char *message)
{
if (SWIG_Python_TypeErrorOccurred(NULL)) {
/* Use existing TypeError to preserve stacktrace and enhance with given message */
PyObject *newvalue;
PyObject *type = NULL, *value = NULL, *traceback = NULL;
PyErr_Fetch(&type, &value, &traceback);
#if PY_VERSION_HEX >= 0x03000000
newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message);
#else
newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message);
#endif
Py_XDECREF(value);
PyErr_Restore(type, newvalue, traceback);
} else {
/* Raise TypeError using given message */
PyErr_SetString(PyExc_TypeError, message);
}
}

View File

@@ -0,0 +1,23 @@
/*
Create a file with this name, 'pyfragments.swg', in your working
directory and add all the %fragments you want to take precedence
over the default ones defined 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.
*/

View File

@@ -0,0 +1,87 @@
/* Compatibility macros for Python 3 */
#if PY_VERSION_HEX >= 0x03000000
#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
#define PyInt_Check(x) PyLong_Check(x)
#define PyInt_AsLong(x) PyLong_AsLong(x)
#define PyInt_FromLong(x) PyLong_FromLong(x)
#define PyInt_FromSize_t(x) PyLong_FromSize_t(x)
#define PyString_Check(name) PyBytes_Check(name)
#define PyString_FromString(x) PyUnicode_FromString(x)
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
#define PyString_AsString(str) PyBytes_AsString(str)
#define PyString_Size(str) PyBytes_Size(str)
#define PyString_InternFromString(key) PyUnicode_InternFromString(key)
#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
#endif
#ifndef Py_TYPE
# define Py_TYPE(op) ((op)->ob_type)
#endif
/* SWIG APIs for compatibility of both Python 2 & 3 */
#if PY_VERSION_HEX >= 0x03000000
# define SWIG_Python_str_FromFormat PyUnicode_FromFormat
#else
# define SWIG_Python_str_FromFormat PyString_FromFormat
#endif
/* Warning: This function will allocate a new string in Python 3,
* so please call SWIG_Python_str_DelForPy3(x) to free the space.
*/
SWIGINTERN char*
SWIG_Python_str_AsChar(PyObject *str)
{
#if PY_VERSION_HEX >= 0x03000000
char *newstr = 0;
str = PyUnicode_AsUTF8String(str);
if (str) {
char *cstr;
Py_ssize_t len;
PyBytes_AsStringAndSize(str, &cstr, &len);
newstr = (char *) malloc(len+1);
memcpy(newstr, cstr, len+1);
Py_XDECREF(str);
}
return newstr;
#else
return PyString_AsString(str);
#endif
}
#if PY_VERSION_HEX >= 0x03000000
# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
#else
# define SWIG_Python_str_DelForPy3(x)
#endif
SWIGINTERN PyObject*
SWIG_Python_str_FromChar(const char *c)
{
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromString(c);
#else
return PyString_FromString(c);
#endif
}
#ifndef PyObject_DEL
# define PyObject_DEL PyObject_Del
#endif
// SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user
// interface files check for it.
# define SWIGPY_USE_CAPSULE
# define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
#define Py_hash_t long
#endif

View File

@@ -0,0 +1,512 @@
/* ------------------------------------------------------------
* The start of the Python initialization function
* ------------------------------------------------------------ */
%insert(init) "swiginit.swg"
#if defined(SWIGPYTHON_BUILTIN)
%fragment("<stddef.h>"); // For offsetof
#endif
%insert(runtime) %{
#ifdef __cplusplus
extern "C" {
#endif
/* Method creation and docstring support functions */
SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name);
SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func);
SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func);
#ifdef __cplusplus
}
#endif
%}
%init %{
#ifdef __cplusplus
extern "C" {
#endif
/* Python-specific SWIG API */
#define SWIG_newvarlink() SWIG_Python_newvarlink()
#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr)
#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
/* -----------------------------------------------------------------------------
* global variable support code.
* ----------------------------------------------------------------------------- */
typedef struct swig_globalvar {
char *name; /* Name of global variable */
PyObject *(*get_attr)(void); /* Return the current value */
int (*set_attr)(PyObject *); /* Set the value */
struct swig_globalvar *next;
} swig_globalvar;
typedef struct swig_varlinkobject {
PyObject_HEAD
swig_globalvar *vars;
} swig_varlinkobject;
SWIGINTERN PyObject *
swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_InternFromString("<Swig global variables>");
#else
return PyString_FromString("<Swig global variables>");
#endif
}
SWIGINTERN PyObject *
swig_varlink_str(swig_varlinkobject *v) {
#if PY_VERSION_HEX >= 0x03000000
PyObject *str = PyUnicode_InternFromString("(");
PyObject *tail;
PyObject *joined;
swig_globalvar *var;
for (var = v->vars; var; var=var->next) {
tail = PyUnicode_FromString(var->name);
joined = PyUnicode_Concat(str, tail);
Py_DecRef(str);
Py_DecRef(tail);
str = joined;
if (var->next) {
tail = PyUnicode_InternFromString(", ");
joined = PyUnicode_Concat(str, tail);
Py_DecRef(str);
Py_DecRef(tail);
str = joined;
}
}
tail = PyUnicode_InternFromString(")");
joined = PyUnicode_Concat(str, tail);
Py_DecRef(str);
Py_DecRef(tail);
str = joined;
#else
PyObject *str = PyString_FromString("(");
swig_globalvar *var;
for (var = v->vars; var; var=var->next) {
PyString_ConcatAndDel(&str,PyString_FromString(var->name));
if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", "));
}
PyString_ConcatAndDel(&str,PyString_FromString(")"));
#endif
return str;
}
SWIGINTERN void
swig_varlink_dealloc(swig_varlinkobject *v) {
swig_globalvar *var = v->vars;
while (var) {
swig_globalvar *n = var->next;
free(var->name);
free(var);
var = n;
}
}
SWIGINTERN PyObject *
swig_varlink_getattr(swig_varlinkobject *v, char *n) {
PyObject *res = NULL;
swig_globalvar *var = v->vars;
while (var) {
if (strcmp(var->name,n) == 0) {
res = (*var->get_attr)();
break;
}
var = var->next;
}
if (res == NULL && !PyErr_Occurred()) {
PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
}
return res;
}
SWIGINTERN int
swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
int res = 1;
swig_globalvar *var = v->vars;
while (var) {
if (strcmp(var->name,n) == 0) {
res = (*var->set_attr)(p);
break;
}
var = var->next;
}
if (res == 1 && !PyErr_Occurred()) {
PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
}
return res;
}
SWIGINTERN PyTypeObject*
swig_varlink_type(void) {
static char varlink__doc__[] = "Swig var link object";
static PyTypeObject varlink_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
#endif
"swigvarlink", /* tp_name */
sizeof(swig_varlinkobject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor) swig_varlink_dealloc, /* tp_dealloc */
0, /* tp_print */
(getattrfunc) swig_varlink_getattr, /* tp_getattr */
(setattrfunc) swig_varlink_setattr, /* tp_setattr */
0, /* tp_compare */
(reprfunc) swig_varlink_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc) swig_varlink_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
0, /* tp_flags */
varlink__doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
0, /* tp_del */
0, /* tp_version_tag */
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
0, /* tp_prev */
0 /* tp_next */
#endif
};
varlink_type = tmp;
type_init = 1;
if (PyType_Ready(&varlink_type) < 0)
return NULL;
}
return &varlink_type;
}
/* Create a variable linking object for use later */
SWIGINTERN PyObject *
SWIG_Python_newvarlink(void) {
swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
if (result) {
result->vars = 0;
}
return ((PyObject*) result);
}
SWIGINTERN void
SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
swig_varlinkobject *v = (swig_varlinkobject *) p;
swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
if (gv) {
size_t size = strlen(name)+1;
gv->name = (char *)malloc(size);
if (gv->name) {
memcpy(gv->name, name, size);
gv->get_attr = get_attr;
gv->set_attr = set_attr;
gv->next = v->vars;
}
}
v->vars = gv;
}
SWIGINTERN PyObject *
SWIG_globals(void) {
static PyObject *globals = 0;
if (!globals) {
globals = SWIG_newvarlink();
}
return globals;
}
/* -----------------------------------------------------------------------------
* constants/methods manipulation
* ----------------------------------------------------------------------------- */
/* Install Constants */
SWIGINTERN void
SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
PyObject *obj = 0;
size_t i;
for (i = 0; constants[i].type; ++i) {
switch(constants[i].type) {
case SWIG_PY_POINTER:
obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
break;
case SWIG_PY_BINARY:
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
break;
default:
obj = 0;
break;
}
if (obj) {
PyDict_SetItemString(d, constants[i].name, obj);
Py_DECREF(obj);
}
}
}
/* -----------------------------------------------------------------------------*/
/* Fix SwigMethods to carry the callback ptrs when needed */
/* -----------------------------------------------------------------------------*/
SWIGINTERN void
SWIG_Python_FixMethods(PyMethodDef *methods,
swig_const_info *const_table,
swig_type_info **types,
swig_type_info **types_initial) {
size_t i;
for (i = 0; methods[i].ml_name; ++i) {
const char *c = methods[i].ml_doc;
if (!c) continue;
c = strstr(c, "swig_ptr: ");
if (c) {
int j;
swig_const_info *ci = 0;
const char *name = c + 10;
for (j = 0; const_table[j].type; ++j) {
if (strncmp(const_table[j].name, name,
strlen(const_table[j].name)) == 0) {
ci = &(const_table[j]);
break;
}
}
if (ci) {
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
if (ptr) {
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
memcpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
memcpy(buff, "swig_ptr: ", 10);
buff += 10;
SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
methods[i].ml_doc = ndoc;
}
}
}
}
}
}
/* -----------------------------------------------------------------------------
* Method creation and docstring support functions
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Function to find the method definition with the correct docstring for the
* proxy module as opposed to the low-level API
* ----------------------------------------------------------------------------- */
SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name) {
/* Find the function in the modified method table */
size_t offset = 0;
int found = 0;
while (SwigMethods_proxydocs[offset].ml_meth != NULL) {
if (strcmp(SwigMethods_proxydocs[offset].ml_name, name) == 0) {
found = 1;
break;
}
offset++;
}
/* Use the copy with the modified docstring if available */
return found ? &SwigMethods_proxydocs[offset] : NULL;
}
/* -----------------------------------------------------------------------------
* Wrapper of PyInstanceMethod_New() used in Python 3
* It is exported to the generated module, used for -fastproxy
* ----------------------------------------------------------------------------- */
SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
if (PyCFunction_Check(func)) {
PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
if (ml)
func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
}
#if PY_VERSION_HEX >= 0x03000000
return PyInstanceMethod_New(func);
#else
return PyMethod_New(func, NULL, NULL);
#endif
}
/* -----------------------------------------------------------------------------
* Wrapper of PyStaticMethod_New()
* It is exported to the generated module, used for -fastproxy
* ----------------------------------------------------------------------------- */
SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
if (PyCFunction_Check(func)) {
PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
if (ml)
func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
}
return PyStaticMethod_New(func);
}
#ifdef __cplusplus
}
#endif
/* -----------------------------------------------------------------------------*
* Partial Init method
* -----------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT
#if PY_VERSION_HEX >= 0x03000000
PyObject*
#else
void
#endif
SWIG_init(void) {
PyObject *m, *d, *md, *globals;
#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef SWIG_module = {
PyModuleDef_HEAD_INIT,
SWIG_name,
NULL,
-1,
SwigMethods,
NULL,
NULL,
NULL,
NULL
};
#endif
#if defined(SWIGPYTHON_BUILTIN)
static SwigPyClientData SwigPyObject_clientdata = {0, 0, 0, 0, 0, 0, 0};
static PyGetSetDef this_getset_def = {
(char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
};
static SwigPyGetSet thisown_getset_closure = {
SwigPyObject_own,
SwigPyObject_own
};
static PyGetSetDef thisown_getset_def = {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
};
PyTypeObject *builtin_pytype;
int builtin_base_count;
swig_type_info *builtin_basetype;
PyObject *tuple;
PyGetSetDescrObject *static_getset;
PyTypeObject *metatype;
PyTypeObject *swigpyobject;
SwigPyClientData *cd;
PyObject *public_interface, *public_symbol;
PyObject *this_descr;
PyObject *thisown_descr;
PyObject *self = 0;
int i;
(void)builtin_pytype;
(void)builtin_base_count;
(void)builtin_basetype;
(void)tuple;
(void)static_getset;
(void)self;
/* Metaclass is used to implement static member variables */
metatype = SwigPyObjectType();
assert(metatype);
#endif
(void)globals;
/* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */
SWIG_This();
SWIG_Python_TypeCache();
SwigPyPacked_type();
#ifndef SWIGPYTHON_BUILTIN
SwigPyObject_type();
#endif
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
#if PY_VERSION_HEX >= 0x03000000
m = PyModule_Create(&SWIG_module);
#else
m = Py_InitModule(SWIG_name, SwigMethods);
#endif
md = d = PyModule_GetDict(m);
(void)md;
SWIG_InitializeModule(0);
#ifdef SWIGPYTHON_BUILTIN
swigpyobject = SwigPyObject_TypeOnce();
SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
assert(SwigPyObject_stype);
cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
if (!cd) {
SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
SwigPyObject_clientdata.pytype = swigpyobject;
} else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) {
PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
# if PY_VERSION_HEX >= 0x03000000
return NULL;
# else
return;
# endif
}
/* All objects have a 'this' attribute */
this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
(void)this_descr;
/* All objects have a 'thisown' attribute */
thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
(void)thisown_descr;
public_interface = PyList_New(0);
public_symbol = 0;
(void)public_symbol;
PyDict_SetItemString(md, "__all__", public_interface);
Py_DECREF(public_interface);
for (i = 0; SwigMethods[i].ml_name != NULL; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name);
for (i = 0; swig_const_table[i].name != 0; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name);
#endif
SWIG_InstallConstants(d,swig_const_table);
%}

View File

@@ -0,0 +1,458 @@
/* -----------------------------------------------------------------------------
* pyiterators.swg
*
* Implement a python 'output' iterator for Python 2.2 or higher.
*
* Users can derive form the SwigPyIterator to implement their
* own iterators. As an example (real one since we use it for STL/STD
* containers), the template SwigPyIterator_T does the
* implementation for generic C++ iterators.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%fragment("SwigPyIterator","header",fragment="<stddef.h>") {
namespace swig {
struct stop_iteration {
};
struct SwigPyIterator {
private:
SwigPtr_PyObject _seq;
protected:
SwigPyIterator(PyObject *seq) : _seq(seq)
{
}
public:
virtual ~SwigPyIterator() {}
// Access iterator method, required by Python
virtual PyObject *value() const = 0;
// Forward iterator method, required by Python
virtual SwigPyIterator *incr(size_t n = 1) = 0;
// Backward iterator method, very common in C++, but not required in Python
virtual SwigPyIterator *decr(size_t /*n*/ = 1)
{
throw stop_iteration();
}
// Random access iterator methods, but not required in Python
virtual ptrdiff_t distance(const SwigPyIterator &/*x*/) const
{
throw std::invalid_argument("operation not supported");
}
virtual bool equal (const SwigPyIterator &/*x*/) const
{
throw std::invalid_argument("operation not supported");
}
// C++ common/needed methods
virtual SwigPyIterator *copy() const = 0;
PyObject *next()
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
PyObject *obj = value();
incr();
SWIG_PYTHON_THREAD_END_BLOCK; // re-enable threads
return obj;
}
/* Make an alias for Python 3.x */
PyObject *__next__()
{
return next();
}
PyObject *previous()
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
decr();
PyObject *obj = value();
SWIG_PYTHON_THREAD_END_BLOCK; // re-enable threads
return obj;
}
SwigPyIterator *advance(ptrdiff_t n)
{
return (n > 0) ? incr(n) : decr(-n);
}
bool operator == (const SwigPyIterator& x) const
{
return equal(x);
}
bool operator != (const SwigPyIterator& x) const
{
return ! operator==(x);
}
SwigPyIterator& operator += (ptrdiff_t n)
{
return *advance(n);
}
SwigPyIterator& operator -= (ptrdiff_t n)
{
return *advance(-n);
}
SwigPyIterator* operator + (ptrdiff_t n) const
{
return copy()->advance(n);
}
SwigPyIterator* operator - (ptrdiff_t n) const
{
return copy()->advance(-n);
}
ptrdiff_t operator - (const SwigPyIterator& x) const
{
return x.distance(*this);
}
static swig_type_info* descriptor() {
static int init = 0;
static swig_type_info* desc = 0;
if (!init) {
desc = SWIG_TypeQuery("swig::SwigPyIterator *");
init = 1;
}
return desc;
}
};
%#if defined(SWIGPYTHON_BUILTIN)
inline PyObject* make_output_iterator_builtin (PyObject *pyself)
{
Py_INCREF(pyself);
return pyself;
}
%#endif
}
}
%fragment("SwigPyIterator_T","header",fragment="<stddef.h>",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
template<typename OutIterator>
class SwigPyIterator_T : public SwigPyIterator
{
public:
typedef OutIterator out_iterator;
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
typedef SwigPyIterator_T<out_iterator> self_type;
SwigPyIterator_T(out_iterator curr, PyObject *seq)
: SwigPyIterator(seq), current(curr)
{
}
const out_iterator& get_current() const
{
return current;
}
bool equal (const SwigPyIterator &iter) const
{
const self_type *iters = dynamic_cast<const self_type *>(&iter);
if (iters) {
return (current == iters->get_current());
} else {
throw std::invalid_argument("bad iterator type");
}
}
ptrdiff_t distance(const SwigPyIterator &iter) const
{
const self_type *iters = dynamic_cast<const self_type *>(&iter);
if (iters) {
return std::distance(current, iters->get_current());
} else {
throw std::invalid_argument("bad iterator type");
}
}
protected:
out_iterator current;
};
template <class ValueType>
struct from_oper
{
typedef const ValueType& argument_type;
typedef PyObject *result_type;
result_type operator()(argument_type v) const
{
return swig::from(v);
}
};
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SwigPyForwardIteratorOpen_T : public SwigPyIterator_T<OutIterator>
{
public:
FromOper from;
typedef OutIterator out_iterator;
typedef ValueType value_type;
typedef SwigPyIterator_T<out_iterator> base;
typedef SwigPyForwardIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
SwigPyForwardIteratorOpen_T(out_iterator curr, PyObject *seq)
: SwigPyIterator_T<OutIterator>(curr, seq)
{
}
PyObject *value() const {
return from(static_cast<const value_type&>(*(base::current)));
}
SwigPyIterator *copy() const
{
return new self_type(*this);
}
SwigPyIterator *incr(size_t n = 1)
{
while (n--) {
++base::current;
}
return this;
}
};
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SwigPyIteratorOpen_T : public SwigPyForwardIteratorOpen_T<OutIterator, ValueType, FromOper>
{
public:
FromOper from;
typedef OutIterator out_iterator;
typedef ValueType value_type;
typedef SwigPyIterator_T<out_iterator> base;
typedef SwigPyIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
SwigPyIteratorOpen_T(out_iterator curr, PyObject *seq)
: SwigPyForwardIteratorOpen_T<OutIterator>(curr, seq)
{
}
SwigPyIterator *decr(size_t n = 1)
{
while (n--) {
--base::current;
}
return this;
}
};
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SwigPyForwardIteratorClosed_T : public SwigPyIterator_T<OutIterator>
{
public:
FromOper from;
typedef OutIterator out_iterator;
typedef ValueType value_type;
typedef SwigPyIterator_T<out_iterator> base;
typedef SwigPyForwardIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
SwigPyForwardIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, PyObject *seq)
: SwigPyIterator_T<OutIterator>(curr, seq), begin(first), end(last)
{
}
PyObject *value() const {
if (base::current == end) {
throw stop_iteration();
} else {
return from(static_cast<const value_type&>(*(base::current)));
}
}
SwigPyIterator *copy() const
{
return new self_type(*this);
}
SwigPyIterator *incr(size_t n = 1)
{
while (n--) {
if (base::current == end) {
throw stop_iteration();
} else {
++base::current;
}
}
return this;
}
protected:
out_iterator begin;
out_iterator end;
};
template<typename OutIterator,
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
typename FromOper = from_oper<ValueType> >
class SwigPyIteratorClosed_T : public SwigPyForwardIteratorClosed_T<OutIterator,ValueType,FromOper>
{
public:
FromOper from;
typedef OutIterator out_iterator;
typedef ValueType value_type;
typedef SwigPyIterator_T<out_iterator> base;
typedef SwigPyForwardIteratorClosed_T<OutIterator, ValueType, FromOper> base0;
typedef SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
SwigPyIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, PyObject *seq)
: SwigPyForwardIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
{
}
SwigPyIterator *decr(size_t n = 1)
{
while (n--) {
if (base::current == base0::begin) {
throw stop_iteration();
} else {
--base::current;
}
}
return this;
}
};
template<typename OutIter>
inline SwigPyIterator*
make_output_forward_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, PyObject *seq = 0)
{
return new SwigPyForwardIteratorClosed_T<OutIter>(current, begin, end, seq);
}
template<typename OutIter>
inline SwigPyIterator*
make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, PyObject *seq = 0)
{
return new SwigPyIteratorClosed_T<OutIter>(current, begin, end, seq);
}
template<typename OutIter>
inline SwigPyIterator*
make_output_forward_iterator(const OutIter& current, PyObject *seq = 0)
{
return new SwigPyForwardIteratorOpen_T<OutIter>(current, seq);
}
template<typename OutIter>
inline SwigPyIterator*
make_output_iterator(const OutIter& current, PyObject *seq = 0)
{
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
}
}
}
%fragment("SwigPyIterator");
namespace swig
{
/*
Throw a StopIteration exception
*/
%ignore stop_iteration;
struct stop_iteration {};
%typemap(throws) stop_iteration {
(void)$1;
SWIG_SetErrorObj(PyExc_StopIteration, SWIG_Py_Void());
SWIG_fail;
}
/*
Mark methods that return new objects
*/
%newobject SwigPyIterator::copy;
%newobject SwigPyIterator::operator + (ptrdiff_t n) const;
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
%nodirector SwigPyIterator;
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
%feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
#else
%extend SwigPyIterator {
%pythoncode %{def __iter__(self):
return self%}
}
#endif
%catches(swig::stop_iteration) SwigPyIterator::value() const;
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
%catches(swig::stop_iteration) SwigPyIterator::decr(size_t n = 1);
%catches(std::invalid_argument) SwigPyIterator::distance(const SwigPyIterator &x) const;
%catches(std::invalid_argument) SwigPyIterator::equal (const SwigPyIterator &x) const;
%catches(swig::stop_iteration) SwigPyIterator::__next__();
%catches(swig::stop_iteration) SwigPyIterator::next();
%catches(swig::stop_iteration) SwigPyIterator::previous();
%catches(swig::stop_iteration) SwigPyIterator::advance(ptrdiff_t n);
%catches(swig::stop_iteration) SwigPyIterator::operator += (ptrdiff_t n);
%catches(swig::stop_iteration) SwigPyIterator::operator -= (ptrdiff_t n);
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
struct SwigPyIterator
{
protected:
SwigPyIterator(PyObject *seq);
public:
virtual ~SwigPyIterator();
// Access iterator method, required by Python
virtual PyObject *value() const = 0;
// Forward iterator method, required by Python
virtual SwigPyIterator *incr(size_t n = 1) = 0;
// Backward iterator method, very common in C++, but not required in Python
virtual SwigPyIterator *decr(size_t n = 1);
// Random access iterator methods, but not required in Python
virtual ptrdiff_t distance(const SwigPyIterator &x) const;
virtual bool equal (const SwigPyIterator &x) const;
// C++ common/needed methods
virtual SwigPyIterator *copy() const = 0;
PyObject *next();
PyObject *__next__();
PyObject *previous();
SwigPyIterator *advance(ptrdiff_t n);
bool operator == (const SwigPyIterator& x) const;
bool operator != (const SwigPyIterator& x) const;
SwigPyIterator& operator += (ptrdiff_t n);
SwigPyIterator& operator -= (ptrdiff_t n);
SwigPyIterator* operator + (ptrdiff_t n) const;
SwigPyIterator* operator - (ptrdiff_t n) const;
ptrdiff_t operator - (const SwigPyIterator& x) const;
};
}

View File

@@ -0,0 +1,4 @@
%include <typemaps/swigmacros.swg>

View File

@@ -0,0 +1,85 @@
/*
* From SWIG 1.3.37 we deprecated all SWIG symbols that start with Py,
* since they are inappropriate and discouraged in Python documentation
* (from http://www.python.org/doc/2.5.2/api/includes.html):
*
* "All user visible names defined by Python.h (except those defined by the included
* standard headers) have one of the prefixes "Py" or "_Py". Names beginning with
* "_Py" are for internal use by the Python implementation and should not be used
* by extension writers. Structure member names do not have a reserved prefix.
*
* Important: user code should never define names that begin with "Py" or "_Py".
* This confuses the reader, and jeopardizes the portability of the user code to
* future Python versions, which may define additional names beginning with one
* of these prefixes."
*
* This file defined macros to provide backward compatibility for these deprecated
* symbols. In the case you have these symbols in your interface file, you can simply
* include this file at beginning of it.
*
* However, this file may be removed in future release of SWIG, so using this file to
* keep these inappropriate names in your SWIG interface file is also not recommended.
* Instead, we provide a simple tool for converting your interface files to
* the new naming convention. You can get the tool from the SWIG distribution:
* Tools/pyname_patch.py
*/
%fragment("PySequence_Base", "header", fragment="SwigPySequence_Base") {}
%fragment("PySequence_Cont", "header", fragment="SwigPySequence_Cont") {}
%fragment("PySwigIterator_T", "header", fragment="SwigPyIterator_T") {}
%fragment("PyPairBoolOutputIterator", "header", fragment="SwigPyPairBoolOutputIterator") {}
%fragment("PySwigIterator", "header", fragment="SwigPyIterator") {}
%fragment("PySwigIterator_T", "header", fragment="SwigPyIterator_T") {}
%inline %{
#define PyMapIterator_T SwigPyMapIterator_T
#define PyMapKeyIterator_T SwigPyMapKeyIterator_T
#define PyMapValueIterator_T SwigPyMapValueIterator_T
#define PyObject_ptr SwigPtr_PyObject
#define PyObject_var SwigVar_PyObject
#define PyOper SwigPyOper
#define PySeq SwigPySeq
#define PySequence_ArrowProxy SwigPySequence_ArrowProxy
#define PySequence_Cont SwigPySequence_Cont
#define PySequence_InputIterator SwigPySequence_InputIterator
#define PySequence_Ref SwigPySequence_Ref
#define PySwigClientData SwigPyClientData
#define PySwigClientData_Del SwigPyClientData_Del
#define PySwigClientData_New SwigPyClientData_New
#define PySwigIterator SwigPyIterator
#define PySwigIteratorClosed_T SwigPyIteratorClosed_T
#define PySwigIteratorOpen_T SwigPyIteratorOpen_T
#define PySwigIterator_T SwigPyIterator_T
#define PySwigObject SwigPyObject
#define PySwigObject_Check SwigPyObject_Check
#define PySwigObject_GetDesc SwigPyObject_GetDesc
#define PySwigObject_New SwigPyObject_New
#define PySwigObject_acquire SwigPyObject_acquire
#define PySwigObject_append SwigPyObject_append
#define PySwigObject_as_number SwigPyObject_as_number
#define PySwigObject_compare SwigPyObject_compare
#define PySwigObject_dealloc SwigPyObject_dealloc
#define PySwigObject_disown SwigPyObject_disown
#define PySwigObject_format SwigPyObject_format
#define PySwigObject_getattr SwigPyObject_getattr
#define PySwigObject_hex SwigPyObject_hex
#define PySwigObject_long SwigPyObject_long
#define PySwigObject_next SwigPyObject_next
#define PySwigObject_oct SwigPyObject_oct
#define PySwigObject_own SwigPyObject_own
#define PySwigObject_repr SwigPyObject_repr
#define PySwigObject_richcompare SwigPyObject_richcompare
#define PySwigObject_type SwigPyObject_type
#define PySwigPacked SwigPyPacked
#define PySwigPacked_Check SwigPyPacked_Check
#define PySwigPacked_New SwigPyPacked_New
#define PySwigPacked_UnpackData SwigPyPacked_UnpackData
#define PySwigPacked_compare SwigPyPacked_compare
#define PySwigPacked_dealloc SwigPyPacked_dealloc
#define PySwigPacked_repr SwigPyPacked_repr
#define PySwigPacked_str SwigPyPacked_str
#define PySwigPacked_type SwigPyPacked_type
#define pyseq swigpyseq
#define pyswigobject_type swigpyobject_type
#define pyswigpacked_type swigpypacked_type
%}

View File

@@ -0,0 +1,264 @@
/* ------------------------------------------------------------
* Overloaded operator support
The directives in this file apply whether or not you use the
-builtin option to SWIG, but operator overloads are particularly
attractive when using -builtin, because they are much faster
than named methods.
If you're using the -builtin option to SWIG, and you want to define
python operator overloads beyond the defaults defined in this file,
here's what you need to know:
There are two ways to define a python slot function: dispatch to a
statically defined function; or dispatch to a method defined on the
operand.
To dispatch to a statically defined function, use %feature("python:<slot>"),
where <slot> is the name of a field in a PyTypeObject, PyNumberMethods,
PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example:
%feature("python:tp_hash") MyClass "myHashFunc";
class MyClass {
public:
...
};
%{
// Note: Py_hash_t was introduced in Python 3.2
static Py_hash_t myHashFunc(PyObject *pyobj) {
MyClass *cobj;
// Convert pyobj to cobj
return (cobj->field1 * (cobj->field2 << 7));
}
%}
NOTE: It is the responsibility of the programmer (that's you) to ensure
that a statically defined slot function has the correct signature.
If, instead, you want to dispatch to an instance method, you can
use %feature("python:slot"). For example:
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
class MyClass {
public:
Py_hash_t myHashFunc () const;
...
};
NOTE: Some python slots use a method signature which does not
match the signature of SWIG-wrapped methods. For those slots,
SWIG will automatically generate a "closure" function to re-marshall
the arguments before dispatching to the wrapped method. Setting
the "functype" attribute of the feature enables SWIG to generate
a correct closure function.
--------------------------------------------------------------
The tp_richcompare slot is a special case: SWIG automatically generates
a rich compare function for all wrapped types. If a type defines C++
operator overloads for comparison (operator==, operator<, etc.), they
will be called from the generated rich compare function. If you
want to explicitly choose a method to handle a certain comparison
operation, you may use a different feature, %feature("python:compare")
like this:
%feature("python:compare", "Py_LT") MyClass::lessThan;
class MyClass {
public:
bool lessThan(const MyClass& other) const;
...
};
... where "Py_LT" is one of the rich comparison opcodes defined in the
python header file object.h.
If there's no method defined to handle a particular comparison operation,
the default behavior is to compare pointer values of the wrapped
C++ objects.
--------------------------------------------------------------
For more information about python slots, including their names and
signatures, you may refer to the python documentation :
http://docs.python.org/c-api/typeobj.html
* ------------------------------------------------------------ */
#ifdef __cplusplus
#if defined(SWIGPYTHON_BUILTIN)
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:slot", #slt, functype=#functp) oper; %feature("python:slot", #slt, functype=#functp) pyname;
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:compare", #comptype) oper; %feature("python:compare", #comptype) pyname;
#else
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
#endif
%pybinoperator(__add__, *::operator+, binaryfunc, nb_add);
%pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive);
%pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive);
%pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract);
%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
%pybinoperator(__and__, *::operator&, binaryfunc, nb_and);
%pybinoperator(__or__, *::operator|, binaryfunc, nb_or);
%pybinoperator(__xor__, *::operator^, binaryfunc, nb_xor);
%pycompare(__lt__, *::operator<, Py_LT);
%pycompare(__le__, *::operator<=, Py_LE);
%pycompare(__gt__, *::operator>, Py_GT);
%pycompare(__ge__, *::operator>=, Py_GE);
%pycompare(__eq__, *::operator==, Py_EQ);
%pycompare(__ne__, *::operator!=, Py_NE);
/* Special cases */
%rename(__invert__) *::operator~;
%feature("python:slot", "nb_invert", functype="unaryfunc") *::operator~;
%rename(__call__) *::operator();
%feature("python:slot", "tp_call", functype="ternarycallfunc") *::operator();
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero);
%pybinoperator(__truediv__, *::operator/ , binaryfunc, nb_divide);
#else
%feature("shadow") *::operator bool %{
def __nonzero__(self):
return $action(self)
__bool__ = __nonzero__
%};
%rename(__nonzero__) *::operator bool;
%feature("shadow") *::operator/ %{
def __truediv__(self, *args):
return $action(self, *args)
__div__ = __truediv__
%};
%rename(__truediv__) *::operator/;
%pythonmaybecall *::operator/;
#endif
/* Ignored operators */
%ignoreoperator(LNOT) operator!;
%ignoreoperator(LAND) operator&&;
%ignoreoperator(LOR) operator||;
%ignoreoperator(EQ) *::operator=;
%ignoreoperator(PLUSPLUS) *::operator++;
%ignoreoperator(MINUSMINUS) *::operator--;
%ignoreoperator(ARROWSTAR) *::operator->*;
%ignoreoperator(INDEX) *::operator[];
/*
Inplace operator declarations.
They translate the inplace C++ operators (+=, -=, ...) into the
corresponding python equivalents(__iadd__,__isub__), etc,
disabling the ownership of the input 'this' pointer, and assigning
it to the returning object:
%feature("del") *::Operator; // disables ownership by generating SWIG_POINTER_DISOWN
%feature("new") *::Operator; // claims ownership by generating SWIG_POINTER_OWN
This makes the most common case safe, ie:
A& A::operator+=(int i) { ...; return *this; }
^^^^ ^^^^^^
will work fine, even when the resulting python object shares the
'this' pointer with the input one. The input object is usually
deleted after the operation, including the shared 'this' pointer,
producing 'strange' seg faults, as reported by Lucriz
(lucriz@sitilandia.it).
If you have an interface that already takes care of that, ie, you
already are using inplace operators and you are not getting
seg. faults, with the new scheme you could end with 'free' elements
that never get deleted (maybe, not sure, it depends). But if that is
the case, you could recover the old behaviour using
%feature("del","0") A::operator+=;
%feature("new","0") A::operator+=;
which recovers the old behaviour for the class 'A', or if you are
100% sure your entire system works fine in the old way, use:
%feature("del","") *::operator+=;
%feature("new","") *::operator+=;
The default behaviour assumes that the 'this' pointer's memory is
already owned by the SWIG object; it relinquishes ownership then
takes it back. This may not be the case though as the SWIG object
might be owned by memory managed elsewhere, eg after calling a
function that returns a C++ reference. In such case you will need
to use the features above to recover the old behaviour too.
*/
#if defined(SWIGPYTHON_BUILTIN)
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %feature("python:slot", #slt, functype=#functp) Oper; %rename(SwigPyOper) Oper
#else
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#endif
%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
%pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor);
%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
/* Special cases */
#if defined(SWIGPYTHON_BUILTIN)
%pyinplaceoper(__itruediv__ , *::operator /=, binaryfunc, nb_inplace_divide);
#else
%delobject *::operator /=;
%newobject *::operator /=;
%feature("shadow") *::operator /= %{
def __itruediv__(self, *args):
return $action(self, *args)
__idiv__ = __itruediv__
%};
%rename(__itruediv__) *::operator /=;
#endif
/* Finally, in python we need to mark the binary operations to fail as
'maybecall' methods */
#define %pybinopermaybecall(oper) %pythonmaybecall __ ## oper ## __; %pythonmaybecall __r ## oper ## __
%pybinopermaybecall(add);
%pybinopermaybecall(pos);
%pybinopermaybecall(pos);
%pybinopermaybecall(sub);
%pybinopermaybecall(neg);
%pybinopermaybecall(neg);
%pybinopermaybecall(mul);
%pybinopermaybecall(div);
%pybinopermaybecall(truediv);
%pybinopermaybecall(mod);
%pybinopermaybecall(lshift);
%pybinopermaybecall(rshift);
%pybinopermaybecall(and);
%pybinopermaybecall(or);
%pybinopermaybecall(xor);
%pybinopermaybecall(lt);
%pybinopermaybecall(le);
%pybinopermaybecall(gt);
%pybinopermaybecall(ge);
%pybinopermaybecall(eq);
%pybinopermaybecall(ne);
#endif

View File

@@ -0,0 +1,353 @@
/* ------------------------------------------------------------
* Primitive Types
* ------------------------------------------------------------ */
/* boolean */
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(bool)(bool value)
{
return PyBool_FromLong(value ? 1 : 0);
}
}
#ifdef SWIG_PYTHON_LEGACY_BOOL
// Default prior to SWIG 3.0.0
%fragment(SWIG_AsVal_frag(bool),"header",
fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
{
int r = PyObject_IsTrue(obj);
if (r == -1)
return SWIG_ERROR;
if (val) *val = r ? true : false;
return SWIG_OK;
}
}
#else
%fragment(SWIG_AsVal_frag(bool),"header",
fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
{
int r;
if (!PyBool_Check(obj))
return SWIG_ERROR;
r = PyObject_IsTrue(obj);
if (r == -1)
return SWIG_ERROR;
if (val) *val = r ? true : false;
return SWIG_OK;
}
}
#endif
/* int */
%fragment(SWIG_From_frag(int),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(int)(int value)
{
return PyInt_FromLong((long) value);
}
}
/* unsigned int */
%fragment(SWIG_From_frag(unsigned int),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned int)(unsigned int value)
{
return PyInt_FromSize_t((size_t) value);
}
}
/* long */
%fragment(SWIG_From_frag(long),"header") {
%define_as(SWIG_From_dec(long), PyInt_FromLong)
}
%fragment(SWIG_AsVal_frag(long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(long)(PyObject *obj, long* val)
{
%#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj)) {
if (val) *val = PyInt_AsLong(obj);
return SWIG_OK;
} else
%#endif
if (PyLong_Check(obj)) {
long v = PyLong_AsLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
PyErr_Clear();
return SWIG_OverflowError;
}
}
%#ifdef SWIG_PYTHON_CAST_MODE
{
int dispatch = 0;
long v = PyInt_AsLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_AddCast(SWIG_OK);
} else {
PyErr_Clear();
}
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;
}
}
}
%#endif
return SWIG_TypeError;
}
}
/* unsigned long */
%fragment(SWIG_From_frag(unsigned long),"header",
fragment=SWIG_From_frag(long)) {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long)(unsigned long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
}
%fragment(SWIG_AsVal_frag(unsigned long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
{
%#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj)) {
long v = PyInt_AsLong(obj);
if (v >= 0) {
if (val) *val = v;
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
} else
%#endif
if (PyLong_Check(obj)) {
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
PyErr_Clear();
return SWIG_OverflowError;
}
}
%#ifdef SWIG_PYTHON_CAST_MODE
{
int dispatch = 0;
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_AddCast(SWIG_OK);
} else {
PyErr_Clear();
}
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;
}
}
}
%#endif
return SWIG_TypeError;
}
}
/* long long */
%fragment(SWIG_From_frag(long long),"header",
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERNINLINE PyObject*
SWIG_From_dec(long long)(long long value)
{
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
%#endif
}
%fragment(SWIG_AsVal_frag(long long),"header",
fragment=SWIG_AsVal_frag(long),
fragment="SWIG_CanCastAsInteger",
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERN int
SWIG_AsVal_dec(long long)(PyObject *obj, long long *val)
{
int res = SWIG_TypeError;
if (PyLong_Check(obj)) {
long long v = PyLong_AsLongLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
PyErr_Clear();
res = SWIG_OverflowError;
}
} else {
long v;
res = SWIG_AsVal(long)(obj,&v);
if (SWIG_IsOK(res)) {
if (val) *val = v;
return res;
}
}
%#ifdef SWIG_PYTHON_CAST_MODE
{
const double mant_max = 1LL << DBL_MANT_DIG;
const double mant_min = -mant_max;
double d;
res = SWIG_AsVal(double)(obj,&d);
if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, mant_min, mant_max))
return SWIG_OverflowError;
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) {
if (val) *val = (long long)(d);
return SWIG_AddCast(res);
}
res = SWIG_TypeError;
}
%#endif
return res;
}
%#endif
}
/* unsigned long long */
%fragment(SWIG_From_frag(unsigned long long),"header",
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
%#endif
}
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
fragment=SWIG_AsVal_frag(unsigned long),
fragment="SWIG_CanCastAsInteger",
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERN int
SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val)
{
int res = SWIG_TypeError;
if (PyLong_Check(obj)) {
unsigned long long v = PyLong_AsUnsignedLongLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
PyErr_Clear();
res = SWIG_OverflowError;
}
} else {
unsigned long v;
res = SWIG_AsVal(unsigned long)(obj,&v);
if (SWIG_IsOK(res)) {
if (val) *val = v;
return res;
}
}
%#ifdef SWIG_PYTHON_CAST_MODE
{
const double mant_max = 1LL << DBL_MANT_DIG;
double d;
res = SWIG_AsVal(double)(obj,&d);
if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max))
return SWIG_OverflowError;
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
if (val) *val = (unsigned long long)(d);
return SWIG_AddCast(res);
}
res = SWIG_TypeError;
}
%#endif
return res;
}
%#endif
}
/* double */
%fragment(SWIG_From_frag(double),"header") {
%define_as(SWIG_From_dec(double), PyFloat_FromDouble)
}
%fragment(SWIG_AsVal_frag(double),"header") {
SWIGINTERN int
SWIG_AsVal_dec(double)(PyObject *obj, double *val)
{
int res = SWIG_TypeError;
if (PyFloat_Check(obj)) {
if (val) *val = PyFloat_AsDouble(obj);
return SWIG_OK;
%#if PY_VERSION_HEX < 0x03000000
} else if (PyInt_Check(obj)) {
if (val) *val = (double) PyInt_AsLong(obj);
return SWIG_OK;
%#endif
} else if (PyLong_Check(obj)) {
double v = PyLong_AsDouble(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
PyErr_Clear();
}
}
%#ifdef SWIG_PYTHON_CAST_MODE
{
int dispatch = 0;
double d = PyFloat_AsDouble(obj);
if (!PyErr_Occurred()) {
if (val) *val = d;
return SWIG_AddCast(SWIG_OK);
} else {
PyErr_Clear();
}
if (!dispatch) {
long v = PyLong_AsLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
return SWIG_AddCast(SWIG_AddCast(SWIG_OK));
} else {
PyErr_Clear();
}
}
}
%#endif
return res;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
%insert(runtime) %{
#if defined(__GNUC__) && defined(_WIN32) && !defined(SWIG_PYTHON_NO_HYPOT_WORKAROUND)
/* Workaround for '::hypot' has not been declared', see https://bugs.python.org/issue11566 */
# include <math.h>
#endif
#if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)
/* Use debug wrappers with the Python release dll */
# undef _DEBUG
# include <Python.h>
# define _DEBUG 1
#else
# include <Python.h>
#endif
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */
%insert(runtime) "swigerrors.swg"; /* SWIG errors */
%insert(runtime) "pyhead.swg"; /* Python includes and fixes */
%insert(runtime) "pyerrors.swg"; /* Python errors */
%insert(runtime) "pythreads.swg"; /* Python thread code */
%insert(runtime) "pyapi.swg"; /* Python API */
%insert(runtime) "pyrun.swg"; /* Python run-time code */
#if defined(SWIGPYTHON_BUILTIN)
%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */
#endif

View File

@@ -0,0 +1,256 @@
%fragment("StdTraits","header",fragment="StdTraitsCommon")
{
namespace swig {
/*
Traits that provides the from method
*/
template <class Type> struct traits_from_ptr {
static PyObject *from(Type *val, int owner = 0) {
return SWIG_InternalNewPointerObj(val, type_info<Type>(), owner);
}
};
template <class Type> struct traits_from {
static PyObject *from(const Type& val) {
return traits_from_ptr<Type>::from(new Type(val), 1);
}
};
template <class Type> struct traits_from<Type *> {
static PyObject *from(Type* val) {
return traits_from_ptr<Type>::from(val, 0);
}
};
template <class Type> struct traits_from<const Type *> {
static PyObject *from(const Type* val) {
return traits_from_ptr<Type>::from(const_cast<Type*>(val), 0);
}
};
template <class Type>
inline PyObject *from(const Type& val) {
return traits_from<Type>::from(val);
}
template <class Type>
inline PyObject *from_ptr(Type* val, int owner) {
return traits_from_ptr<Type>::from(val, owner);
}
/*
Traits that provides the asval/as/check method
*/
template <class Type>
struct traits_asptr {
static int asptr(PyObject *obj, Type **val) {
Type *p = 0;
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
template <class Type>
inline int asptr(PyObject *obj, Type **vptr) {
return traits_asptr<Type>::asptr(obj, vptr);
}
template <class Type>
struct traits_asval {
static int asval(PyObject *obj, Type *val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (!SWIG_IsOK(res)) return res;
if (p) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = *p;
if (SWIG_IsNewObj(res)){
%delete(p);
res = SWIG_DelNewMask(res);
}
return res;
} else {
return SWIG_ERROR;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type> struct traits_asval<Type*> {
static int asval(PyObject *obj, Type **val) {
if (val) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
noconst_type *p = 0;
int res = traits_asptr<noconst_type>::asptr(obj, &p);
if (SWIG_IsOK(res)) {
*(const_cast<noconst_type**>(val)) = p;
}
return res;
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type>
inline int asval(PyObject *obj, Type *val) {
return traits_asval<Type>::asval(obj, val);
}
template <class Type>
struct traits_as<Type, value_category> {
static Type as(PyObject *obj) {
Type v;
int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) {
if (!PyErr_Occurred()) {
::%type_error(swig::type_name<Type>());
}
throw std::invalid_argument("bad type");
}
return v;
}
};
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(PyObject *obj) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res) && v) {
if (SWIG_IsNewObj(res)) {
Type r(*v);
%delete(v);
return r;
} else {
return *v;
}
} else {
if (!PyErr_Occurred()) {
%type_error(swig::type_name<Type>());
}
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
struct traits_as<Type*, pointer_category> {
static Type* as(PyObject *obj) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res)) {
return v;
} else {
if (!PyErr_Occurred()) {
%type_error(swig::type_name<Type>());
}
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
inline Type as(PyObject *obj) {
return traits_as<Type, typename traits<Type>::category>::as(obj);
}
template <class Type>
struct traits_check<Type, value_category> {
static bool check(PyObject *obj) {
int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR;
return SWIG_IsOK(res) ? true : false;
}
};
template <class Type>
struct traits_check<Type, pointer_category> {
static bool check(PyObject *obj) {
int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR;
return SWIG_IsOK(res) ? true : false;
}
};
template <class Type>
inline bool check(PyObject *obj) {
return traits_check<Type, typename traits<Type>::category>::check(obj);
}
}
}
//
// Backward compatibility
//
#ifdef SWIG_PYTHON_BACKWARD_COMP
%fragment("<string>");
%{
PyObject* SwigInt_FromBool(bool b) {
return PyInt_FromLong(b ? 1L : 0L);
}
double SwigNumber_Check(PyObject* o) {
return PyFloat_Check(o) || PyInt_Check(o) || PyLong_Check(o);
}
double SwigNumber_AsDouble(PyObject* o) {
return PyFloat_Check(o) ? PyFloat_AsDouble(o)
: (PyInt_Check(o) ? double(PyInt_AsLong(o))
: double(PyLong_AsLong(o)));
}
PyObject* SwigString_FromString(const std::string& s) {
return PyString_FromStringAndSize(s.data(),s.size());
}
std::string SwigString_AsString(PyObject* o) {
return std::string(PyString_AsString(o));
}
%}
#endif
%define %specialize_std_container(Type,Check,As,From)
%{
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(PyObject *obj, value_type *val) {
if (Check(obj)) {
if (val) *val = As(obj);
return SWIG_OK;
}
return SWIG_ERROR;
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static PyObject *from(const value_type& val) {
return From(val);
}
};
template <>
struct traits_check<Type, value_category> {
static int check(PyObject *obj) {
int res = Check(obj);
return obj && res ? res : 0;
}
};
}
%}
%enddef
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_unordered_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_unordered_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)

View File

@@ -0,0 +1,137 @@
/* ------------------------------------------------------------
* utility methods for char strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
SWIGINTERN int
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
{
%#if PY_VERSION_HEX>=0x03000000
%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
if (PyBytes_Check(obj))
%#else
if (PyUnicode_Check(obj))
%#endif
%#else
if (PyString_Check(obj))
%#endif
{
char *cstr; Py_ssize_t len;
int ret = SWIG_OK;
%#if PY_VERSION_HEX>=0x03000000
%#if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
if (!alloc && cptr) {
/* We can't allow converting without allocation, since the internal
representation of string in Python 3 is UCS-2/UCS-4 but we require
a UTF-8 representation.
TODO(bhy) More detailed explanation */
return SWIG_RuntimeError;
}
obj = PyUnicode_AsUTF8String(obj);
if (!obj)
return SWIG_TypeError;
if (alloc)
*alloc = SWIG_NEWOBJ;
%#endif
PyBytes_AsStringAndSize(obj, &cstr, &len);
%#else
PyString_AsStringAndSize(obj, &cstr, &len);
%#endif
if (cptr) {
if (alloc) {
if (*alloc == SWIG_NEWOBJ) {
*cptr = %new_copy_array(cstr, len + 1, char);
*alloc = SWIG_NEWOBJ;
} else {
*cptr = cstr;
*alloc = SWIG_OLDOBJ;
}
} else {
%#if PY_VERSION_HEX>=0x03000000
%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
*cptr = PyBytes_AsString(obj);
%#else
assert(0); /* Should never reach here with Unicode strings in Python 3 */
%#endif
%#else
*cptr = SWIG_Python_str_AsChar(obj);
if (!*cptr)
ret = SWIG_TypeError;
%#endif
}
}
if (psize) *psize = len + 1;
%#if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
Py_XDECREF(obj);
%#endif
return ret;
} else {
%#if defined(SWIG_PYTHON_2_UNICODE)
%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
%#error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once"
%#endif
%#if PY_VERSION_HEX<0x03000000
if (PyUnicode_Check(obj)) {
char *cstr; Py_ssize_t len;
if (!alloc && cptr) {
return SWIG_RuntimeError;
}
obj = PyUnicode_AsUTF8String(obj);
if (!obj)
return SWIG_TypeError;
if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) {
if (cptr) {
if (alloc) *alloc = SWIG_NEWOBJ;
*cptr = %new_copy_array(cstr, len + 1, char);
}
if (psize) *psize = len + 1;
Py_XDECREF(obj);
return SWIG_OK;
} else {
Py_XDECREF(obj);
}
}
%#endif
%#endif
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
if (pchar_descriptor) {
void* vptr = 0;
if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
if (cptr) *cptr = (char *) vptr;
if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
if (alloc) *alloc = SWIG_OLDOBJ;
return SWIG_OK;
}
}
}
return SWIG_TypeError;
}
}
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
SWIGINTERNINLINE PyObject *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
if (carray) {
if (size > INT_MAX) {
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
return pchar_descriptor ?
SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
} else {
%#if PY_VERSION_HEX >= 0x03000000
%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
return PyBytes_FromStringAndSize(carray, %numeric_cast(size, Py_ssize_t));
%#else
return PyUnicode_DecodeUTF8(carray, %numeric_cast(size, Py_ssize_t), "surrogateescape");
%#endif
%#else
return PyString_FromStringAndSize(carray, %numeric_cast(size, Py_ssize_t));
%#endif
}
} else {
return SWIG_Py_Void();
}
}
}

View File

@@ -0,0 +1,59 @@
/* ------------------------------------------------------------
* python.swg
*
* Python configuration module.
* ------------------------------------------------------------ */
/* ------------------------------------------------------------
* Inner macros
* ------------------------------------------------------------ */
%include <pymacros.swg>
/* ------------------------------------------------------------
* The runtime part
* ------------------------------------------------------------ */
%include <pyruntime.swg>
/* ------------------------------------------------------------
* Special user directives
* ------------------------------------------------------------ */
%include <pyuserdir.swg>
/* ------------------------------------------------------------
* Typemap specializations
* ------------------------------------------------------------ */
%include <pytypemaps.swg>
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */
%include <pyopers.swg>
/* ------------------------------------------------------------
* Warnings for Python keywords
* ------------------------------------------------------------ */
%include <pythonkw.swg>
/* ------------------------------------------------------------
* The Python autodoc support
* ------------------------------------------------------------ */
%include <pydocs.swg>
/* ------------------------------------------------------------
* The Python classes, for C++
* ------------------------------------------------------------ */
%include <pyclasses.swg>
/* ------------------------------------------------------------
* The Python initialization function
* ------------------------------------------------------------ */
%include <pyinit.swg>
/* ------------------------------------------------------------
* For backward compatibility
* ------------------------------------------------------------ */
%include <pybackward.swg>

View File

@@ -0,0 +1,140 @@
/*
Warnings for Python keywords, built-in names and bad names.
*/
#define PYTHONKW(x) %keywordwarn("'" `x` "' is a python keyword, renaming to '_" `x` "'", rename="_%s") `x`
#define PYTHONBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in python") `x`
/*
Warnings for Python keywords
https://docs.python.org/2/reference/lexical_analysis.html#keywords
*/
PYTHONKW(and);
PYTHONKW(as);
PYTHONKW(assert);
PYTHONKW(async);
PYTHONKW(await);
PYTHONKW(break);
PYTHONKW(class);
PYTHONKW(continue);
PYTHONKW(def);
PYTHONKW(del);
PYTHONKW(elif);
PYTHONKW(else);
PYTHONKW(except);
PYTHONKW(exec);
PYTHONKW(finally);
PYTHONKW(for);
PYTHONKW(from);
PYTHONKW(global);
PYTHONKW(if);
PYTHONKW(import);
PYTHONKW(in);
PYTHONKW(is);
PYTHONKW(lambda);
PYTHONKW(not);
PYTHONKW(or);
PYTHONKW(pass);
PYTHONKW(print);
PYTHONKW(raise);
PYTHONKW(return);
PYTHONKW(try);
PYTHONKW(while);
PYTHONKW(with);
PYTHONKW(yield);
/*
built-in functions
https://docs.python.org/2/library/functions.html
*/
PYTHONBN(abs);
PYTHONBN(apply);
PYTHONBN(bool);
PYTHONBN(buffer);
PYTHONBN(callable);
PYTHONBN(chr);
PYTHONBN(classmethod);
PYTHONBN(cmp);
PYTHONBN(coerce);
PYTHONBN(compile);
PYTHONBN(complex);
PYTHONBN(delattr);
PYTHONBN(dict);
PYTHONBN(dir);
PYTHONBN(divmod);
PYTHONBN(enumerate);
PYTHONBN(eval);
PYTHONBN(execfile);
PYTHONBN(file);
PYTHONBN(filter);
PYTHONBN(float);
PYTHONBN(frozenset);
PYTHONBN(getattr);
PYTHONBN(globals);
PYTHONBN(hasattr);
PYTHONBN(hash);
PYTHONBN(hex);
PYTHONBN(id);
PYTHONBN(input);
PYTHONBN(int);
PYTHONBN(intern);
PYTHONBN(isinstance);
PYTHONBN(issubclass);
PYTHONBN(iter);
PYTHONBN(len);
PYTHONBN(list);
PYTHONBN(locals);
PYTHONBN(long);
PYTHONBN(map);
PYTHONBN(max);
PYTHONBN(min);
PYTHONBN(object);
PYTHONBN(oct);
PYTHONBN(open);
PYTHONBN(ord);
PYTHONBN(pow);
PYTHONBN(property);
PYTHONBN(range);
PYTHONBN(raw_input);
PYTHONBN(reduce);
PYTHONBN(reload);
PYTHONBN(repr);
PYTHONBN(reversed);
PYTHONBN(round);
PYTHONBN(set);
PYTHONBN(setattr);
PYTHONBN(slice);
PYTHONBN(sorted);
PYTHONBN(staticmethod);
PYTHONBN(str);
PYTHONBN(sum);
PYTHONBN(super);
PYTHONBN(tuple);
PYTHONBN(type);
PYTHONBN(unichr);
PYTHONBN(unicode);
PYTHONBN(vars);
PYTHONBN(xrange);
PYTHONBN(zip);
/*
built-in names
boolean type and None
*/
PYTHONBN(True);
PYTHONBN(False);
PYTHONKW(None);
/*
'self' is also a bad Name
*/
PYTHONKW(self);
#undef PYTHONBN
#undef PYTHONKW

View File

@@ -0,0 +1,64 @@
#if defined(SWIG_PYTHON_NO_THREADS)
# if defined(SWIG_PYTHON_THREADS)
# undef SWIG_PYTHON_THREADS
# endif
#endif
#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */
# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL)
# define SWIG_PYTHON_USE_GIL
# endif
# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
# ifndef SWIG_PYTHON_INITIALIZE_THREADS
# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads()
# endif
# ifdef __cplusplus /* C++ code */
class SWIG_Python_Thread_Block {
bool status;
PyGILState_STATE state;
public:
void end() { if (status) { PyGILState_Release(state); status = false;} }
SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {}
~SWIG_Python_Thread_Block() { end(); }
};
class SWIG_Python_Thread_Allow {
bool status;
PyThreadState *save;
public:
void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {}
~SWIG_Python_Thread_Allow() { end(); }
};
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block
# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end()
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow
# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end()
# else /* C code */
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure()
# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block)
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread()
# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow)
# endif
# else /* Old thread way, not implemented, user must provide it */
# if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
# define SWIG_PYTHON_INITIALIZE_THREADS
# endif
# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK)
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK
# endif
# if !defined(SWIG_PYTHON_THREAD_END_BLOCK)
# define SWIG_PYTHON_THREAD_END_BLOCK
# endif
# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW)
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW
# endif
# if !defined(SWIG_PYTHON_THREAD_END_ALLOW)
# define SWIG_PYTHON_THREAD_END_ALLOW
# endif
# endif
#else /* No thread support */
# define SWIG_PYTHON_INITIALIZE_THREADS
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK
# define SWIG_PYTHON_THREAD_END_BLOCK
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW
# define SWIG_PYTHON_THREAD_END_ALLOW
#endif

View File

@@ -0,0 +1,8 @@
/*
Helper function to return output types, now we need to use a list
instead of a tuple since all the other types
(std::pair,std::vector,std::list,etc) return tuples.
*/
#warning "Deprecated file: Don't use t_output_helper anymore,"
#warning "use SWIG_Python_AppendOutput or %append_output instead."

View File

@@ -0,0 +1,105 @@
/* ------------------------------------------------------------
* Typemap specializations for Python
* ------------------------------------------------------------ */
/* ------------------------------------------------------------
* Fragment section
* ------------------------------------------------------------ */
#ifdef SWIG_PYTHON_LEGACY_BOOL
// Default prior to SWIG 3.0.0
#undef SWIG_TYPECHECK_BOOL
%define SWIG_TYPECHECK_BOOL 10000 %enddef
#endif
/* Include fundamental fragment definitions */
%include <typemaps/fragments.swg>
/* Look for user fragments file. */
%include <pyfragments.swg>
/* Python fragments for fundamental types */
%include <pyprimtypes.swg>
/* Python fragments for char* strings */
%include <pystrings.swg>
/* Backward compatibility output helper */
%fragment("t_output_helper","header") %{
#define t_output_helper SWIG_Python_AppendOutput
%}
/* ------------------------------------------------------------
* Unified typemap section
* ------------------------------------------------------------ */
/* directors are supported in Python */
#ifndef SWIG_DIRECTOR_TYPEMAPS
#define SWIG_DIRECTOR_TYPEMAPS
#endif
/* Python types */
#define SWIG_Object PyObject *
#define VOID_Object SWIG_Py_Void()
/* Python allows implicit conversion */
#define %implicitconv_flag $implicitconv
/* Overload of the output/constant/exception/dirout handling */
/* append output */
#define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj)
/* set constant */
#if defined(SWIGPYTHON_BUILTIN)
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, name,obj)
#else
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
#endif
/* raise */
#define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc)
/* Include the unified typemap library */
%include <typemaps/swigtypemaps.swg>
/* ------------------------------------------------------------
* Python extra typemaps / typemap overrides
* ------------------------------------------------------------ */
/* Get the address of the 'python self' object */
%typemap(in,numinputs=0,noblock=1) PyObject **PYTHON_SELF {
$1 = &$self;
}
/* Consttab, needed for callbacks, it should be removed later */
%typemap(consttab) SWIGTYPE ((*)(ANY))
{ SWIG_PY_POINTER, "$symname", 0, 0, (void *)($value), &$descriptor }
%typemap(consttab) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY));
%typemap(constcode) SWIGTYPE ((*)(ANY)) "";
%typemap(constcode) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY));
/* Smart Pointers */
%typemap(out,noblock=1) const SWIGTYPE & SMARTPOINTER {
$result = SWIG_NewPointerObj(%new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags);
}
%typemap(ret,noblock=1) const SWIGTYPE & SMARTPOINTER, SWIGTYPE SMARTPOINTER {
if ($result) {
PyObject *robj = PyObject_CallMethod($result, (char *)"__deref__", NULL);
if (robj && !PyErr_Occurred()) {
SwigPyObject_append((PyObject *) SWIG_Python_GetSwigThis($result),
(PyObject *) SWIG_Python_GetSwigThis(robj));
Py_DECREF(robj);
}
}
}

View File

@@ -0,0 +1,242 @@
/* -------------------------------------------------------------------------
* Special user directives
* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* shadow code */
#define %shadow %insert("shadow")
#define %pythoncode %insert("python")
#define %pythonbegin %insert("pythonbegin")
/* ------------------------------------------------------------------------- */
/*
Use the "nondynamic" feature to make a wrapped class behave as a "nondynamic"
one, ie, a python class that doesn't dynamically add new attributes.
For example, for the class
%pythonnondynamic A;
struct A
{
int a;
int b;
};
you will get:
aa = A()
aa.a = 1 # Ok
aa.b = 1 # Ok
aa.c = 3 # error
Since nondynamic is a feature, if you use it like
%pythonnondynamic;
it will make all the wrapped classes nondynamic ones.
The implementation is based on this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
*/
#define %pythonnondynamic %feature("python:nondynamic", "1")
#define %nopythonnondynamic %feature("python:nondynamic", "0")
#define %clearpythonnondynamic %feature("python:nondynamic", "")
#define %pythondynamic %nopythonnondynamic
/* ------------------------------------------------------------------------- */
/*
Use %pythonmaybecall to flag a method like __add__ or __radd__. These
don't produce an error when called, they just return NotImplemented.
These methods "may be called" if needed.
*/
#define %pythonmaybecall %feature("python:maybecall", "1")
#define %nopythonmaybecall %feature("python:maybecall", "0")
#define %clearpythonmaybecall %feature("python:maybecall", "")
/* ------------------------------------------------------------------------- */
/*
The %pythoncallback feature produce a more natural callback wrapper
than the %callback mechanism, ie, it uses the original name for
the callback and callable objects.
Just use it as
%pythoncallback(1) foo;
int foo(int a);
%pythoncallback(1) A::foo;
struct A {
static int foo(int a);
};
int bar(int, int (*pf)(int));
then, you can use it as:
a = foo(1)
b = bar(2, foo)
c = A.foo(3)
d = bar(4, A.foo)
If you use it with a member method
%pythoncallback(1) A::foom;
struct A {
int foom(int a);
};
then you can use it as
r = a.foom(3) # eval the method
mptr = A.foom_cb_ptr # returns the callback pointer
where the '_cb_ptr' suffix is added for the callback pointer.
*/
#define %pythoncallback %feature("python:callback")
#define %nopythoncallback %feature("python:callback","0")
#define %clearpythoncallback %feature("python:callback","")
/* ------------------------------------------------------------------------- */
/*
Support for the old %callback directive name
*/
#ifdef %callback
#undef %callback
#endif
#ifdef %nocallback
#undef %nocallback
#endif
#ifdef %clearcallback
#undef %clearcallback
#endif
#define %callback(x) %feature("python:callback",`x`)
#define %nocallback %nopythoncallback
#define %clearcallback %clearpythoncallback
/* ------------------------------------------------------------------------- */
/*
Thread support - Advance control
*/
#define %nothread %feature("nothread")
#define %thread %feature("nothread","0")
#define %clearnothread %feature("nothread","")
#define %nothreadblock %feature("nothreadblock")
#define %threadblock %feature("nothreadblock","0")
#define %clearnothreadblock %feature("nothreadblock","")
#define %nothreadallow %feature("nothreadallow")
#define %threadallow %feature("nothreadallow","0")
#define %clearnothreadallow %feature("nothreadallow","")
/* ------------------------------------------------------------------------- */
/*
Implicit Conversion using the C++ constructor mechanism
*/
#define %implicitconv %feature("implicitconv")
#define %noimplicitconv %feature("implicitconv", "0")
#define %clearimplicitconv %feature("implicitconv", "")
/* ------------------------------------------------------------------------- */
/*
Enable keywords parameters
*/
#define %kwargs %feature("kwargs")
#define %nokwargs %feature("kwargs", "0")
#define %clearkwargs %feature("kwargs", "")
/* ------------------------------------------------------------------------- */
/*
Add python code to the proxy/shadow code
%pythonprepend - Add code before the C++ function is called
%pythonappend - Add code after the C++ function is called
*/
#define %pythonprepend %feature("pythonprepend")
#define %clearpythonprepend %feature("pythonprepend","")
#define %pythonappend %feature("pythonappend")
#define %clearpythonappend %feature("pythonappend","")
/* ------------------------------------------------------------------------- */
/*
%extend_smart_pointer extend the smart pointer support.
For example, if you have a smart pointer as:
template <class Type> class RCPtr {
public:
...
RCPtr(Type *p);
Type * operator->() const;
...
};
you use the %extend_smart_pointer directive as:
%extend_smart_pointer(RCPtr<A>);
%template(RCPtr_A) RCPtr<A>;
then, if you have something like:
RCPtr<A> make_ptr();
int foo(A *);
you can do the following:
a = make_ptr();
b = foo(a);
ie, swig will accept a RCPtr<A> object where a 'A *' is
expected.
Also, when using vectors
%extend_smart_pointer(RCPtr<A>);
%template(RCPtr_A) RCPtr<A>;
%template(vector_A) std::vector<RCPtr<A> >;
you can type
a = A();
v = vector_A(2)
v[0] = a
ie, an 'A *' object is accepted, via implicit conversion,
where a RCPtr<A> object is expected. Additionally
x = v[0]
returns (and sets 'x' as) a copy of v[0], making reference
counting possible and consistent.
*/
%define %extend_smart_pointer(Type...)
%implicitconv Type;
%apply const SWIGTYPE& SMARTPOINTER { const Type& };
%apply SWIGTYPE SMARTPOINTER { Type };
%enddef

View File

@@ -0,0 +1,85 @@
/* ------------------------------------------------------------
* utility methods for wchar_t strings
* ------------------------------------------------------------ */
%{
#if PY_VERSION_HEX >= 0x03020000
# define SWIGPY_UNICODE_ARG(obj) ((PyObject*) (obj))
#else
# define SWIGPY_UNICODE_ARG(obj) ((PyUnicodeObject*) (obj))
#endif
%}
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") {
SWIGINTERN int
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
{
PyObject *tmp = 0;
int isunicode = PyUnicode_Check(obj);
%#if PY_VERSION_HEX < 0x03000000 && !defined(SWIG_PYTHON_STRICT_UNICODE_WCHAR)
if (!isunicode && PyString_Check(obj)) {
tmp = PyUnicode_FromObject(obj);
if (tmp) {
isunicode = 1;
obj = tmp;
} else {
PyErr_Clear();
return SWIG_TypeError;
}
}
%#endif
if (isunicode) {
%#if PY_VERSION_HEX >= 0x03030000
Py_ssize_t len = PyUnicode_GetLength(obj);
%#else
Py_ssize_t len = PyUnicode_GetSize(obj);
%#endif
if (cptr) {
Py_ssize_t length;
*cptr = %new_array(len + 1, wchar_t);
length = PyUnicode_AsWideChar(SWIGPY_UNICODE_ARG(obj), *cptr, len);
if (length == -1) {
PyErr_Clear();
Py_XDECREF(tmp);
return SWIG_TypeError;
}
(*cptr)[length] = 0;
}
if (psize) *psize = (size_t) len + 1;
if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0;
Py_XDECREF(tmp);
return SWIG_OK;
} else {
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
if (pwchar_descriptor) {
void * vptr = 0;
if (SWIG_ConvertPtr(obj, &vptr, pwchar_descriptor, 0) == SWIG_OK) {
if (cptr) *cptr = (wchar_t *)vptr;
if (psize) *psize = vptr ? (wcslen((wchar_t *)vptr) + 1) : 0;
return SWIG_OK;
}
}
}
return SWIG_TypeError;
}
}
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") {
SWIGINTERNINLINE PyObject *
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
{
if (carray) {
if (size > INT_MAX) {
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
return pwchar_descriptor ?
SWIG_InternalNewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
} else {
return PyUnicode_FromWideChar(carray, %numeric_cast(size, Py_ssize_t));
}
} else {
return SWIG_Py_Void();
}
}
}

View File

@@ -0,0 +1 @@
%include <std/std_alloc.i>

View File

@@ -0,0 +1,91 @@
/*
std::array
*/
%fragment("StdArrayTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T, size_t N>
struct traits_asptr<std::array<T, N> > {
static int asptr(PyObject *obj, std::array<T, N> **vec) {
return traits_asptr_stdseq<std::array<T, N> >::asptr(obj, vec);
}
};
template <class T, size_t N>
struct traits_from<std::array<T, N> > {
static PyObject *from(const std::array<T, N>& vec) {
return traits_from_stdseq<std::array<T, N> >::from(vec);
}
};
template <class SwigPySeq, class T, size_t N>
inline void
assign(const SwigPySeq& swigpyseq, std::array<T, N>* seq) {
if (swigpyseq.size() < seq->size())
throw std::invalid_argument("std::array cannot be expanded in size");
else if (swigpyseq.size() > seq->size())
throw std::invalid_argument("std::array cannot be reduced in size");
std::copy(swigpyseq.begin(), swigpyseq.end(), seq->begin());
}
template <class T, size_t N>
inline void
erase(std::array<T, N>* SWIGUNUSEDPARM(seq), const typename std::array<T, N>::iterator& SWIGUNUSEDPARM(position)) {
throw std::invalid_argument("std::array object does not support item deletion");
}
// Only limited slicing is supported as std::array is fixed in size
template <class T, size_t N, class Difference>
inline std::array<T, N>*
getslice(const std::array<T, N>* self, Difference i, Difference j, Py_ssize_t step) {
typedef std::array<T, N> Sequence;
typename Sequence::size_type size = self->size();
Difference ii = 0;
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj);
if (step == 1 && ii == 0 && static_cast<typename Sequence::size_type>(jj) == size) {
Sequence *sequence = new Sequence();
std::copy(self->begin(), self->end(), sequence->begin());
return sequence;
} else if (step == -1 && static_cast<typename Sequence::size_type>(ii) == (size - 1) && jj == -1) {
Sequence *sequence = new Sequence();
std::copy(self->rbegin(), self->rend(), sequence->begin());
return sequence;
} else {
throw std::invalid_argument("std::array object only supports getting a slice that is the size of the array");
}
}
template <class T, size_t N, class Difference, class InputSeq>
inline void
setslice(std::array<T, N>* self, Difference i, Difference j, Py_ssize_t step, const InputSeq& is = InputSeq()) {
typedef std::array<T, N> Sequence;
typename Sequence::size_type size = self->size();
Difference ii = 0;
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj, true);
if (step == 1 && ii == 0 && static_cast<typename Sequence::size_type>(jj) == size) {
std::copy(is.begin(), is.end(), self->begin());
} else if (step == -1 && static_cast<typename Sequence::size_type>(ii) == (size - 1) && jj == -1) {
std::copy(is.rbegin(), is.rend(), self->begin());
} else {
throw std::invalid_argument("std::array object only supports setting a slice that is the size of the array");
}
}
template <class T, size_t N, class Difference>
inline void
delslice(std::array<T, N>* SWIGUNUSEDPARM(self), Difference SWIGUNUSEDPARM(i), Difference SWIGUNUSEDPARM(j), Py_ssize_t SWIGUNUSEDPARM(step)) {
throw std::invalid_argument("std::array object does not support item deletion");
}
}
%}
#define %swig_array_methods(Type...) %swig_sequence_methods_non_resizable(Type)
#define %swig_array_methods_val(Type...) %swig_sequence_methods_non_resizable_val(Type);
%include <std/std_array.i>

View File

@@ -0,0 +1,17 @@
/*
The typemaps here allow to handle functions returning std::auto_ptr<>,
which is the most common use of this type. If you have functions taking it
as parameter, these typemaps can't be used for them and you need to do
something else (e.g. use shared_ptr<> which SWIG supports fully).
*/
%define %auto_ptr(TYPE)
%typemap (out) std::auto_ptr<TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%template() std::auto_ptr<TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

View File

@@ -0,0 +1,89 @@
#if !defined(SWIG_STD_STRING)
#define SWIG_STD_BASIC_STRING
%include <pycontainer.swg>
#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val) {
static swig_type_info* string_info = SWIG_TypeQuery("std::basic_string<char> *");
std::string *vptr;
if (SWIG_IsOK(SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0))) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
PyErr_Clear();
char* buf = 0 ; size_t size = 0; int alloc = 0;
if (SWIG_IsOK(SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc))) {
if (buf) {
if (val) *val = new std::string(buf, size - 1);
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
return SWIG_NEWOBJ;
} else {
if (val) *val = 0;
return SWIG_OLDOBJ;
}
}
return SWIG_ERROR;
}
}
}
%fragment(SWIG_From_frag(std::basic_string<char>),"header",
fragment="SWIG_FromCharPtrAndSize") {
SWIGINTERNINLINE PyObject*
SWIG_From(std::basic_string<char>)(const std::string& s) {
return SWIG_FromCharPtrAndSize(s.data(), s.size());
}
}
%include <std/std_basic_string.i>
%typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>);
#endif
#if !defined(SWIG_STD_WSTRING)
%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header",
fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int
SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val) {
static swig_type_info* string_info = SWIG_TypeQuery("std::basic_string<wchar_t> *");
std::wstring *vptr;
if (SWIG_IsOK(SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0))) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
PyErr_Clear();
wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
if (SWIG_IsOK(SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc))) {
if (buf) {
if (val) *val = new std::wstring(buf, size - 1);
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
return SWIG_NEWOBJ;
} else {
if (val) *val = 0;
return SWIG_OLDOBJ;
}
}
return SWIG_ERROR;
}
}
}
%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
fragment="SWIG_FromWCharPtrAndSize") {
SWIGINTERNINLINE PyObject*
SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s) {
return SWIG_FromWCharPtrAndSize(s.data(), s.size());
}
}
%typemaps_asptrfromn(%checkcode(UNISTRING), std::basic_string<wchar_t>);
#endif

View File

@@ -0,0 +1,54 @@
%include <pycontainer.swg>
%fragment("StdCarrayTraits","header",fragment="StdSequenceTraits")
{
namespace swig {
template <class T, size_t S>
struct traits_asptr<std::carray<T, S> > {
static int asptr(PyObject *obj, std::carray<T, S> **array) {
return traits_asptr_stdseq<std::carray<T, S> >::asptr(obj, array);
}
};
}
}
%warnfilter(SWIGWARN_IGNORE_OPERATOR_INDEX) std::carray::operator[];
%extend std::carray {
%fragment(SWIG_Traits_frag(std::carray<_Type, _Size >), "header",
fragment="SwigPyIterator_T",
fragment=SWIG_Traits_frag(_Type),
fragment="StdCarrayTraits") {
namespace swig {
template <> struct traits<std::carray<_Type, _Size > > {
typedef pointer_category category;
static const char* type_name() {
return "std::carray<" #_Type "," #_Size " >";
}
};
}
}
%typemaps_asptr(SWIG_TYPECHECK_VECTOR, swig::asptr,
SWIG_Traits_frag(std::carray<_Type, _Size >),
std::carray<_Type, _Size >);
%typemap(out,noblock=1) iterator, const_iterator {
$result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
}
inline size_t __len__() const { return self->size(); }
inline const _Type& __getitem__(size_t i) const { return (*self)[i]; }
inline void __setitem__(size_t i, const _Type& v) { (*self)[i] = v; }
swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
%include <std/std_carray.swg>

View File

@@ -0,0 +1 @@
%include <std/std_char_traits.i>

View File

@@ -0,0 +1,74 @@
%include <std/std_except.i>
%include <pystdcommon.swg>
/*
Generate the traits for a 'primitive' type, such as 'double',
for which the SWIG_AsVal and SWIG_From methods are already defined.
*/
%define %traits_ptypen(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="StdTraits") {
namespace swig {
template <> struct traits< Type > {
typedef value_category category;
static const char* type_name() { return #Type; }
};
template <> struct traits_asval< Type > {
typedef Type value_type;
static int asval(PyObject *obj, value_type *val) {
return SWIG_AsVal(Type)(obj, val);
}
};
template <> struct traits_from< Type > {
typedef Type value_type;
static PyObject *from(const value_type& val) {
return SWIG_From(Type)(val);
}
};
}
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval< Type > {
typedef Type value_type;
static int asval(PyObject *obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from< Type > {
typedef Type value_type;
static PyObject *from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>
//
// Generates the traits for all the known primitive
// C++ types (int, double, ...)
//
%apply_cpptypes(%traits_ptypen);

View File

@@ -0,0 +1,27 @@
/*
* STD C++ complex typemaps
*/
%include <pycomplex.swg>
%{
#include <complex>
%}
namespace std {
%naturalvar complex;
template<typename T> class complex;
%template() complex<double>;
%template() complex<float>;
}
/* defining the complex as/from converters */
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
/* defining the typemaps */
%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);

View File

@@ -0,0 +1,2 @@
%include <pycontainer.swg>
%include <std/std_container.i>

View File

@@ -0,0 +1,27 @@
/*
Deques
*/
%fragment("StdDequeTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T>
struct traits_asptr<std::deque<T> > {
static int asptr(PyObject *obj, std::deque<T> **vec) {
return traits_asptr_stdseq<std::deque<T> >::asptr(obj, vec);
}
};
template <class T>
struct traits_from<std::deque<T> > {
static PyObject *from(const std::deque<T>& vec) {
return traits_from_stdseq<std::deque<T> >::from(vec);
}
};
}
%}
#define %swig_deque_methods(Type...) %swig_sequence_methods(Type)
#define %swig_deque_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_deque.i>

View File

@@ -0,0 +1 @@
%include <typemaps/std_except.swg>

View File

@@ -0,0 +1,3 @@
%rename(ios_base_in) std::ios_base::in;
%include <std/std_ios.i>

View File

@@ -0,0 +1,8 @@
namespace std
{
%callback(1) endl;
%callback(1) ends;
%callback(1) flush;
}
%include <std/std_iostream.i>

View File

@@ -0,0 +1,28 @@
/*
Lists
*/
%fragment("StdListTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T >
struct traits_asptr<std::list<T> > {
static int asptr(PyObject *obj, std::list<T> **lis) {
return traits_asptr_stdseq<std::list<T> >::asptr(obj, lis);
}
};
template <class T>
struct traits_from<std::list<T> > {
static PyObject *from(const std::list<T>& vec) {
return traits_from_stdseq<std::list<T> >::from(vec);
}
};
}
%}
#define %swig_list_methods(Type...) %swig_sequence_methods(Type)
#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_list.i>

View File

@@ -0,0 +1,310 @@
/*
Maps
*/
%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits")
{
namespace swig {
template <class ValueType>
struct from_key_oper
{
typedef const ValueType& argument_type;
typedef PyObject *result_type;
result_type operator()(argument_type v) const
{
return swig::from(v.first);
}
};
template <class ValueType>
struct from_value_oper
{
typedef const ValueType& argument_type;
typedef PyObject *result_type;
result_type operator()(argument_type v) const
{
return swig::from(v.second);
}
};
template<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type>
struct SwigPyMapIterator_T : SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper>
{
SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
{
}
};
template<class OutIterator,
class FromOper = from_key_oper<typename OutIterator::value_type> >
struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T<OutIterator, FromOper>
{
SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
{
}
};
template<typename OutIter>
inline SwigPyIterator*
make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
{
return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq);
}
template<class OutIterator,
class FromOper = from_value_oper<typename OutIterator::value_type> >
struct SwigPyMapValueIterator_T : SwigPyMapIterator_T<OutIterator, FromOper>
{
SwigPyMapValueIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
{
}
};
template<typename OutIter>
inline SwigPyIterator*
make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
{
return new SwigPyMapValueIterator_T<OutIter>(current, begin, end, seq);
}
}
}
%fragment("StdMapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
template <class SwigPySeq, class K, class T, class Compare, class Alloc >
inline void
assign(const SwigPySeq& swigpyseq, std::map<K,T,Compare,Alloc > *map) {
typedef typename std::map<K,T,Compare,Alloc >::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
map->insert(value_type(it->first, it->second));
}
}
template <class K, class T, class Compare, class Alloc>
struct traits_asptr<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
static int asptr(PyObject *obj, map_type **val) {
int res = SWIG_ERROR;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<map_type, std::pair<K, T> >::asptr(items, val);
} else {
map_type *p;
swig_type_info *descriptor = swig::type_info<map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
SWIG_PYTHON_THREAD_END_BLOCK;
return res;
}
};
template <class K, class T, class Compare, class Alloc >
struct traits_from<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
typedef typename map_type::const_iterator const_iterator;
typedef typename map_type::size_type size_type;
static PyObject *asdict(const map_type& map) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
SWIG_PYTHON_THREAD_END_BLOCK;
return obj;
}
static PyObject *from(const map_type& map) {
swig_type_info *desc = swig::type_info<map_type>();
if (desc && desc->clientdata) {
return SWIG_InternalNewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
} else {
return asdict(map);
}
}
};
}
}
%define %swig_map_common(Map...)
%swig_sequence_iterator(Map);
%swig_container_methods(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_length", functype="lenfunc") __len__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "tp_iter", functype="getiterfunc") key_iterator;
%feature("python:slot", "sq_contains", functype="objobjproc") __contains__;
%extend {
%newobject iterkeys(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject itervalues(PyObject **PYTHON_SELF);
swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject iteritems(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
#else
%extend {
%pythoncode %{def __iter__(self):
return self.key_iterator()%}
%pythoncode %{def iterkeys(self):
return self.key_iterator()%}
%pythoncode %{def itervalues(self):
return self.value_iterator()%}
%pythoncode %{def iteritems(self):
return self.iterator()%}
}
#endif
%extend {
mapped_type const & __getitem__(const key_type& key) throw (std::out_of_range) {
Map::const_iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::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 key_type& key) const {
Map::const_iterator i = self->find(key);
return i != self->end();
}
PyObject* keys() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* keyList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(keyList, j, swig::from(i->first));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return keyList;
}
PyObject* values() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* valList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(valList, j, swig::from(i->second));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return valList;
}
PyObject* items() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* itemList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(itemList, j, swig::from(*i));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return itemList;
}
bool __contains__(const key_type& key) {
return self->find(key) != self->end();
}
%newobject key_iterator(PyObject **PYTHON_SELF);
swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject value_iterator(PyObject **PYTHON_SELF);
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
%enddef
%define %swig_map_methods(Map...)
%swig_map_common(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x;
}
PyObject* asdict() {
return swig::traits_from< Map >::asdict(*self);
}
}
%enddef
%include <std/std_map.i>

View File

@@ -0,0 +1,93 @@
/*
Multimaps
*/
%include <std_map.i>
%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
template <class SwigPySeq, class K, class T >
inline void
assign(const SwigPySeq& swigpyseq, std::multimap<K,T > *multimap) {
typedef typename std::multimap<K,T>::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
multimap->insert(value_type(it->first, it->second));
}
}
template <class K, class T>
struct traits_asptr<std::multimap<K,T> > {
typedef std::multimap<K,T> multimap_type;
static int asptr(PyObject *obj, std::multimap<K,T> **val) {
int res = SWIG_ERROR;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
multimap_type *p;
swig_type_info *descriptor = swig::type_info<multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;
}
};
template <class K, class T >
struct traits_from<std::multimap<K,T> > {
typedef std::multimap<K,T> multimap_type;
typedef typename multimap_type::const_iterator const_iterator;
typedef typename multimap_type::size_type size_type;
static PyObject *from(const multimap_type& multimap) {
swig_type_info *desc = swig::type_info<multimap_type>();
if (desc && desc->clientdata) {
return SWIG_InternalNewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
} else {
size_type size = multimap.size();
Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError, "multimap size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= multimap.begin(); i!= multimap.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
return obj;
}
}
};
}
}
%define %swig_multimap_methods(Type...)
%swig_map_common(Type);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
self->insert(Type::value_type(key,x));
}
}
%enddef
%include <std/std_multimap.i>

View File

@@ -0,0 +1,41 @@
/*
Multisets
*/
%include <std_set.i>
%fragment("StdMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class SwigPySeq, class T>
inline void
assign(const SwigPySeq& swigpyseq, std::multiset<T>* seq) {
// seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class T>
struct traits_asptr<std::multiset<T> > {
static int asptr(PyObject *obj, std::multiset<T> **m) {
return traits_asptr_stdseq<std::multiset<T> >::asptr(obj, m);
}
};
template <class T>
struct traits_from<std::multiset<T> > {
static PyObject *from(const std::multiset<T>& vec) {
return traits_from_stdseq<std::multiset<T> >::from(vec);
}
};
}
%}
#define %swig_multiset_methods(Set...) %swig_set_methods(Set)
%include <std/std_multiset.i>

View File

@@ -0,0 +1,206 @@
/*
Pairs
*/
%include <pystdcommon.swg>
//#define SWIG_STD_PAIR_ASVAL
%fragment("StdPairTraits","header",fragment="StdTraits") {
namespace swig {
#ifdef SWIG_STD_PAIR_ASVAL
template <class T, class U >
struct traits_asval<std::pair<T,U> > {
typedef std::pair<T,U> value_type;
static int get_pair(PyObject* first, PyObject* second,
std::pair<T,U> *val)
{
if (val) {
T *pfirst = &(val->first);
int res1 = swig::asval((PyObject*)first, pfirst);
if (!SWIG_IsOK(res1)) return res1;
U *psecond = &(val->second);
int res2 = swig::asval((PyObject*)second, psecond);
if (!SWIG_IsOK(res2)) return res2;
return res1 > res2 ? res1 : res2;
} else {
T *pfirst = 0;
int res1 = swig::asval((PyObject*)first, 0);
if (!SWIG_IsOK(res1)) return res1;
U *psecond = 0;
int res2 = swig::asval((PyObject*)second, psecond);
if (!SWIG_IsOK(res2)) return res2;
return res1 > res2 ? res1 : res2;
}
}
static int asval(PyObject *obj, std::pair<T,U> *val) {
int res = SWIG_ERROR;
if (PyTuple_Check(obj)) {
if (PyTuple_GET_SIZE(obj) == 2) {
res = get_pair(PyTuple_GET_ITEM(obj,0),PyTuple_GET_ITEM(obj,1), val);
}
} else if (PySequence_Check(obj)) {
if (PySequence_Size(obj) == 2) {
swig::SwigVar_PyObject first = PySequence_GetItem(obj,0);
swig::SwigVar_PyObject second = PySequence_GetItem(obj,1);
res = get_pair(first, second, val);
}
} else {
value_type *p;
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = *p;
}
return res;
}
};
#else
template <class T, class U >
struct traits_asptr<std::pair<T,U> > {
typedef std::pair<T,U> value_type;
static int get_pair(PyObject* first, PyObject* second,
std::pair<T,U> **val)
{
if (val) {
value_type *vp = %new_instance(std::pair<T,U>);
T *pfirst = &(vp->first);
int res1 = swig::asval((PyObject*)first, pfirst);
if (!SWIG_IsOK(res1)) {
%delete(vp);
return res1;
}
U *psecond = &(vp->second);
int res2 = swig::asval((PyObject*)second, psecond);
if (!SWIG_IsOK(res2)) {
%delete(vp);
return res2;
}
*val = vp;
return SWIG_AddNewMask(res1 > res2 ? res1 : res2);
} else {
T *pfirst = 0;
int res1 = swig::asval((PyObject*)first, pfirst);
if (!SWIG_IsOK(res1)) return res1;
U *psecond = 0;
int res2 = swig::asval((PyObject*)second, psecond);
if (!SWIG_IsOK(res2)) return res2;
return res1 > res2 ? res1 : res2;
}
}
static int asptr(PyObject *obj, std::pair<T,U> **val) {
int res = SWIG_ERROR;
if (PyTuple_Check(obj)) {
if (PyTuple_GET_SIZE(obj) == 2) {
res = get_pair(PyTuple_GET_ITEM(obj,0),PyTuple_GET_ITEM(obj,1), val);
}
} else if (PySequence_Check(obj)) {
if (PySequence_Size(obj) == 2) {
swig::SwigVar_PyObject first = PySequence_GetItem(obj,0);
swig::SwigVar_PyObject second = PySequence_GetItem(obj,1);
res = get_pair(first, second, val);
}
} else {
value_type *p;
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;
}
};
#endif
template <class T, class U >
struct traits_from<std::pair<T,U> > {
static PyObject *from(const std::pair<T,U>& val) {
PyObject* obj = PyTuple_New(2);
PyTuple_SetItem(obj,0,swig::from(val.first));
PyTuple_SetItem(obj,1,swig::from(val.second));
return obj;
}
};
}
#if defined(SWIGPYTHON_BUILTIN)
SWIGINTERN Py_ssize_t
SwigPython_std_pair_len (PyObject *a)
{
return 2;
}
SWIGINTERN PyObject*
SwigPython_std_pair_repr (PyObject *o)
{
PyObject *tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, (char*) "first"));
PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, (char*) "second"));
PyObject *result = PyObject_Repr(tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject*
SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b)
{
PyObject *result = PyObject_GetAttrString(a, b % 2 ? (char*) "second" : (char*) "first");
return result;
}
SWIGINTERN int
SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
{
int result = PyObject_SetAttrString(a, b % 2 ? (char*) "second" : (char*) "first", c);
return result;
}
#endif
}
%feature("python:sq_length") std::pair "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T,U*> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U*> "SwigPython_std_pair_len";
%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T,U*> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U*> "SwigPython_std_pair_repr";
%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T,U*> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U*> "SwigPython_std_pair_setitem";
%define %swig_pair_methods(pair...)
#if !defined(SWIGPYTHON_BUILTIN)
%extend {
%pythoncode %{def __len__(self):
return 2
def __repr__(self):
return str((self.first, self.second))
def __getitem__(self, index):
if not (index % 2):
return self.first
else:
return self.second
def __setitem__(self, index, val):
if not (index % 2):
self.first = val
else:
self.second = val%}
}
#endif
%enddef
%include <std/std_pair.i>

View File

@@ -0,0 +1,67 @@
/*
Sets
*/
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class SwigPySeq, class T>
inline void
assign(const SwigPySeq& swigpyseq, std::set<T>* seq) {
// seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class T>
struct traits_asptr<std::set<T> > {
static int asptr(PyObject *obj, std::set<T> **s) {
return traits_asptr_stdseq<std::set<T> >::asptr(obj, s);
}
};
template <class T>
struct traits_from<std::set<T> > {
static PyObject *from(const std::set<T>& vec) {
return traits_from_stdseq<std::set<T> >::from(vec);
}
};
}
%}
%define %swig_set_methods(set...)
%swig_sequence_iterator(set);
%swig_container_methods(set);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "sq_contains", functype="objobjproc") __contains__;
#endif
%extend {
void append(value_type x) {
self->insert(x);
}
bool __contains__(value_type x) {
return self->find(x) != self->end();
}
value_type __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
}
void add(value_type x) {
self->insert(x);
}
void discard(value_type x) {
self->erase(x);
}
}
%enddef
%include <std/std_set.i>

View File

@@ -0,0 +1,2 @@
#define SWIG_SHARED_PTR_NAMESPACE std
%include <boost_shared_ptr.i>

View File

@@ -0,0 +1 @@
%include <std/std_sstream.i>

View File

@@ -0,0 +1 @@
%include <std/std_streambuf.i>

View File

@@ -0,0 +1 @@
%include <typemaps/std_string.swg>

View File

@@ -0,0 +1,296 @@
/*
Unordered Maps
*/
%include <std_map.i>
%fragment("StdUnorderedMapForwardIteratorTraits","header")
{
namespace swig {
template<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type>
struct SwigPyMapForwardIterator_T : SwigPyForwardIteratorClosed_T<OutIterator, ValueType, FromOper>
{
SwigPyMapForwardIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyForwardIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
{
}
};
template<class OutIterator,
class FromOper = from_key_oper<typename OutIterator::value_type> >
struct SwigPyMapKeyForwardIterator_T : SwigPyMapForwardIterator_T<OutIterator, FromOper>
{
SwigPyMapKeyForwardIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyMapForwardIterator_T<OutIterator, FromOper>(curr, first, last, seq)
{
}
};
template<typename OutIter>
inline SwigPyIterator*
make_output_key_forward_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
{
return new SwigPyMapKeyForwardIterator_T<OutIter>(current, begin, end, seq);
}
template<class OutIterator,
class FromOper = from_value_oper<typename OutIterator::value_type> >
struct SwigPyMapValueForwardIterator_T : SwigPyMapForwardIterator_T<OutIterator, FromOper>
{
SwigPyMapValueForwardIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
: SwigPyMapForwardIterator_T<OutIterator, FromOper>(curr, first, last, seq)
{
}
};
template<typename OutIter>
inline SwigPyIterator*
make_output_value_forward_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
{
return new SwigPyMapValueForwardIterator_T<OutIter>(current, begin, end, seq);
}
}
}
%fragment("StdUnorderedMapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
inline void
assign(const SwigPySeq& swigpyseq, std::unordered_map<K,T,Hash,Compare,Alloc> *unordered_map) {
typedef typename std::unordered_map<K,T,Hash,Compare,Alloc>::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
unordered_map->insert(value_type(it->first, it->second));
}
}
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_map<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_map<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_map<K,T,Hash,Compare,Alloc>::size_type n) {
seq.reserve(n);
}
};
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_asptr<std::unordered_map<K,T,Hash,Compare,Alloc> > {
typedef std::unordered_map<K,T,Hash,Compare,Alloc> unordered_map_type;
static int asptr(PyObject *obj, unordered_map_type **val) {
int res = SWIG_ERROR;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::unordered_map<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val);
} else {
unordered_map_type *p;
swig_type_info *descriptor = swig::type_info<unordered_map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
SWIG_PYTHON_THREAD_END_BLOCK;
return res;
}
};
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_from<std::unordered_map<K,T,Hash,Compare,Alloc> > {
typedef std::unordered_map<K,T,Hash,Compare,Alloc> unordered_map_type;
typedef typename unordered_map_type::const_iterator const_iterator;
typedef typename unordered_map_type::size_type size_type;
static PyObject *asdict(const unordered_map_type& map) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
SWIG_PYTHON_THREAD_END_BLOCK;
return obj;
}
static PyObject *from(const unordered_map_type& map) {
swig_type_info *desc = swig::type_info<unordered_map_type>();
if (desc && desc->clientdata) {
return SWIG_InternalNewPointerObj(new unordered_map_type(map), desc, SWIG_POINTER_OWN);
} else {
return asdict(map);
}
}
};
}
}
%define %swig_unordered_map_common(Map...)
%swig_sequence_forward_iterator(Map);
%swig_container_methods(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_length", functype="lenfunc") __len__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "tp_iter", functype="getiterfunc") key_iterator;
%feature("python:slot", "sq_contains", functype="objobjproc") __contains__;
%extend {
%newobject iterkeys(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
return swig::make_output_key_forward_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject itervalues(PyObject **PYTHON_SELF);
swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
return swig::make_output_value_forward_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject iteritems(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
return swig::make_output_forward_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
#else
%extend {
%pythoncode %{def __iter__(self):
return self.key_iterator()%}
%pythoncode %{def iterkeys(self):
return self.key_iterator()%}
%pythoncode %{def itervalues(self):
return self.value_iterator()%}
%pythoncode %{def iteritems(self):
return self.iterator()%}
}
#endif
%extend {
mapped_type const & __getitem__(const key_type& key) throw (std::out_of_range) {
Map::const_iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::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 key_type& key) const {
Map::const_iterator i = self->find(key);
return i != self->end();
}
PyObject* keys() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* keyList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(keyList, j, swig::from(i->first));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return keyList;
}
PyObject* values() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* valList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(valList, j, swig::from(i->second));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return valList;
}
PyObject* items() {
Map::size_type size = self->size();
Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject* itemList = PyList_New(pysize);
Map::const_iterator i = self->begin();
for (Py_ssize_t j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(itemList, j, swig::from(*i));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return itemList;
}
bool __contains__(const key_type& key) {
return self->find(key) != self->end();
}
%newobject key_iterator(PyObject **PYTHON_SELF);
swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_key_forward_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject value_iterator(PyObject **PYTHON_SELF);
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_forward_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
%enddef
%define %swig_unordered_map_methods(Map...)
%swig_unordered_map_common(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x;
}
PyObject* asdict() {
return swig::traits_from< Map >::asdict(*self);
}
}
%enddef
%include <std/std_unordered_map.i>

View File

@@ -0,0 +1,100 @@
/*
Unordered Multimaps
*/
%include <std_unordered_map.i>
%fragment("StdUnorderedMultimapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
inline void
assign(const SwigPySeq& swigpyseq, std::unordered_multimap<K,T,Hash,Compare,Alloc> *unordered_multimap) {
typedef typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
unordered_multimap->insert(value_type(it->first, it->second));
}
}
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multimap<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multimap<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::size_type n) {
seq.reserve(n);
}
};
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_asptr<std::unordered_multimap<K,T,Hash,Compare,Alloc> > {
typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> unordered_multimap_type;
static int asptr(PyObject *obj, std::unordered_multimap<K,T,Hash,Compare,Alloc> **val) {
int res = SWIG_ERROR;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::unordered_multimap<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val);
} else {
unordered_multimap_type *p;
swig_type_info *descriptor = swig::type_info<unordered_multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;
}
};
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_from<std::unordered_multimap<K,T,Hash,Compare,Alloc> > {
typedef std::unordered_multimap<K,T,Hash,Compare,Alloc> unordered_multimap_type;
typedef typename unordered_multimap_type::const_iterator const_iterator;
typedef typename unordered_multimap_type::size_type size_type;
static PyObject *from(const unordered_multimap_type& unordered_multimap) {
swig_type_info *desc = swig::type_info<unordered_multimap_type>();
if (desc && desc->clientdata) {
return SWIG_InternalNewPointerObj(new unordered_multimap_type(unordered_multimap), desc, SWIG_POINTER_OWN);
} else {
size_type size = unordered_multimap.size();
Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError, "unordered_multimap size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= unordered_multimap.begin(); i!= unordered_multimap.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
return obj;
}
}
};
}
}
%define %swig_unordered_multimap_methods(Type...)
%swig_unordered_map_common(Type);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
self->insert(Type::value_type(key,x));
}
}
%enddef
%include <std/std_unordered_multimap.i>

View File

@@ -0,0 +1,48 @@
/*
Unordered Multisets
*/
%include <std_unordered_set.i>
%fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
inline void
assign(const SwigPySeq& swigpyseq, std::unordered_multiset<Key,Hash,Compare,Alloc>* seq) {
// seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multiset<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multiset<Key,Hash,Compare,Alloc> &seq, typename std::unordered_multiset<Key,Hash,Compare,Alloc>::size_type n) {
seq.reserve(n);
}
};
template <class Key, class Hash, class Compare, class Alloc>
struct traits_asptr<std::unordered_multiset<Key,Hash,Compare,Alloc> > {
static int asptr(PyObject *obj, std::unordered_multiset<Key,Hash,Compare,Alloc> **m) {
return traits_asptr_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::asptr(obj, m);
}
};
template <class Key, class Hash, class Compare, class Alloc>
struct traits_from<std::unordered_multiset<Key,Hash,Compare,Alloc> > {
static PyObject *from(const std::unordered_multiset<Key,Hash,Compare,Alloc>& vec) {
return traits_from_stdseq<std::unordered_multiset<Key,Hash,Compare,Alloc> >::from(vec);
}
};
}
%}
#define %swig_unordered_multiset_methods(Set...) %swig_unordered_set_methods(Set)
%include <std/std_unordered_multiset.i>

View File

@@ -0,0 +1,67 @@
/*
Unordered Sets
*/
%fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
inline void
assign(const SwigPySeq& swigpyseq, std::unordered_set<Key,Hash,Compare,Alloc>* seq) {
// seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_set<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_set<Key,Hash,Compare,Alloc> &seq, typename std::unordered_set<Key,Hash,Compare,Alloc>::size_type n) {
seq.reserve(n);
}
};
template <class Key, class Hash, class Compare, class Alloc>
struct traits_asptr<std::unordered_set<Key,Hash,Compare,Alloc> > {
static int asptr(PyObject *obj, std::unordered_set<Key,Hash,Compare,Alloc> **s) {
return traits_asptr_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::asptr(obj, s);
}
};
template <class Key, class Hash, class Compare, class Alloc>
struct traits_from<std::unordered_set<Key,Hash,Compare,Alloc> > {
static PyObject *from(const std::unordered_set<Key,Hash,Compare,Alloc>& vec) {
return traits_from_stdseq<std::unordered_set<Key,Hash,Compare,Alloc> >::from(vec);
}
};
}
%}
%define %swig_unordered_set_methods(unordered_set...)
%swig_sequence_forward_iterator(unordered_set);
%swig_container_methods(unordered_set);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "sq_contains", functype="objobjproc") __contains__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
#endif
%extend {
void append(value_type x) {
self->insert(x);
}
bool __contains__(value_type x) {
return self->find(x) != self->end();
}
value_type __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
}
}
%enddef
%include <std/std_unordered_set.i>

View File

@@ -0,0 +1,34 @@
/*
Vectors
*/
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T>
struct traits_reserve<std::vector<T> > {
static void reserve(std::vector<T> &seq, typename std::vector<T>::size_type n) {
seq.reserve(n);
}
};
template <class T>
struct traits_asptr<std::vector<T> > {
static int asptr(PyObject *obj, std::vector<T> **vec) {
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
}
};
template <class T>
struct traits_from<std::vector<T> > {
static PyObject *from(const std::vector<T>& vec) {
return traits_from_stdseq<std::vector<T> >::from(vec);
}
};
}
%}
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_vector.i>

View File

@@ -0,0 +1,31 @@
/*
Vectors + allocators
*/
%fragment("StdVectorATraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T, class A>
struct traits_asptr<std::vector<T,A> > {
typedef std::vector<T,A> vector_type;
typedef T value_type;
static int asptr(PyObject *obj, vector_type **vec) {
return traits_asptr_stdseq<vector_type>::asptr(obj, vec);
}
};
template <class T, class A>
struct traits_from<std::vector<T,A> > {
typedef std::vector<T,A> vector_type;
static PyObject *from(const vector_type& vec) {
return traits_from_stdseq<vector_type>::from(vec);
}
};
}
%}
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_vectora.i>

View File

@@ -0,0 +1 @@
%include <std/std_wios.i>

View File

@@ -0,0 +1,10 @@
namespace std
{
%callback(1) wendl;
%callback(1) wends;
%callback(1) wflush;
}
%include <std_basic_string.i>
%include <std_wstring.i>
%include <std/std_wiostream.i>

View File

@@ -0,0 +1 @@
%include <std/std_wsstream.i>

View File

@@ -0,0 +1 @@
%include <std/std_wstreambuf.i>

View File

@@ -0,0 +1,3 @@
%include <pywstrings.swg>
%include <typemaps/std_wstring.swg>

View File

@@ -0,0 +1,10 @@
/* -----------------------------------------------------------------------------
* stl.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

View File

@@ -0,0 +1,148 @@
/* -----------------------------------------------------------------------------
* typemaps.i
*
* Pointer handling
* These mappings provide support for input/output arguments and common
* uses for C/C++ pointers.
* ----------------------------------------------------------------------------- */
// 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);
*/
// 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, they are returned in the form of a Python tuple.
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).K:
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 Python output of the function would be a tuple containing both
output values.
*/
// 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 Python tuple.
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 (since
this makes no sense in Python). Rather, the modified input value shows
up as the return value of the function. Thus, to apply this function
to a Python variable you might do this :
x = neg(x)
Note : previous versions of SWIG used the symbol 'BOTH' to mark
input/output arguments. This is still supported, but will be slowly
phased out in future releases.
*/
%include <typemaps/typemaps.swg>

View File

@@ -0,0 +1,21 @@
#ifdef __cplusplus
%{
#include <cwchar>
%}
#else
%{
#include <wchar.h>
%}
#endif
%types(wchar_t *);
%include <pywstrings.swg>
/*
Enable swig wchar support.
*/
#define SWIG_WCHAR