mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-30 05:59:20 +00:00
1
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
# ---------------------------------------------------------------
|
||||
# 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
|
||||
#SWIGLIB = -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
|
||||
|
||||
# X11 installation (needed if rebuilding Python + tkinter)
|
||||
|
||||
XLIB = @XLIBSW@
|
||||
XINCLUDE = @XINCLUDES@
|
||||
|
||||
# Python installation
|
||||
|
||||
PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@
|
||||
PY_LIB = @PYLIB@
|
||||
|
||||
# Tcl installation. Needed if rebuilding Python with tkinter.
|
||||
|
||||
TCL_INCLUDE = @TCLINCLUDE@
|
||||
TCL_LIB = @TCLLIB@
|
||||
|
||||
# Build libraries (needed for static builds)
|
||||
|
||||
LIBM = @LIBM@
|
||||
LIBC = @LIBC@
|
||||
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
|
||||
|
||||
# Build options (uncomment only one these)
|
||||
|
||||
#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB)
|
||||
BUILD_LIBS = $(LIBS) # Dynamic loading
|
||||
#BUILD_LIBS = $(PY_LIB) @PYLINK@ $(TKINTER) $(LIBS) $(SYSLIBS)
|
||||
|
||||
# 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) $(SWIGLIB) $(INTERFACE)
|
||||
|
||||
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
|
||||
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
*
|
||||
* 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
|
||||
embed15.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 realy 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/Pyton 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 (doen't need to be included)
|
||||
defarg.swg for processing default arguments with shadow classes
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/attribute.swg>
|
||||
@@ -0,0 +1,207 @@
|
||||
%include <shared_ptr.i>
|
||||
|
||||
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
|
||||
|
||||
%naturalvar TYPE;
|
||||
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
|
||||
|
||||
// destructor mods
|
||||
%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;"
|
||||
|
||||
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
|
||||
|
||||
// TODO:
|
||||
// varout varin typemaps
|
||||
|
||||
// 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 {
|
||||
%set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
|
||||
}
|
||||
|
||||
// plain pointer
|
||||
%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 > *), %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") 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 > *), SWIG_POINTER_OWN));
|
||||
}
|
||||
|
||||
// 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") 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));
|
||||
}
|
||||
|
||||
// plain pointer by reference
|
||||
%typemap(in) CONST TYPE *& (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 > *), %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") 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));
|
||||
}
|
||||
|
||||
// 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, $<ype));
|
||||
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype);
|
||||
}
|
||||
|
||||
%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));
|
||||
}
|
||||
|
||||
// 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 (argp) tempshared = *%reinterpret_cast(argp, $ltype);
|
||||
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $ltype);
|
||||
$1 = &tempshared;
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
// 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,noblock=1)
|
||||
CONST TYPE,
|
||||
CONST TYPE &,
|
||||
CONST TYPE *,
|
||||
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 > *,
|
||||
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"
|
||||
%}
|
||||
|
||||
|
||||
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
|
||||
%enddef
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
%define %array_class(TYPE,NAME)
|
||||
%array_class_wrap(TYPE,NAME,__getitem__,__setitem__)
|
||||
%enddef
|
||||
|
||||
%include <typemaps/carrays.swg>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* 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);
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/cdata.swg>
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/cmalloc.swg>
|
||||
@@ -0,0 +1,2 @@
|
||||
%include <gcj/cni.i>
|
||||
%include <jstring.i>
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifdef __cplusplus
|
||||
%include <std_complex.i>
|
||||
#else
|
||||
%include <ccomplex.i>
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/cpointer.swg>
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/cstring.swg>
|
||||
@@ -0,0 +1,3 @@
|
||||
%include <pywstrings.swg>
|
||||
%include <typemaps/cwstring.swg>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,482 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* director.swg
|
||||
*
|
||||
* This file contains support for director classes that proxy
|
||||
* method calls from C++ to Python extensions.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SWIG_DIRECTOR_PYTHON_HEADER_
|
||||
#define SWIG_DIRECTOR_PYTHON_HEADER_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#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 swift
|
||||
*/
|
||||
#ifndef SWIG_DIRECTOR_NO_UEH
|
||||
#ifndef SWIG_DIRECTOR_UEH
|
||||
#define SWIG_DIRECTOR_UEH
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
|
||||
'Swig' namespace. This could be usefull for multi-modules projects.
|
||||
*/
|
||||
#ifdef SWIG_DIRECTOR_STATIC
|
||||
/* Force anonymous (static) namespace */
|
||||
#define Swig
|
||||
#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
|
||||
#include <map>
|
||||
|
||||
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() = 0;
|
||||
|
||||
virtual int get_own() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
GCItem::~GCItem()
|
||||
{
|
||||
}
|
||||
|
||||
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 {
|
||||
protected:
|
||||
std::string swig_msg;
|
||||
public:
|
||||
DirectorException(PyObject *error, const char* hdr ="", const char* msg ="")
|
||||
: swig_msg(hdr)
|
||||
{
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
if (strlen(msg)) {
|
||||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
if (!PyErr_Occurred()) {
|
||||
swig_msg.insert(0, ": ");
|
||||
PyErr_SetString(error, getMessage());
|
||||
} else {
|
||||
SWIG_Python_AddErrorMsg(getMessage());
|
||||
}
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
|
||||
const char *getMessage() const
|
||||
{
|
||||
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.getMessage() << 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 like 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 Swig::DirectorException {
|
||||
public:
|
||||
DirectorTypeMismatchException(PyObject *error, const char* msg="")
|
||||
: Swig::DirectorException(error, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
DirectorTypeMismatchException(const char* msg="")
|
||||
: Swig::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 Swig::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 Swig::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, optionally taking ownership */
|
||||
Director(PyObject* self) : swig_self(self), swig_disown_flag(false) {
|
||||
swig_incref();
|
||||
}
|
||||
|
||||
|
||||
/* 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* /* name */) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void swig_set_inner(const char* /* name */, bool /* val */) const {
|
||||
}
|
||||
|
||||
/* ownership management */
|
||||
private:
|
||||
typedef std::map<void*, GCItem_var> ownership_map;
|
||||
mutable ownership_map 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);
|
||||
owner[vptr] = new GCArray_T<Type>(vptr);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void swig_acquire_ownership(Type *vptr) const
|
||||
{
|
||||
if (vptr) {
|
||||
SWIG_GUARD(swig_mutex_own);
|
||||
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);
|
||||
owner[vptr] = new GCItem_Object(own);
|
||||
}
|
||||
}
|
||||
|
||||
int swig_release_ownership(void *vptr) const
|
||||
{
|
||||
int own = 0;
|
||||
if (vptr) {
|
||||
SWIG_GUARD(swig_mutex_own);
|
||||
ownership_map::iterator iter = owner.find(vptr);
|
||||
if (iter != owner.end()) {
|
||||
own = iter->second->get_own();
|
||||
owner.erase(iter);
|
||||
}
|
||||
}
|
||||
return own;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __THREAD__
|
||||
PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// embed15.i
|
||||
// SWIG file embedding the Python interpreter in something else.
|
||||
// This file is based on Python-1.5. It will not work with
|
||||
// earlier versions.
|
||||
//
|
||||
// This file makes it possible to extend Python and all of its
|
||||
// built-in functions without having to hack it's 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.
|
||||
|
||||
This library file only works with Python 1.5. A version
|
||||
compatible with Python 1.4 is available as embed14.i and
|
||||
a Python1.3 version is available as embed13.i. As far as
|
||||
I know, this module is C++ safe.
|
||||
%}
|
||||
#else
|
||||
%echo "embed.i : Using Python 1.5"
|
||||
#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 build 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);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* embed15.i
|
||||
*
|
||||
* SWIG file embedding the Python interpreter in something else.
|
||||
* This file is based on Python-1.5. It will not work with
|
||||
* earlier versions.
|
||||
*
|
||||
* This file makes it possible to extend Python and all of its
|
||||
* built-in functions without having to hack it's 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.
|
||||
|
||||
This library file only works with Python 1.5. A version
|
||||
compatible with Python 1.4 is available as embed14.i and
|
||||
a Python1.3 version is available as embed13.i. As far as
|
||||
I know, this module is C++ safe.
|
||||
%}
|
||||
#else
|
||||
%echo "embed.i : Using Python 1.5"
|
||||
#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 build 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);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
%include <typemaps/exception.swg>
|
||||
|
||||
|
||||
%insert("runtime") {
|
||||
%define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; ))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/factory.swg>
|
||||
@@ -0,0 +1,43 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* file.i
|
||||
*
|
||||
* Typemaps for FILE*
|
||||
* From the ideas of Luigi Ballabio
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%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 (PyFile_Check(obj)) {
|
||||
if (val) *val = PyFile_AsFile(obj);
|
||||
return SWIG_OK;
|
||||
}
|
||||
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*);
|
||||
@@ -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."
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
%include <typemaps/valtypes.swg>
|
||||
|
||||
%fragment(SWIG_AsVal_frag(jstring),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(jstring)(PyObject *obj, jstring *val)
|
||||
{
|
||||
if (obj == Py_None) {
|
||||
if (val) *val = 0;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
PyObject *tmp = 0;
|
||||
int isunicode = PyUnicode_Check(obj);
|
||||
if (!isunicode && PyString_Check(obj)) {
|
||||
if (val) {
|
||||
obj = tmp = PyUnicode_FromObject(obj);
|
||||
}
|
||||
isunicode = 1;
|
||||
}
|
||||
if (isunicode) {
|
||||
if (val) {
|
||||
if (sizeof(Py_UNICODE) == sizeof(jchar)) {
|
||||
*val = JvNewString((const jchar *) PyUnicode_AS_UNICODE(obj),PyUnicode_GET_SIZE(obj));
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
int len = PyUnicode_GET_SIZE(obj);
|
||||
Py_UNICODE *pchars = PyUnicode_AS_UNICODE(obj);
|
||||
*val = JvAllocString (len);
|
||||
jchar *jchars = JvGetStringChars (*val);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
jchars[i] = pchars[i];
|
||||
}
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
}
|
||||
Py_XDECREF(tmp);
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(jstring),"header") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_From(jstring)(jstring val)
|
||||
{
|
||||
if (!val) {
|
||||
return SWIG_Py_Void();
|
||||
}
|
||||
if (sizeof(Py_UNICODE) == sizeof(jchar)) {
|
||||
return PyUnicode_FromUnicode((const Py_UNICODE *) JvGetStringChars(val),
|
||||
JvGetStringUTFLength(val));
|
||||
} else {
|
||||
int len = JvGetStringUTFLength(val);
|
||||
Py_UNICODE pchars[len];
|
||||
jchar *jchars = JvGetStringChars(val);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
pchars[i] = jchars[i];
|
||||
}
|
||||
return PyUnicode_FromUnicode((const Py_UNICODE *) pchars, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%typemaps_asvalfrom(%checkcode(STRING),
|
||||
%arg(SWIG_AsVal(jstring)),
|
||||
%arg(SWIG_From(jstring)),
|
||||
%arg(SWIG_AsVal_frag(jstring)),
|
||||
%arg(SWIG_From_frag(jstring)),
|
||||
java::lang::String *);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Python API portion that goes into the runtime
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* cc-mode */
|
||||
#endif
|
||||
#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;
|
||||
char *name;
|
||||
long lvalue;
|
||||
double dvalue;
|
||||
void *pvalue;
|
||||
swig_type_info **ptype;
|
||||
} swig_const_info;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if 0
|
||||
{ /* cc-mode */
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
/*
|
||||
PyObject_ptr is used as a replacement of PyObject *, where
|
||||
the INCREF/DECREF are applied as needed.
|
||||
|
||||
You can use PyObject_ptr in a container, such as
|
||||
|
||||
std::vector<PyObject_ptr>;
|
||||
|
||||
or as a member variable:
|
||||
|
||||
struct A {
|
||||
PyObject_ptr obj;
|
||||
A(PyObject *o) : _obj(o) {
|
||||
}
|
||||
};
|
||||
|
||||
or as a input/output value
|
||||
|
||||
PyObject_ptr func(PyObject_ptr obj) {
|
||||
PyObject_ptr 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 PyObject_ptr always add
|
||||
one reference at construction.
|
||||
|
||||
PyObject_ptr is 'visible' at the wrapped side, so you can do:
|
||||
|
||||
|
||||
%template(pyvector) std::vector<swig::PyObject_ptr>;
|
||||
|
||||
and all the proper typemaps will be used.
|
||||
|
||||
*/
|
||||
|
||||
namespace swig {
|
||||
%ignore PyObject_ptr;
|
||||
struct PyObject_ptr {};
|
||||
%apply PyObject * {PyObject_ptr};
|
||||
%apply PyObject * const& {PyObject_ptr const&};
|
||||
|
||||
/* For output */
|
||||
%typemap(out,noblock=1) PyObject_ptr {
|
||||
$result = (PyObject *)$1;
|
||||
Py_INCREF($result);
|
||||
}
|
||||
|
||||
%typemap(out,noblock=1) PyObject_ptr const & {
|
||||
$result = (PyObject *)*$1;
|
||||
Py_INCREF($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%{
|
||||
namespace swig {
|
||||
class PyObject_ptr {
|
||||
protected:
|
||||
PyObject *_obj;
|
||||
|
||||
public:
|
||||
PyObject_ptr() :_obj(0)
|
||||
{
|
||||
}
|
||||
|
||||
PyObject_ptr(const PyObject_ptr& item) : _obj(item._obj)
|
||||
{
|
||||
Py_XINCREF(_obj);
|
||||
}
|
||||
|
||||
PyObject_ptr(PyObject *obj, bool initial_ref = true) :_obj(obj)
|
||||
{
|
||||
if (initial_ref) Py_XINCREF(_obj);
|
||||
}
|
||||
|
||||
PyObject_ptr & operator=(const PyObject_ptr& item)
|
||||
{
|
||||
Py_XINCREF(item._obj);
|
||||
Py_XDECREF(_obj);
|
||||
_obj = item._obj;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~PyObject_ptr()
|
||||
{
|
||||
Py_XDECREF(_obj);
|
||||
}
|
||||
|
||||
operator PyObject *() const
|
||||
{
|
||||
return _obj;
|
||||
}
|
||||
|
||||
PyObject *operator->() const
|
||||
{
|
||||
return _obj;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
/*
|
||||
PyObject_var is used to manage 'in the scope' PyObject * variables,
|
||||
as in
|
||||
|
||||
int func () {
|
||||
PyObject_var 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.
|
||||
|
||||
PyObject_var 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 PyObject_var;
|
||||
struct PyObject_var {};
|
||||
%apply PyObject * {PyObject_var};
|
||||
%apply PyObject * const& {PyObject_var const&};
|
||||
}
|
||||
|
||||
%{
|
||||
namespace swig {
|
||||
struct PyObject_var : PyObject_ptr {
|
||||
PyObject_var(PyObject* obj = 0) : PyObject_ptr(obj, false) { }
|
||||
|
||||
PyObject_var & operator = (PyObject* obj)
|
||||
{
|
||||
Py_XDECREF(_obj);
|
||||
_obj = obj;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Defines the As/From conversors for double/float complex, you need to
|
||||
provide complex Type, the Name you want to use in the conversors,
|
||||
the complex Constructor method, and the Real and Imag complex
|
||||
accesor methods.
|
||||
|
||||
See the std_complex.i and ccomplex.i for concret examples.
|
||||
*/
|
||||
|
||||
/* the common from conversor */
|
||||
%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)
|
||||
|
||||
|
||||
@@ -0,0 +1,766 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pycontainer.swg
|
||||
*
|
||||
* Python sequence <-> C++ container wrapper
|
||||
*
|
||||
* This wrapper, and its iterator, allows a general use (and reuse) of
|
||||
* the the mapping between C++ and Python, thanks to the C++
|
||||
* templates.
|
||||
*
|
||||
* Of course, it needs the C++ compiler to support templates, but
|
||||
* since we will use this wrapper with the STL containers, that should
|
||||
* be the case.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
|
||||
#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS)
|
||||
# if !defined(SWIG_EXPORT_ITERATOR_METHODS)
|
||||
# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
%include <pyiterators.swg>
|
||||
|
||||
/**** The PySequence C++ Wrap ***/
|
||||
|
||||
%insert(header) %{
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
%include <std_except.i>
|
||||
|
||||
%fragment(SWIG_Traits_frag(swig::PyObject_ptr),"header",fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<PyObject_ptr > {
|
||||
typedef value_category category;
|
||||
static const char* type_name() { return "PyObject_ptr"; }
|
||||
};
|
||||
|
||||
template <> struct traits_from<PyObject_ptr> {
|
||||
typedef PyObject_ptr value_type;
|
||||
static PyObject *from(const value_type& val) {
|
||||
PyObject *obj = static_cast<PyObject *>(val);
|
||||
Py_XINCREF(obj);
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<PyObject_ptr, value_category> {
|
||||
static bool check(PyObject_ptr) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct traits_asval<PyObject_ptr > {
|
||||
typedef PyObject_ptr value_type;
|
||||
static int asval(PyObject *obj, value_type *val) {
|
||||
if (val) *val = obj;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_Traits_frag(swig::PyObject_var),"header",fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<PyObject_var > {
|
||||
typedef value_category category;
|
||||
static const char* type_name() { return "PyObject_var"; }
|
||||
};
|
||||
|
||||
template <> struct traits_from<PyObject_var> {
|
||||
typedef PyObject_var value_type;
|
||||
static PyObject *from(const value_type& val) {
|
||||
PyObject *obj = static_cast<PyObject *>(val);
|
||||
Py_XINCREF(obj);
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<PyObject_var, value_category> {
|
||||
static bool check(PyObject_var) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct traits_asval<PyObject_var > {
|
||||
typedef PyObject_var value_type;
|
||||
static int asval(PyObject *obj, value_type *val) {
|
||||
if (val) *val = obj;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("PySequence_Base","header")
|
||||
{
|
||||
%#include <functional>
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct less <PyObject *>: public binary_function<PyObject *, PyObject *, bool>
|
||||
{
|
||||
bool
|
||||
operator()(PyObject * v, PyObject *w) const
|
||||
{
|
||||
bool res;
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
res = PyObject_Compare(v, w) < 0;
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct less <swig::PyObject_ptr>: public binary_function<swig::PyObject_ptr, swig::PyObject_ptr, bool>
|
||||
{
|
||||
bool
|
||||
operator()(const swig::PyObject_ptr& v, const swig::PyObject_ptr& w) const
|
||||
{
|
||||
return std::less<PyObject *>()(v, w);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct less <swig::PyObject_var>: public binary_function<swig::PyObject_var, swig::PyObject_var, bool>
|
||||
{
|
||||
bool
|
||||
operator()(const swig::PyObject_var& v, const swig::PyObject_var& w) const
|
||||
{
|
||||
return std::less<PyObject *>()(v, w);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace swig {
|
||||
template <> struct traits<PyObject *> {
|
||||
typedef value_category category;
|
||||
static const char* type_name() { return "PyObject *"; }
|
||||
};
|
||||
|
||||
template <> struct traits_asval<PyObject * > {
|
||||
typedef PyObject * value_type;
|
||||
static int asval(PyObject *obj, value_type *val) {
|
||||
if (val) *val = obj;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<PyObject *, value_category> {
|
||||
static bool check(PyObject *) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct traits_from<PyObject *> {
|
||||
typedef PyObject * value_type;
|
||||
static PyObject *from(const value_type& val) {
|
||||
Py_XINCREF(val);
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace swig {
|
||||
inline size_t
|
||||
check_index(ptrdiff_t i, size_t size, bool insert = false) {
|
||||
if ( i < 0 ) {
|
||||
if ((size_t) (-i) <= size)
|
||||
return (size_t) (i + size);
|
||||
} else if ( (size_t) i < size ) {
|
||||
return (size_t) i;
|
||||
} else if (insert && ((size_t) i == size)) {
|
||||
return size;
|
||||
}
|
||||
|
||||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
|
||||
inline size_t
|
||||
slice_index(ptrdiff_t i, size_t size) {
|
||||
if ( i < 0 ) {
|
||||
if ((size_t) (-i) <= size) {
|
||||
return (size_t) (i + size);
|
||||
} else {
|
||||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
} else {
|
||||
return ( (size_t) i < size ) ? ((size_t) i) : size;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference>
|
||||
inline typename Sequence::iterator
|
||||
getpos(Sequence* self, Difference i) {
|
||||
typename Sequence::iterator pos = self->begin();
|
||||
std::advance(pos, check_index(i,self->size()));
|
||||
return pos;
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference>
|
||||
inline typename Sequence::const_iterator
|
||||
cgetpos(const Sequence* self, Difference i) {
|
||||
typename Sequence::const_iterator pos = self->begin();
|
||||
std::advance(pos, check_index(i,self->size()));
|
||||
return pos;
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference>
|
||||
inline Sequence*
|
||||
getslice(const Sequence* self, Difference i, Difference j) {
|
||||
typename Sequence::size_type size = self->size();
|
||||
typename Sequence::size_type ii = swig::check_index(i, size);
|
||||
typename Sequence::size_type jj = swig::slice_index(j, size);
|
||||
|
||||
if (jj > ii) {
|
||||
typename Sequence::const_iterator vb = self->begin();
|
||||
typename Sequence::const_iterator ve = self->begin();
|
||||
std::advance(vb,ii);
|
||||
std::advance(ve,jj);
|
||||
return new Sequence(vb, ve);
|
||||
} else {
|
||||
return new Sequence();
|
||||
}
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference, class InputSeq>
|
||||
inline void
|
||||
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) {
|
||||
typename Sequence::size_type size = self->size();
|
||||
typename Sequence::size_type ii = swig::check_index(i, size, true);
|
||||
typename Sequence::size_type jj = swig::slice_index(j, size);
|
||||
if (jj < ii) jj = ii;
|
||||
size_t ssize = jj - ii;
|
||||
if (ssize <= v.size()) {
|
||||
typename Sequence::iterator sb = self->begin();
|
||||
typename InputSeq::const_iterator vmid = v.begin();
|
||||
std::advance(sb,ii);
|
||||
std::advance(vmid, jj - ii);
|
||||
self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end());
|
||||
} else {
|
||||
typename Sequence::iterator sb = self->begin();
|
||||
typename Sequence::iterator se = self->begin();
|
||||
std::advance(sb,ii);
|
||||
std::advance(se,jj);
|
||||
self->erase(sb,se);
|
||||
self->insert(sb, v.begin(), v.end());
|
||||
}
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference>
|
||||
inline void
|
||||
delslice(Sequence* self, Difference i, Difference j) {
|
||||
typename Sequence::size_type size = self->size();
|
||||
typename Sequence::size_type ii = swig::check_index(i, size, true);
|
||||
typename Sequence::size_type jj = swig::slice_index(j, size);
|
||||
if (jj > ii) {
|
||||
typename Sequence::iterator sb = self->begin();
|
||||
typename Sequence::iterator se = self->begin();
|
||||
std::advance(sb,ii);
|
||||
std::advance(se,jj);
|
||||
self->erase(sb,se);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("PySequence_Cont","header",
|
||||
fragment="StdTraits",
|
||||
fragment="PySequence_Base",
|
||||
fragment="PySwigIterator_T")
|
||||
{
|
||||
namespace swig
|
||||
{
|
||||
template <class T>
|
||||
struct PySequence_Ref
|
||||
{
|
||||
PySequence_Ref(PyObject* seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
operator T () const
|
||||
{
|
||||
swig::PyObject_var item = PySequence_GetItem(_seq, _index);
|
||||
try {
|
||||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d ", _index);
|
||||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<T>());
|
||||
}
|
||||
SWIG_Python_AddErrorMsg(msg);
|
||||
SWIG_Python_AddErrorMsg(e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
PySequence_Ref& operator=(const T& v)
|
||||
{
|
||||
PySequence_SetItem(_seq, _index, swig::from<T>(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
int _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct PySequence_ArrowProxy
|
||||
{
|
||||
PySequence_ArrowProxy(const T& x): m_value(x) {}
|
||||
const T* operator->() const { return &m_value; }
|
||||
operator const T*() const { return &m_value; }
|
||||
T m_value;
|
||||
};
|
||||
|
||||
template <class T, class Reference >
|
||||
struct PySequence_InputIterator
|
||||
{
|
||||
typedef PySequence_InputIterator<T, Reference > self;
|
||||
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef Reference reference;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef int difference_type;
|
||||
|
||||
PySequence_InputIterator()
|
||||
{
|
||||
}
|
||||
|
||||
PySequence_InputIterator(PyObject* seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return reference(_seq, _index);
|
||||
}
|
||||
|
||||
PySequence_ArrowProxy<T>
|
||||
operator->() const {
|
||||
return PySequence_ArrowProxy<T>(operator*());
|
||||
}
|
||||
|
||||
bool operator==(const self& ri) const
|
||||
{
|
||||
return (_index == ri._index) && (_seq == ri._seq);
|
||||
}
|
||||
|
||||
bool operator!=(const self& ri) const
|
||||
{
|
||||
return !(operator==(ri));
|
||||
}
|
||||
|
||||
self& operator ++ ()
|
||||
{
|
||||
++_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& operator -- ()
|
||||
{
|
||||
--_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& operator += (difference_type n)
|
||||
{
|
||||
_index += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self operator +(difference_type n) const
|
||||
{
|
||||
return self(_seq, _index + n);
|
||||
}
|
||||
|
||||
self& operator -= (difference_type n)
|
||||
{
|
||||
_index -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self operator -(difference_type n) const
|
||||
{
|
||||
return self(_seq, _index - n);
|
||||
}
|
||||
|
||||
difference_type operator - (const self& ri) const
|
||||
{
|
||||
return _index - ri._index;
|
||||
}
|
||||
|
||||
bool operator < (const self& ri) const
|
||||
{
|
||||
return _index < ri._index;
|
||||
}
|
||||
|
||||
reference
|
||||
operator[](difference_type n) const
|
||||
{
|
||||
return reference(_seq, _index + n);
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
difference_type _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct PySequence_Cont
|
||||
{
|
||||
typedef PySequence_Ref<T> reference;
|
||||
typedef const PySequence_Ref<T> const_reference;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef int difference_type;
|
||||
typedef int size_type;
|
||||
typedef const pointer const_pointer;
|
||||
typedef PySequence_InputIterator<T, reference> iterator;
|
||||
typedef PySequence_InputIterator<T, const_reference> const_iterator;
|
||||
|
||||
PySequence_Cont(PyObject* seq) : _seq(0)
|
||||
{
|
||||
if (!PySequence_Check(seq)) {
|
||||
throw std::invalid_argument("a sequence is expected");
|
||||
}
|
||||
_seq = seq;
|
||||
Py_INCREF(_seq);
|
||||
}
|
||||
|
||||
~PySequence_Cont()
|
||||
{
|
||||
if (_seq) Py_DECREF(_seq);
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return static_cast<size_type>(PySequence_Size(_seq));
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(_seq, 0);
|
||||
}
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(_seq, 0);
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return iterator(_seq, size());
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator(_seq, size());
|
||||
}
|
||||
|
||||
reference operator[](difference_type n)
|
||||
{
|
||||
return reference(_seq, n);
|
||||
}
|
||||
|
||||
const_reference operator[](difference_type n) const
|
||||
{
|
||||
return const_reference(_seq, n);
|
||||
}
|
||||
|
||||
bool check(bool set_err = true) const
|
||||
{
|
||||
int s = size();
|
||||
for (int i = 0; i < s; ++i) {
|
||||
swig::PyObject_var item = PySequence_GetItem(_seq, i);
|
||||
if (!swig::check<value_type>(item)) {
|
||||
if (set_err) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d", i);
|
||||
SWIG_Error(SWIG_RuntimeError, msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_sequence_iterator(Sequence...)
|
||||
#if defined(SWIG_EXPORT_ITERATOR_METHODS)
|
||||
class iterator;
|
||||
class reverse_iterator;
|
||||
class const_iterator;
|
||||
class const_reverse_iterator;
|
||||
|
||||
%typemap(out,noblock=1,fragment="PySequence_Cont")
|
||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
$result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)),
|
||||
swig::PySwigIterator::descriptor(),SWIG_POINTER_OWN);
|
||||
}
|
||||
%typemap(out,noblock=1,fragment="PySequence_Cont")
|
||||
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::PySwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
||||
swig::PySwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
}
|
||||
|
||||
%fragment("PyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="PySequence_Cont") {}
|
||||
|
||||
%typemap(out,noblock=1,fragment="PyPairBoolOutputIterator")
|
||||
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::PySwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
|
||||
}
|
||||
|
||||
%typemap(in,noblock=1,fragment="PySequence_Cont")
|
||||
iterator(swig::PySwigIterator *iter = 0, int res),
|
||||
reverse_iterator(swig::PySwigIterator *iter = 0, int res),
|
||||
const_iterator(swig::PySwigIterator *iter = 0, int res),
|
||||
const_reverse_iterator(swig::PySwigIterator *iter = 0, int res) {
|
||||
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::PySwigIterator::descriptor(), 0);
|
||||
if (!SWIG_IsOK(res) || !iter) {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
} else {
|
||||
swig::PySwigIterator_T<$type > *iter_t = dynamic_cast<swig::PySwigIterator_T<$type > *>(iter);
|
||||
if (iter_t) {
|
||||
$1 = iter_t->get_current();
|
||||
} else {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="PySequence_Cont")
|
||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
swig::PySwigIterator *iter = 0;
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::PySwigIterator::descriptor(), 0);
|
||||
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::PySwigIterator_T<$type > *>(iter) != 0));
|
||||
}
|
||||
|
||||
%fragment("PySequence_Cont");
|
||||
|
||||
%newobject iterator(PyObject **PYTHON_SELF);
|
||||
%extend {
|
||||
swig::PySwigIterator* iterator(PyObject **PYTHON_SELF) {
|
||||
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
|
||||
}
|
||||
|
||||
%pythoncode {def __iter__(self): return self.iterator()}
|
||||
}
|
||||
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
||||
%enddef
|
||||
|
||||
|
||||
/**** The python container methods ****/
|
||||
|
||||
|
||||
%define %swig_container_methods(Container...)
|
||||
|
||||
%newobject __getslice__;
|
||||
|
||||
%extend {
|
||||
bool __nonzero__() const {
|
||||
return !(self->empty());
|
||||
}
|
||||
|
||||
size_type __len__() const {
|
||||
return self->size();
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %swig_sequence_methods_common(Sequence...)
|
||||
%swig_sequence_iterator(%arg(Sequence))
|
||||
%swig_container_methods(%arg(Sequence))
|
||||
|
||||
%fragment("PySequence_Base");
|
||||
|
||||
%extend {
|
||||
value_type pop() throw (std::out_of_range) {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty container");
|
||||
Sequence::value_type x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
|
||||
Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) {
|
||||
return swig::getslice(self, i, j);
|
||||
}
|
||||
|
||||
void __setslice__(difference_type i, difference_type j, const Sequence& v)
|
||||
throw (std::out_of_range, std::invalid_argument) {
|
||||
swig::setslice(self, i, j, v);
|
||||
}
|
||||
|
||||
void __delslice__(difference_type i, difference_type j) throw (std::out_of_range) {
|
||||
swig::delslice(self, i, j);
|
||||
}
|
||||
|
||||
void __delitem__(difference_type i) throw (std::out_of_range) {
|
||||
self->erase(swig::getpos(self,i));
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %swig_sequence_methods(Sequence...)
|
||||
%swig_sequence_methods_common(%arg(Sequence))
|
||||
%extend {
|
||||
const value_type& __getitem__(difference_type i) const throw (std::out_of_range) {
|
||||
return *(swig::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(difference_type i, const value_type& x) throw (std::out_of_range) {
|
||||
*(swig::getpos(self,i)) = x;
|
||||
}
|
||||
|
||||
void append(const value_type& x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %swig_sequence_methods_val(Sequence...)
|
||||
%swig_sequence_methods_common(%arg(Sequence))
|
||||
%extend {
|
||||
value_type __getitem__(difference_type i) throw (std::out_of_range) {
|
||||
return *(swig::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(difference_type i, value_type x) throw (std::out_of_range) {
|
||||
*(swig::getpos(self,i)) = x;
|
||||
}
|
||||
|
||||
void append(value_type x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Common fragments
|
||||
//
|
||||
|
||||
%fragment("StdSequenceTraits","header",
|
||||
fragment="StdTraits",
|
||||
fragment="PySequence_Cont")
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class Seq>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, Seq* seq) {
|
||||
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
seq->insert(seq->end(),(value_type)(*it));
|
||||
}
|
||||
%#else
|
||||
seq->assign(pyseq.begin(), pyseq.end());
|
||||
%#endif
|
||||
}
|
||||
|
||||
template <class Seq, class T = typename Seq::value_type >
|
||||
struct traits_asptr_stdseq {
|
||||
typedef Seq sequence;
|
||||
typedef T value_type;
|
||||
|
||||
static int asptr(PyObject *obj, sequence **seq) {
|
||||
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
|
||||
sequence *p;
|
||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
if (seq) *seq = p;
|
||||
return SWIG_OLDOBJ;
|
||||
}
|
||||
} else if (PySequence_Check(obj)) {
|
||||
try {
|
||||
PySequence_Cont<value_type> pyseq(obj);
|
||||
if (seq) {
|
||||
sequence *pseq = new sequence();
|
||||
assign(pyseq, pseq);
|
||||
*seq = pseq;
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
return pyseq.check() ? SWIG_OK : SWIG_ERROR;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
if (seq) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, e.what());
|
||||
}
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Seq, class T = typename Seq::value_type >
|
||||
struct traits_from_stdseq {
|
||||
typedef Seq sequence;
|
||||
typedef T value_type;
|
||||
typedef typename Seq::size_type size_type;
|
||||
typedef typename sequence::const_iterator const_iterator;
|
||||
|
||||
static PyObject *from(const sequence& seq) {
|
||||
#ifdef SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
|
||||
swig_type_info *desc = swig::type_info<sequence>();
|
||||
if (desc && desc->clientdata) {
|
||||
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
||||
}
|
||||
#endif
|
||||
size_type size = seq.size();
|
||||
if (size <= (size_type)INT_MAX) {
|
||||
PyObject *obj = PyTuple_New((int)size);
|
||||
int i = 0;
|
||||
for (const_iterator it = seq.begin();
|
||||
it != seq.end(); ++it, ++i) {
|
||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
// basic doc for primitive types....
|
||||
|
||||
#ifdef SWIG_DOC_DOXYGEN_STYLE
|
||||
%typemap(doc) SWIGTYPE "@param $1_name $1_type value";
|
||||
%typemap(doc) SWIGTYPE* "@param $1_name $1_type value";
|
||||
%typemap(doc) const SWIGTYPE& "@param $1_name $1_type value";
|
||||
%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type value";
|
||||
#else
|
||||
%typemap(doc) SWIGTYPE "$1_name: $1_type value";
|
||||
%typemap(doc) SWIGTYPE* "$1_name: $1_type value";
|
||||
%typemap(doc) const SWIGTYPE& "$1_name: $1_type value";
|
||||
%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type value";
|
||||
|
||||
%typemap(doc) SWIGTYPE *INOUT "$1_name: $1_type input/ouput value";
|
||||
%typemap(doc) SWIGTYPE *INPUT "$1_name: $1_type input value";
|
||||
%typemap(doc) SWIGTYPE *OUTPUT "$1_name: $1_type output value";
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* 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);
|
||||
PyErr_Clear();
|
||||
Py_XINCREF(type);
|
||||
PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
|
||||
Py_DECREF(old_str);
|
||||
Py_DECREF(value);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError, mesg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
/* Add PyOS_snprintf for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
|
||||
# define PyOS_snprintf _snprintf
|
||||
# else
|
||||
# define PyOS_snprintf snprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* A crude PyString_FromFormat implementation for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
|
||||
#ifndef SWIG_PYBUFFER_SIZE
|
||||
# define SWIG_PYBUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
PyString_FromFormat(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[SWIG_PYBUFFER_SIZE * 2];
|
||||
int res;
|
||||
va_start(ap, fmt);
|
||||
res = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add PyObject_Del for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x01060000
|
||||
# define PyObject_Del(op) PyMem_DEL((op))
|
||||
#endif
|
||||
#ifndef PyObject_DEL
|
||||
# define PyObject_DEL PyObject_Del
|
||||
#endif
|
||||
|
||||
/* A crude PyExc_StopIteration exception for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
# ifndef PyExc_StopIteration
|
||||
# define PyExc_StopIteration PyExc_RuntimeError
|
||||
# endif
|
||||
# ifndef PyObject_GenericGetAttr
|
||||
# define PyObject_GenericGetAttr 0
|
||||
# endif
|
||||
#endif
|
||||
/* Py_NotImplemented is defined in 2.1 and up. */
|
||||
#if PY_VERSION_HEX < 0x02010000
|
||||
# ifndef Py_NotImplemented
|
||||
# define Py_NotImplemented PyExc_RuntimeError
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* A crude PyString_AsStringAndSize implementation for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02010000
|
||||
# ifndef PyString_AsStringAndSize
|
||||
# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* PySequence_Size for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02000000
|
||||
# ifndef PySequence_Size
|
||||
# define PySequence_Size PySequence_Length
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* PyBool_FromLong for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02030000
|
||||
static
|
||||
PyObject *PyBool_FromLong(long ok)
|
||||
{
|
||||
PyObject *result = ok ? Py_True : Py_False;
|
||||
Py_INCREF(result);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Py_ssize_t for old Pythons */
|
||||
/* This code is as recommended by: */
|
||||
/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */
|
||||
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
|
||||
typedef int Py_ssize_t;
|
||||
# define PY_SSIZE_T_MAX INT_MAX
|
||||
# define PY_SSIZE_T_MIN INT_MIN
|
||||
#endif
|
||||
@@ -0,0 +1,288 @@
|
||||
/* ------------------------------------------------------------
|
||||
* The start of the Python initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%insert(init) "swiginit.swg"
|
||||
|
||||
%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)) {
|
||||
return PyString_FromString("<Swig global variables>");
|
||||
}
|
||||
|
||||
SWIGINTERN PyObject *
|
||||
swig_varlink_str(swig_varlinkobject *v) {
|
||||
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(")"));
|
||||
return str;
|
||||
}
|
||||
|
||||
SWIGINTERN int
|
||||
swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) {
|
||||
PyObject *str = swig_varlink_str(v);
|
||||
fprintf(fp,"Swig global variables ");
|
||||
fprintf(fp,"%s\n", PyString_AsString(str));
|
||||
Py_DECREF(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_SetString(PyExc_NameError,"Unknown C global variable");
|
||||
}
|
||||
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_SetString(PyExc_NameError,"Unknown C global variable");
|
||||
}
|
||||
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
|
||||
= {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* Number of items in variable part (ob_size) */
|
||||
(char *)"swigvarlink", /* Type name (tp_name) */
|
||||
sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */
|
||||
0, /* Itemsize (tp_itemsize) */
|
||||
(destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */
|
||||
(printfunc) swig_varlink_print, /* Print (tp_print) */
|
||||
(getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */
|
||||
(setattrfunc) swig_varlink_setattr, /* Set attr (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 */
|
||||
#if PY_VERSION_HEX >= 0x02020000
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
|
||||
#endif
|
||||
#if PY_VERSION_HEX >= 0x02030000
|
||||
0, /* tp_del */
|
||||
#endif
|
||||
#ifdef COUNT_ALLOCS
|
||||
0,0,0,0 /* tp_alloc -> tp_next */
|
||||
#endif
|
||||
};
|
||||
varlink_type = tmp;
|
||||
varlink_type.ob_type = &PyType_Type;
|
||||
type_init = 1;
|
||||
}
|
||||
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, 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) {
|
||||
strncpy(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 *_SWIG_globals = 0;
|
||||
if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink();
|
||||
return _SWIG_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_NewPointerObj(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 && (c = strstr(c, "swig_ptr: "))) {
|
||||
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) {
|
||||
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;
|
||||
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
|
||||
if (ptr) {
|
||||
strncpy(buff, methods[i].ml_doc, ldoc);
|
||||
buff += ldoc;
|
||||
strncpy(buff, "swig_ptr: ", 10);
|
||||
buff += 10;
|
||||
SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
|
||||
methods[i].ml_doc = ndoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Partial Init method
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
SWIGEXPORT void SWIG_init(void) {
|
||||
PyObject *m, *d;
|
||||
|
||||
/* Fix SwigMethods to carry the callback ptrs when needed */
|
||||
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
|
||||
|
||||
m = Py_InitModule((char *) SWIG_name, SwigMethods);
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
SWIG_InitializeModule(0);
|
||||
SWIG_InstallConstants(d,swig_const_table);
|
||||
|
||||
%}
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pyiterators.swg
|
||||
*
|
||||
* Implement a python 'output' iterator for Python 2.2 or higher.
|
||||
*
|
||||
* Users can derive form the PySwigIterator to implemet their
|
||||
* own iterators. As an example (real one since we use it for STL/STD
|
||||
* containers), the template PySwigIterator_T does the
|
||||
* implementation for genereic C++ iterators.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
%fragment("PySwigIterator","header") {
|
||||
namespace swig {
|
||||
struct stop_iteration {
|
||||
};
|
||||
|
||||
struct PySwigIterator {
|
||||
private:
|
||||
PyObject_ptr _seq;
|
||||
|
||||
protected:
|
||||
PySwigIterator(PyObject *seq) : _seq(seq)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~PySwigIterator() {}
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual PyObject *value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual PySwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
virtual PySwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
throw stop_iteration();
|
||||
}
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const PySwigIterator &x) const
|
||||
{
|
||||
throw std::invalid_argument("operation not supported");
|
||||
}
|
||||
|
||||
virtual bool equal (const PySwigIterator &x) const
|
||||
{
|
||||
throw std::invalid_argument("operation not supported");
|
||||
}
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual PySwigIterator *copy() const = 0;
|
||||
|
||||
PyObject *next()
|
||||
{
|
||||
PyObject *obj = value();
|
||||
incr();
|
||||
return obj;
|
||||
}
|
||||
|
||||
PyObject *previous()
|
||||
{
|
||||
decr();
|
||||
return value();
|
||||
}
|
||||
|
||||
PySwigIterator *advance(ptrdiff_t n)
|
||||
{
|
||||
return (n > 0) ? incr(n) : decr(-n);
|
||||
}
|
||||
|
||||
bool operator == (const PySwigIterator& x) const
|
||||
{
|
||||
return equal(x);
|
||||
}
|
||||
|
||||
bool operator != (const PySwigIterator& x) const
|
||||
{
|
||||
return ! operator==(x);
|
||||
}
|
||||
|
||||
PySwigIterator& operator += (ptrdiff_t n)
|
||||
{
|
||||
return *advance(n);
|
||||
}
|
||||
|
||||
PySwigIterator& operator -= (ptrdiff_t n)
|
||||
{
|
||||
return *advance(-n);
|
||||
}
|
||||
|
||||
PySwigIterator* operator + (ptrdiff_t n) const
|
||||
{
|
||||
return copy()->advance(n);
|
||||
}
|
||||
|
||||
PySwigIterator* operator - (ptrdiff_t n) const
|
||||
{
|
||||
return copy()->advance(-n);
|
||||
}
|
||||
|
||||
ptrdiff_t operator - (const PySwigIterator& 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::PySwigIterator *");
|
||||
init = 1;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("PySwigIterator_T","header",fragment="PySwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
|
||||
namespace swig {
|
||||
template<typename OutIterator>
|
||||
class PySwigIterator_T : public PySwigIterator
|
||||
{
|
||||
public:
|
||||
typedef OutIterator out_iterator;
|
||||
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
|
||||
typedef PySwigIterator_T<out_iterator> self_type;
|
||||
|
||||
PySwigIterator_T(out_iterator curr, PyObject *seq)
|
||||
: PySwigIterator(seq), current(curr)
|
||||
{
|
||||
}
|
||||
|
||||
const out_iterator& get_current() const
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool equal (const PySwigIterator &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 PySwigIterator &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 PySwigIteratorOpen_T : public PySwigIterator_T<OutIterator>
|
||||
{
|
||||
public:
|
||||
FromOper from;
|
||||
typedef OutIterator out_iterator;
|
||||
typedef ValueType value_type;
|
||||
typedef PySwigIterator_T<out_iterator> base;
|
||||
typedef PySwigIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
|
||||
|
||||
PySwigIteratorOpen_T(out_iterator curr, PyObject *seq)
|
||||
: PySwigIterator_T<OutIterator>(curr, seq)
|
||||
{
|
||||
}
|
||||
|
||||
PyObject *value() const {
|
||||
return from(static_cast<const value_type&>(*(base::current)));
|
||||
}
|
||||
|
||||
PySwigIterator *copy() const
|
||||
{
|
||||
return new self_type(*this);
|
||||
}
|
||||
|
||||
PySwigIterator *incr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
++base::current;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
PySwigIterator *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 PySwigIteratorClosed_T : public PySwigIterator_T<OutIterator>
|
||||
{
|
||||
public:
|
||||
FromOper from;
|
||||
typedef OutIterator out_iterator;
|
||||
typedef ValueType value_type;
|
||||
typedef PySwigIterator_T<out_iterator> base;
|
||||
typedef PySwigIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
|
||||
|
||||
PySwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, PyObject *seq)
|
||||
: PySwigIterator_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)));
|
||||
}
|
||||
}
|
||||
|
||||
PySwigIterator *copy() const
|
||||
{
|
||||
return new self_type(*this);
|
||||
}
|
||||
|
||||
PySwigIterator *incr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
if (base::current == end) {
|
||||
throw stop_iteration();
|
||||
} else {
|
||||
++base::current;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
PySwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
if (base::current == begin) {
|
||||
throw stop_iteration();
|
||||
} else {
|
||||
--base::current;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private:
|
||||
out_iterator begin;
|
||||
out_iterator end;
|
||||
};
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, PyObject *seq = 0)
|
||||
{
|
||||
return new PySwigIteratorClosed_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_iterator(const OutIter& current, PyObject *seq = 0)
|
||||
{
|
||||
return new PySwigIteratorOpen_T<OutIter>(current, seq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment("PySwigIterator");
|
||||
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 PySwigIterator::copy;
|
||||
%newobject PySwigIterator::operator + (ptrdiff_t n) const;
|
||||
%newobject PySwigIterator::operator - (ptrdiff_t n) const;
|
||||
|
||||
%nodirector PySwigIterator;
|
||||
%extend PySwigIterator {
|
||||
%pythoncode {def __iter__(self): return self}
|
||||
}
|
||||
|
||||
%catches(swig::stop_iteration) PySwigIterator::value() const;
|
||||
%catches(swig::stop_iteration) PySwigIterator::incr(size_t n = 1);
|
||||
%catches(swig::stop_iteration) PySwigIterator::decr(size_t n = 1);
|
||||
%catches(std::invalid_argument) PySwigIterator::distance(const PySwigIterator &x) const;
|
||||
%catches(std::invalid_argument) PySwigIterator::equal (const PySwigIterator &x) const;
|
||||
%catches(swig::stop_iteration) PySwigIterator::next();
|
||||
%catches(swig::stop_iteration) PySwigIterator::previous();
|
||||
%catches(swig::stop_iteration) PySwigIterator::advance(ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) PySwigIterator::operator += (ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) PySwigIterator::operator -= (ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) PySwigIterator::operator + (ptrdiff_t n) const;
|
||||
%catches(swig::stop_iteration) PySwigIterator::operator - (ptrdiff_t n) const;
|
||||
|
||||
|
||||
struct PySwigIterator
|
||||
{
|
||||
protected:
|
||||
PySwigIterator(PyObject *seq);
|
||||
|
||||
public:
|
||||
virtual ~PySwigIterator();
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual PyObject *value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual PySwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
virtual PySwigIterator *decr(size_t n = 1);
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const PySwigIterator &x) const;
|
||||
|
||||
virtual bool equal (const PySwigIterator &x) const;
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual PySwigIterator *copy() const = 0;
|
||||
|
||||
PyObject *next();
|
||||
PyObject *previous();
|
||||
PySwigIterator *advance(ptrdiff_t n);
|
||||
|
||||
bool operator == (const PySwigIterator& x) const;
|
||||
bool operator != (const PySwigIterator& x) const;
|
||||
PySwigIterator& operator += (ptrdiff_t n);
|
||||
PySwigIterator& operator -= (ptrdiff_t n);
|
||||
PySwigIterator* operator + (ptrdiff_t n) const;
|
||||
PySwigIterator* operator - (ptrdiff_t n) const;
|
||||
ptrdiff_t operator - (const PySwigIterator& x) const;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
%include <typemaps/swigmacros.swg>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
|
||||
|
||||
%pybinoperator(__add__, *::operator+);
|
||||
%pybinoperator(__pos__, *::operator+());
|
||||
%pybinoperator(__pos__, *::operator+() const);
|
||||
%pybinoperator(__sub__, *::operator-);
|
||||
%pybinoperator(__neg__, *::operator-());
|
||||
%pybinoperator(__neg__, *::operator-() const);
|
||||
%pybinoperator(__mul__, *::operator*);
|
||||
%pybinoperator(__div__, *::operator/);
|
||||
%pybinoperator(__mod__, *::operator%);
|
||||
%pybinoperator(__lshift__, *::operator<<);
|
||||
%pybinoperator(__rshift__, *::operator>>);
|
||||
%pybinoperator(__and__, *::operator&);
|
||||
%pybinoperator(__or__, *::operator|);
|
||||
%pybinoperator(__xor__, *::operator^);
|
||||
%pybinoperator(__lt__, *::operator<);
|
||||
%pybinoperator(__le__, *::operator<=);
|
||||
%pybinoperator(__gt__, *::operator>);
|
||||
%pybinoperator(__ge__, *::operator>=);
|
||||
%pybinoperator(__eq__, *::operator==);
|
||||
%pybinoperator(__ne__, *::operator!=);
|
||||
|
||||
|
||||
|
||||
/* Special cases */
|
||||
%rename(__invert__) *::operator~;
|
||||
%rename(__call__) *::operator();
|
||||
|
||||
/* 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 'self' pointer, and assigning
|
||||
it to the returning object:
|
||||
|
||||
%feature("del") *::Operator;
|
||||
%feature("new") *::Operator;
|
||||
|
||||
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","") A::operator+=;
|
||||
%feature("new","") 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+=;
|
||||
|
||||
*/
|
||||
|
||||
#define %pyinplaceoper(PyOper, Oper) %delobject Oper; %newobject Oper; %rename(PyOper) Oper
|
||||
|
||||
%pyinplaceoper(__iadd__ , *::operator +=);
|
||||
%pyinplaceoper(__isub__ , *::operator -=);
|
||||
%pyinplaceoper(__imul__ , *::operator *=);
|
||||
%pyinplaceoper(__idiv__ , *::operator /=);
|
||||
%pyinplaceoper(__imod__ , *::operator %=);
|
||||
%pyinplaceoper(__iand__ , *::operator &=);
|
||||
%pyinplaceoper(__ior__ , *::operator |=);
|
||||
%pyinplaceoper(__ixor__ , *::operator ^=);
|
||||
%pyinplaceoper(__ilshift__, *::operator <<=);
|
||||
%pyinplaceoper(__irshift__, *::operator >>=);
|
||||
|
||||
|
||||
/* 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(mod);
|
||||
%pybinopermaybecall(lshift);
|
||||
%pybinopermaybecall(rshift);
|
||||
%pybinopermaybecall(and);
|
||||
%pybinopermaybecall(or);
|
||||
%pybinopermaybecall(xor);
|
||||
%pybinopermaybecall(lt);
|
||||
%pybinopermaybecall(le);
|
||||
%pybinopermaybecall(gt);
|
||||
%pybinopermaybecall(ge);
|
||||
%pybinopermaybecall(eq);
|
||||
%pybinopermaybecall(ne);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
/* ------------------------------------------------------------
|
||||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* boolean */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
return PyBool_FromLong(value ? 1 : 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return SWIG_OK;
|
||||
} else if (PyLong_Check(obj)) {
|
||||
long v = PyLong_AsLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
%#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 (PyInt_Check(obj)) {
|
||||
long v = PyInt_AsLong(obj);
|
||||
if (v >= 0) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else if (PyLong_Check(obj)) {
|
||||
unsigned long v = PyLong_AsUnsignedLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
%#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_From_frag(long),
|
||||
fragment="<limits.h>") {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header",
|
||||
fragment=SWIG_AsVal_frag(long),
|
||||
fragment="SWIG_CanCastAsInteger",
|
||||
fragment="<limits.h>") {
|
||||
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();
|
||||
}
|
||||
} 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)) {
|
||||
if (val) *val = (long long)(d);
|
||||
return SWIG_AddCast(res);
|
||||
}
|
||||
res = SWIG_TypeError;
|
||||
}
|
||||
%#endif
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment=SWIG_From_frag(long long),
|
||||
fragment="<limits.h>") {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||
fragment=SWIG_AsVal_frag(unsigned long),
|
||||
fragment="SWIG_CanCastAsInteger",
|
||||
fragment="<limits.h>") {
|
||||
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();
|
||||
}
|
||||
} 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)) {
|
||||
if (val) *val = (unsigned long long)(d);
|
||||
return SWIG_AddCast(res);
|
||||
}
|
||||
res = SWIG_TypeError;
|
||||
}
|
||||
%#endif
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
} else if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return SWIG_OK;
|
||||
} 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
@@ -0,0 +1,13 @@
|
||||
%insert(runtime) %{
|
||||
/* Python.h has to appear first */
|
||||
#include <Python.h>
|
||||
%}
|
||||
|
||||
%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"; /* Pyton API */
|
||||
%insert(runtime) "pyrun.swg"; /* Python run-time code */
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
%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_NewPointerObj(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;
|
||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0;
|
||||
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, bool throw_error) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj || !SWIG_IsOK(res)) {
|
||||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(PyObject *obj, bool throw_error) {
|
||||
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 {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(PyObject *obj, bool throw_error) {
|
||||
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>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(PyObject *obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
}
|
||||
|
||||
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
|
||||
%{
|
||||
#include <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)
|
||||
@@ -0,0 +1,75 @@
|
||||
/* ------------------------------------------------------------
|
||||
* 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 (PyString_Check(obj) || PyUnicode_Check(obj) ) {
|
||||
char *cstr; Py_ssize_t len;
|
||||
PyString_AsStringAndSize(obj, &cstr, &len);
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
/*
|
||||
In python the user should not be able to modify the inner
|
||||
string representation. To warranty that, if you define
|
||||
SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string
|
||||
buffer is always returned.
|
||||
|
||||
The default behavior is just to return the pointer value,
|
||||
so, be careful.
|
||||
*/
|
||||
%#if defined(SWIG_PYTHON_SAFE_CSTRINGS)
|
||||
if (*alloc != SWIG_OLDOBJ)
|
||||
%#else
|
||||
if (*alloc == SWIG_NEWOBJ)
|
||||
%#endif
|
||||
{
|
||||
*cptr = %new_copy_array(cstr, len + 1, char);
|
||||
*alloc = SWIG_NEWOBJ;
|
||||
}
|
||||
else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
} else {
|
||||
*cptr = PyString_AsString(obj);
|
||||
}
|
||||
}
|
||||
if (psize) *psize = len + 1;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
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_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
|
||||
} else {
|
||||
return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
|
||||
}
|
||||
} else {
|
||||
return SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Warnings for Python keywords, built-in names and bad names.
|
||||
*/
|
||||
|
||||
#define PYTHONKW(x) %keywordwarn(`x` " is a python keyword, symbol will be renamed as '_" `x`"'", rename="_%s") `x`
|
||||
#define PYTHONBN(x) %builtinwarn(`x` " conflicts with a built-in name in python") "::"`x`
|
||||
|
||||
|
||||
/*
|
||||
Warnings for Python keywords
|
||||
http://www.fnorb.org/docs/1.2/Fnorb-Guide/node62.html
|
||||
*/
|
||||
|
||||
PYTHONKW(and);
|
||||
PYTHONKW(assert);
|
||||
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(yield);
|
||||
|
||||
/*
|
||||
built-in functions
|
||||
http://www.zvon.org/other/python/doc21/lib/built-in-funcs.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(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);
|
||||
PYTHONBN(None);
|
||||
|
||||
|
||||
/*
|
||||
'self' is also a bad Name
|
||||
*/
|
||||
PYTHONBN(self);
|
||||
|
||||
#undef PYTHONBN
|
||||
#undef PYTHONKW
|
||||
@@ -0,0 +1,66 @@
|
||||
#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)
|
||||
# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */
|
||||
# define SWIG_PYTHON_USE_GIL
|
||||
# endif
|
||||
# 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
|
||||
@@ -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."
|
||||
@@ -0,0 +1,98 @@
|
||||
/* ------------------------------------------------------------
|
||||
* Typemap specializations for Python
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Fragment section
|
||||
* ------------------------------------------------------------ */
|
||||
/* bool is dangerous in Python, change precedence */
|
||||
#undef SWIG_TYPECHECK_BOOL
|
||||
%define SWIG_TYPECHECK_BOOL 10000 %enddef
|
||||
|
||||
/* Include fundamental fragemt 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 */
|
||||
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
|
||||
|
||||
/* 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
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* 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, (char*)"$symname", 0, 0, (void *)($value), &$descriptor }
|
||||
|
||||
%typemap(constcode) 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()) {
|
||||
PySwigObject_append((PyObject *) SWIG_Python_GetSwigThis($result),
|
||||
(PyObject *) SWIG_Python_GetSwigThis(robj));
|
||||
Py_DECREF(robj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* shadow code */
|
||||
#define %shadow %insert("shadow")
|
||||
#define %pythoncode %insert("python")
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
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
|
||||
|
||||
and works for modern (-modern) and plain python. We do not use __slots__,
|
||||
so, it works with old python versions.
|
||||
|
||||
*/
|
||||
|
||||
#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 paramaters
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,61 @@
|
||||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%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 (!isunicode && PyString_Check(obj)) {
|
||||
if (cptr) {
|
||||
obj = tmp = PyUnicode_FromObject(obj);
|
||||
}
|
||||
isunicode = 1;
|
||||
}
|
||||
if (isunicode) {
|
||||
int len = PyUnicode_GetSize(obj);
|
||||
if (cptr) {
|
||||
*cptr = %new_array(len + 1, wchar_t);
|
||||
PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len);
|
||||
(*cptr)[len] = 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_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
|
||||
} else {
|
||||
return PyUnicode_FromWideChar(carray, %numeric_cast(size,int));
|
||||
}
|
||||
} else {
|
||||
return SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_alloc.i>
|
||||
@@ -0,0 +1,103 @@
|
||||
#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_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
char* buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::string(buf, size - 1);
|
||||
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%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_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::wstring(buf, size - 1);
|
||||
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,"a wstring is expected");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%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
|
||||
@@ -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="PySwigIterator_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::PySwigIterator::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::PySwigIterator* __iter__(PyObject **PYTHON_SELF) {
|
||||
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
|
||||
}
|
||||
}
|
||||
|
||||
%include <std/std_carray.swg>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_char_traits.i>
|
||||
@@ -0,0 +1,44 @@
|
||||
%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
|
||||
|
||||
|
||||
%include <std/std_common.i>
|
||||
|
||||
//
|
||||
// Generates the traits for all the known primitive
|
||||
// C++ types (int, double, ...)
|
||||
//
|
||||
%apply_cpptypes(%traits_ptypen);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* STD C++ complex typemaps
|
||||
*/
|
||||
|
||||
%include <pycomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
|
||||
/* 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>);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
%include <pycontainer.swg>
|
||||
%include <std/std_container.i>
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/std_except.swg>
|
||||
@@ -0,0 +1,3 @@
|
||||
%rename(ios_base_in) std::ios_base::in;
|
||||
|
||||
%include <std/std_ios.i>
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace std
|
||||
{
|
||||
%callback(1) endl;
|
||||
%callback(1) ends;
|
||||
%callback(1) flush;
|
||||
}
|
||||
|
||||
%include <std/std_iostream.i>
|
||||
@@ -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>
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
Maps
|
||||
*/
|
||||
|
||||
%fragment("StdMapTraits","header",fragment="StdSequenceTraits")
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class K, class T >
|
||||
inline void
|
||||
assign(const PySeq& pyseq, std::map<K,T > *map) {
|
||||
typedef typename std::map<K,T>::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
map->insert(value_type(it->first, it->second));
|
||||
}
|
||||
}
|
||||
|
||||
template <class K, class T>
|
||||
struct traits_asptr<std::map<K,T> > {
|
||||
typedef std::map<K,T> map_type;
|
||||
static int asptr(PyObject *obj, map_type **val) {
|
||||
int res = SWIG_ERROR;
|
||||
if (PyDict_Check(obj)) {
|
||||
PyObject_var items = PyObject_CallMethod(obj,(char *)"items",NULL);
|
||||
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
|
||||
} else {
|
||||
map_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
|
||||
if (SWIG_IsOK(res) && val) *val = p;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <class K, class T >
|
||||
struct traits_from<std::map<K,T> > {
|
||||
typedef std::map<K,T> map_type;
|
||||
typedef typename map_type::const_iterator const_iterator;
|
||||
typedef typename map_type::size_type size_type;
|
||||
|
||||
static PyObject *from(const map_type& map) {
|
||||
swig_type_info *desc = swig::type_info<map_type>();
|
||||
if (desc && desc->clientdata) {
|
||||
return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
|
||||
} else {
|
||||
size_type size = map.size();
|
||||
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
|
||||
if (pysize < 0) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
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::PyObject_var key = swig::from(i->first);
|
||||
swig::PyObject_var val = swig::from(i->second);
|
||||
PyDict_SetItem(obj, key, val);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 PyMapIterator_T : PySwigIteratorClosed_T<OutIterator, ValueType, FromOper>
|
||||
{
|
||||
PyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
|
||||
: PySwigIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class OutIterator,
|
||||
class FromOper = from_key_oper<typename OutIterator::value_type> >
|
||||
struct PyMapKeyIterator_T : PyMapIterator_T<OutIterator, FromOper>
|
||||
{
|
||||
PyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
|
||||
: PyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
|
||||
{
|
||||
return new PyMapKeyIterator_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
|
||||
template<class OutIterator,
|
||||
class FromOper = from_value_oper<typename OutIterator::value_type> >
|
||||
struct PyMapValueIterator_T : PyMapIterator_T<OutIterator, FromOper>
|
||||
{
|
||||
PyMapValueIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
|
||||
: PyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
|
||||
{
|
||||
return new PyMapValueIterator_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_map_common(Map...)
|
||||
%swig_sequence_iterator(Map);
|
||||
%swig_container_methods(Map)
|
||||
|
||||
%extend {
|
||||
mapped_type __getitem__(const key_type& key) const 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();
|
||||
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
|
||||
if (pysize < 0) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
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 (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyList_SET_ITEM(keyList, j, swig::from(i->first));
|
||||
}
|
||||
return keyList;
|
||||
}
|
||||
|
||||
PyObject* values() {
|
||||
Map::size_type size = self->size();
|
||||
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
|
||||
if (pysize < 0) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
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 (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyList_SET_ITEM(valList, j, swig::from(i->second));
|
||||
}
|
||||
return valList;
|
||||
}
|
||||
|
||||
PyObject* items() {
|
||||
Map::size_type size = self->size();
|
||||
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
|
||||
if (pysize < 0) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
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 (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyList_SET_ITEM(itemList, j, swig::from(*i));
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
// Python 2.2 methods
|
||||
bool __contains__(const key_type& key) {
|
||||
return self->find(key) != self->end();
|
||||
}
|
||||
|
||||
%newobject key_iterator(PyObject **PYTHON_SELF);
|
||||
swig::PySwigIterator* 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::PySwigIterator* value_iterator(PyObject **PYTHON_SELF) {
|
||||
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
|
||||
}
|
||||
|
||||
%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()}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %swig_map_methods(Map...)
|
||||
%swig_map_common(Map)
|
||||
%extend {
|
||||
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
%include <std/std_map.i>
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Multimaps
|
||||
*/
|
||||
%include <std_map.i>
|
||||
|
||||
%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits")
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class K, class T >
|
||||
inline void
|
||||
assign(const PySeq& pyseq, std::multimap<K,T > *multimap) {
|
||||
typedef typename std::multimap<K,T>::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.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)) {
|
||||
PyObject_var items = PyObject_CallMethod(obj,(char *)"items",NULL);
|
||||
return traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
|
||||
} else {
|
||||
multimap_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<multimap_type>(),0);
|
||||
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_NewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
|
||||
} else {
|
||||
size_type size = multimap.size();
|
||||
int pysize = (size <= (size_type) INT_MAX) ? (int) 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::PyObject_var key = swig::from(i->first);
|
||||
swig::PyObject_var val = swig::from(i->second);
|
||||
PyDict_SetItem(obj, key, val);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_multimap_methods(Type...)
|
||||
%swig_map_common(Type);
|
||||
%extend {
|
||||
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>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Multisets
|
||||
*/
|
||||
|
||||
%include <std_set.i>
|
||||
|
||||
%fragment("StdMultisetTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
template <class PySeq, class T>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, std::multiset<T>* seq) {
|
||||
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
seq->insert(seq->end(),(value_type)(*it));
|
||||
}
|
||||
#else
|
||||
seq->insert(pyseq.begin(), pyseq.end());
|
||||
#endif
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
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::PyObject_var first = PySequence_GetItem(obj,0);
|
||||
swig::PyObject_var second = PySequence_GetItem(obj,1);
|
||||
res = get_pair(first, second, val);
|
||||
}
|
||||
} else {
|
||||
value_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
|
||||
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)) return res1;
|
||||
U *psecond = &(vp->second);
|
||||
int res2 = swig::asval((PyObject*)second, psecond);
|
||||
if (!SWIG_IsOK(res2)) 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::PyObject_var first = PySequence_GetItem(obj,0);
|
||||
swig::PyObject_var second = PySequence_GetItem(obj,1);
|
||||
res = get_pair(first, second, val);
|
||||
}
|
||||
} else {
|
||||
value_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_pair_methods(pair...)
|
||||
%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}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%include <std/std_pair.i>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Sets
|
||||
*/
|
||||
|
||||
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
template <class PySeq, class T>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, std::set<T>* seq) {
|
||||
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
seq->insert(seq->end(),(value_type)(*it));
|
||||
}
|
||||
#else
|
||||
seq->insert(pyseq.begin(), pyseq.end());
|
||||
#endif
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
%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_set.i>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_sstream.i>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_streambuf.i>
|
||||
@@ -0,0 +1 @@
|
||||
%include <typemaps/std_string.swg>
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Vectors
|
||||
*/
|
||||
|
||||
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
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>
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_wios.i>
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_wsstream.i>
|
||||
@@ -0,0 +1 @@
|
||||
%include <std/std_wstreambuf.i>
|
||||
@@ -0,0 +1,3 @@
|
||||
%include <pywstrings.swg>
|
||||
%include <typemaps/std_wstring.swg>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/* initial STL definition. extended as needed in each language */
|
||||
%include <std_common.i>
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_pair.i>
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* typemaps.i
|
||||
*
|
||||
* 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>
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user