eliminate compilation warnings, add docs, and centralize the access to the unified typemap library

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7710 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-25 09:31:15 +00:00
commit 029ff00d77
31 changed files with 746 additions and 492 deletions

View file

@ -26,39 +26,3 @@
}
}
/*
typemaps needed due to unnamed enums
*/
%define %enum_out_typemaps(from_meth,frag)
%typemap(out,noblock=1,fragment=frag) enum SWIGTYPE {
%set_output(from_meth(($1)));
}
%typemap(out,noblock=1,fragment=frag) const enum SWIGTYPE& {
%set_output(from_meth((*$1)));
}
%typemap(varout,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& {
%set_varoutput(from_meth($1));
}
%typemap(constcode,noblock=1,fragment=frag) enum SWIGTYPE {
%set_constant("$symname", from_meth($value));
}
%typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE *DIRECTORIN {
$input = from_meth(*$1_name);
}
%typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& {
$input = from_meth($1_name);
}
%typemap(throws,noblock=1,fragment=frag) enum SWIGTYPE {
%raise(from_meth($1),"$type",0);
}
%enddef
%enum_out_typemaps(SWIG_From(int),SWIG_From_frag(int));

View file

@ -1,143 +0,0 @@
/*
Special macros to define and use fragment names and declarations.
These macros generate the names used in fragments, for example, a
typical use will be:
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(bool)(bool value)
{
PyObject *obj = value ? Py_True : Py_False;
Py_INCREF(obj);
return obj;
}
}
and then you can call the method using
%typemap(out,fragment=SWIG_From_frag(bool)) bool {
%set_output(SWIG_From(bool)($1));
}
when the typemap get generated, the proper fragment for the
SWIG_From(bool) method will be included.
*/
#define SWIG_Traits_frag(Type...) %string_type(Traits, Type)
#define SWIG_AsPtr_frag(Type...) %string_type(AsPtr, Type)
#define SWIG_AsVal_frag(Type...) %string_type(AsVal, Type)
#define SWIG_From_frag(Type...) %string_type(From, Type)
#ifndef SWIG_ASVAL_DECL_ARGS
#define SWIG_ASVAL_DECL_ARGS
#endif
#ifndef SWIG_ASPTR_DECL_ARGS
#define SWIG_ASPTR_DECL_ARGS
#endif
#ifndef SWIG_FROM_DECL_ARGS
#define SWIG_FROM_DECL_ARGS
#endif
#ifndef SWIG_ASVAL_CALL_ARGS
#define SWIG_ASVAL_CALL_ARGS
#endif
#ifndef SWIG_ASPTR_CALL_ARGS
#define SWIG_ASPTR_CALL_ARGS
#endif
#ifndef SWIG_FROM_CALL_ARGS
#define SWIG_FROM_CALL_ARGS
#endif
#define SWIG_AsVal_dec(Type...) %name_type(AsVal, Type) SWIG_ASVAL_DECL_ARGS
#define SWIG_AsPtr_dec(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_DECL_ARGS
#define SWIG_From_dec(Type...) %name_type(From, Type) SWIG_FROM_DECL_ARGS
#define SWIG_AsVal(Type...) %name_type(AsVal, Type) SWIG_ASVAL_CALL_ARGS
#define SWIG_AsPtr(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_CALL_ARGS
#define SWIG_From(Type...) %name_type(From, Type) SWIG_FROM_CALL_ARGS
/* ------------------------------------------------------------
* common macro helpers
* ------------------------------------------------------------ */
/* Macros for numeric types */
%define %numeric_type_from(Type, Base)
%fragment(SWIG_From_frag(Type),"header",
fragment=SWIG_From_frag(Base)) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(Type)(Type value)
{
return SWIG_From(Base)(value);
}
}
%enddef
%define %numeric_type_asval(Type, Base, Frag, OverflowCond)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=Frag,
fragment=SWIG_AsVal_frag(Base)) {
SWIGINTERN int
SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
{
Base v;
int res = SWIG_AsVal(Base)(obj, &v);
if (res == SWIG_OK) {
if (OverflowCond) {
return SWIG_OverflowError;
} else {
if (val) *val = %numeric_cast(v, Type);
return SWIG_OK;
}
}
return res;
}
}
%enddef
%define %numeric_signed_type_asval(Type, Base, Frag, Min, Max)
%numeric_type_asval(Type, Base, Frag, (v < Min || v > Max))
%enddef
%define %numeric_unsigned_type_asval(Type, Base, Frag, Max)
%numeric_type_asval(Type, Base, Frag, (v > Max))
%enddef
/* Macro for 'signed long' derived types */
%define %numeric_slong(Type, Frag, Min, Max)
%numeric_type_from(Type, long)
%numeric_signed_type_asval(Type, long, Frag , Min, Max)
%enddef
/* Macro for 'unsigned long' derived types */
%define %numeric_ulong(Type, Frag, Max)
%numeric_type_from(Type, unsigned long)
%numeric_unsigned_type_asval(Type, unsigned long, Frag, Max)
%enddef
/* Macro for 'double' derived types */
%define %numeric_double(Type, Frag, Min, Max)
%numeric_type_from(Type, double)
%numeric_signed_type_asval(Type, double, Frag , Min, Max)
%enddef

View file

@ -269,11 +269,51 @@
*/
/* -----------------------------------------------------------------------------
* Define the basic macros to 'normalize' the type fragments
* ----------------------------------------------------------------------------- */
#ifndef SWIG_ASVAL_DECL_ARGS
#define SWIG_ASVAL_DECL_ARGS
#endif
#ifndef SWIG_ASPTR_DECL_ARGS
#define SWIG_ASPTR_DECL_ARGS
#endif
#ifndef SWIG_FROM_DECL_ARGS
#define SWIG_FROM_DECL_ARGS
#endif
#ifndef SWIG_ASVAL_CALL_ARGS
#define SWIG_ASVAL_CALL_ARGS
#endif
#ifndef SWIG_ASPTR_CALL_ARGS
#define SWIG_ASPTR_CALL_ARGS
#endif
#ifndef SWIG_FROM_CALL_ARGS
#define SWIG_FROM_CALL_ARGS
#endif
#define SWIG_Traits_frag(Type...) %string_type(Traits, Type)
#define SWIG_AsPtr_frag(Type...) %string_type(AsPtr, Type)
#define SWIG_AsVal_frag(Type...) %string_type(AsVal, Type)
#define SWIG_From_frag(Type...) %string_type(From, Type)
#define SWIG_AsVal_dec(Type...) %name_type(AsVal, Type) SWIG_ASVAL_DECL_ARGS
#define SWIG_AsPtr_dec(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_DECL_ARGS
#define SWIG_From_dec(Type...) %name_type(From, Type) SWIG_FROM_DECL_ARGS
#define SWIG_AsVal(Type...) %name_type(AsVal, Type) SWIG_ASVAL_CALL_ARGS
#define SWIG_AsPtr(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_CALL_ARGS
#define SWIG_From(Type...) %name_type(From, Type) SWIG_FROM_CALL_ARGS
/* ------------------------------------------------------------
* common fragments
* ------------------------------------------------------------ */
%fragment("<limits.h>","header") %{
#include <limits.h>
%}
@ -286,4 +326,90 @@
#include <float.h>
%}
/* -----------------------------------------------------------------------------
* special macros for fragments
* ----------------------------------------------------------------------------- */
/* Macros to derive numeric types */
%define %numeric_type_from(Type, Base)
%fragment(SWIG_From_frag(Type),"header",
fragment=SWIG_From_frag(Base)) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(Type)(Type value)
{
return SWIG_From(Base)(value);
}
}
%enddef
%define %numeric_type_asval(Type, Base, Frag, OverflowCond)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=Frag,
fragment=SWIG_AsVal_frag(Base)) {
SWIGINTERN int
SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
{
Base v;
int res = SWIG_AsVal(Base)(obj, &v);
if (res == SWIG_OK) {
if (OverflowCond) {
return SWIG_OverflowError;
} else {
if (val) *val = %numeric_cast(v, Type);
return SWIG_OK;
}
}
return res;
}
}
%enddef
%define %numeric_signed_type_asval(Type, Base, Frag, Min, Max)
%numeric_type_asval(Type, Base, Frag, (v < Min || v > Max))
%enddef
%define %numeric_unsigned_type_asval(Type, Base, Frag, Max)
%numeric_type_asval(Type, Base, Frag, (v > Max))
%enddef
/* Macro for 'signed long' derived types */
%define %numeric_slong(Type, Frag, Min, Max)
%numeric_type_from(Type, long)
%numeric_signed_type_asval(Type, long, Frag , Min, Max)
%enddef
/* Macro for 'unsigned long' derived types */
%define %numeric_ulong(Type, Frag, Max)
%numeric_type_from(Type, unsigned long)
%numeric_unsigned_type_asval(Type, unsigned long, Frag, Max)
%enddef
/* Macro for 'double' derived types */
%define %numeric_double(Type, Frag, Min, Max)
%numeric_type_from(Type, double)
%numeric_signed_type_asval(Type, double, Frag , Min, Max)
%enddef
/* Macros for missing fragments */
%define %ensure_fragment(Fragment)
%fragment(`Fragment`,"header") {
%#error "Swig language implementation must provide the Fragment fragment"
}
%enddef
%define %ensure_type_fragments(Type)
%fragment(SWIG_From_frag(Type),"header") {
%#error "Swig language implementation must provide a SWIG_From_frag(Type) fragment"
}
%fragment(SWIG_AsVal_frag(Type),"header") {
%#error "Swig language implementation must provide a SWIG_AsVal_frag(Type) fragment"
}
%enddef

View file

@ -1,7 +1,117 @@
/* ------------------------------------------------------------
* Basic fragments derived from long and double types
* Primitive type fragments and macros
* ------------------------------------------------------------ */
/*
This file provide fragments and macros for the C/C++ primitive types.
The file defines default fragments for the following types:
bool
signed char
unsigned char
signed wchar_t // in C++
unsigned wchar_t // in C++
short
unsigned short
int
unsigned int
float
which can always be redefined in the swig target languge if needed.
The fragments for the following types, however, need to be defined
in the target language always:
long
unsigned long
long long
unsigned long long
double
If they are not provided, an #error directive will appear in the
wrapped code.
--------------------------------------------------------------------
This file provides the macro
%typemaps_primitive(CheckCode, Type)
which generate the typemaps for a primitive type with a given
checkcode. It is assumed the the primitive type is 'normalized' and
the corresponding SWIG_AsVal(Type) and SWIG_From(Type) methods are
provided via fragments.
The following auxiliar macros (explained with bash pseudo code) are
also defined:
%apply_ctypes(Macro)
for i in C Type
do
Macro($i)
done
%apply_cpptypes(Macro)
for i in C++ Type
do
Macro($i)
done
%apply_ctypes_2(Macro2)
for i in C Type
do
for j in C Type
do
Macro_2($i, $j)
done
done
%apply_cpptypes_2(Macro2)
for i in C++ Type
do
for j in C++ Type
do
Macro_2($i, $j)
done
done
%apply_checkctypes(Macro2)
for i in Check Type
do
Macro2(%checkcode($i), $i)
done
*/
/* ------------------------------------------------------------
* Primitive type fragments
* ------------------------------------------------------------ */
/* boolean */
%fragment(SWIG_From_frag(bool),"header",fragment=SWIG_From_frag(long)) {
SWIGINTERN SWIG_Object
SWIG_From_dec(bool)(bool value)
{
return SWIG_From(long)(value ? 1 : 0);
}
}
%fragment(SWIG_AsVal_frag(bool),"header",fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val)
{
long v;
if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) {
if (val) *val = v ? true : false;
return SWIG_OK;
}
return SWIG_TypeError;
}
}
/* signed/unsigned char */
%numeric_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
@ -28,9 +138,23 @@
%numeric_double(float, "<float.h>", -FLT_MAX, FLT_MAX)
/* long/unsgined long */
%ensure_type_fragments(long)
%ensure_type_fragments(unsigned long)
/* long long/unsigned long long */
%ensure_type_fragments(long long)
%ensure_type_fragments(unsigned long long)
/* double */
%ensure_type_fragments(double)
/* ------------------------------------------------------------
* typemap macro for primitive types with asval/from methods
* Generate the typemaps for primitive type
* ------------------------------------------------------------ */
%define %typemaps_primitive(Code, Type)
@ -70,7 +194,12 @@ _apply_macro(Macro, char , __VA_ARGS__);
_apply_macro(Macro, wchar_t , __VA_ARGS__);
%enddef
/* apply the Macro(Type) to all the C++ types */
/* apply the Macro2(Type1, Type2) to all C types */
%define %apply_ctypes_2(Macro2)
%apply_ctypes(%apply_ctypes, Macro2)
%enddef
/* apply the Macro(Type) to all C++ types */
%define %apply_cpptypes(Macro,...)
%apply_ctypes(Macro, __VA_ARGS__)
_apply_macro(Macro, std::string, __VA_ARGS__);
@ -78,32 +207,33 @@ _apply_macro(Macro, std::complex<float>, __VA_ARGS__);
_apply_macro(Macro, std::complex<double>, __VA_ARGS__);
%enddef
/* apply the Macro2(Type1, Type2) to all the C++ types */
/* apply the Macro2(Type1, Type2) to all C++ types */
%define %apply_cpptypes_2(Macro2)
%apply_cpptypes(%apply_cpptypes, Macro2)
%enddef
%define %apply_checkctypes(Macro)
Macro(%checkcode(BOOL), bool);
Macro(%checkcode(INT8), signed char);
Macro(%checkcode(UINT8), unsigned char);
Macro(%checkcode(INT16), short);
Macro(%checkcode(UINT16), unsigned short);
Macro(%checkcode(INT32), int);
Macro(%checkcode(UINT32), unsigned int);
Macro(%checkcode(INT64), long);
Macro(%checkcode(UINT64), unsigned long);
Macro(%checkcode(INT128), long long);
Macro(%checkcode(UINT128), unsigned long long);
Macro(%checkcode(FLOAT), float);
Macro(%checkcode(DOUBLE), double);
Macro(%checkcode(CHAR), char);
Macro(%checkcode(UNICHAR), wchar_t);
/* apply the Macro2(CheckCode,Type) to all Checked Types */
%define %apply_checkctypes(Macro2)
Macro2(%checkcode(BOOL), bool);
Macro2(%checkcode(INT8), signed char);
Macro2(%checkcode(UINT8), unsigned char);
Macro2(%checkcode(INT16), short);
Macro2(%checkcode(UINT16), unsigned short);
Macro2(%checkcode(INT32), int);
Macro2(%checkcode(UINT32), unsigned int);
Macro2(%checkcode(INT64), long);
Macro2(%checkcode(UINT64), unsigned long);
Macro2(%checkcode(INT128), long long);
Macro2(%checkcode(UINT128), unsigned long long);
Macro2(%checkcode(FLOAT), float);
Macro2(%checkcode(DOUBLE), double);
Macro2(%checkcode(CHAR), char);
Macro2(%checkcode(UNICHAR), wchar_t);
%enddef
/* ------------------------------------------------------------
* Apply the primitive typemap for all the types with checkcode
* Generate the typemaps for all the primitive types with checkcode
* ------------------------------------------------------------ */
%apply_checkctypes(%typemaps_primitive);

View file

@ -1,3 +1,7 @@
%ensure_fragment(SWIG_AsCharPtrAndSize)
%ensure_fragment(SWIG_FromCharPtrAndSize)
%include <typemaps/strings.swg>
%typemaps_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen,
"<limits.h>", CHAR_MIN, CHAR_MAX)

View file

@ -1,14 +1,97 @@
/* -----------------------------------------------------------------------------
* SWIG API. Portion only visible from SWIG
* ----------------------------------------------------------------------------- */
/*
This file implements the internal macros of the 'SWIG API', which
are useful to implement all the SWIG target languges.
Basic preprocessor macros:
--------------------------
%arg(Arg) Safe argument wrap
%str(Arg) Stringtify the argument
%begin_block Begin a execution block
%end_block End a execution block
%block(Block) Execute Block as a excecution block
%define_as(Def, Val) Define 'Def' as 'Val', expanding Def and Val first
%ifcplusplus(V1, V2) if C++ Mode; then V1; else V2; fi
Casting Operations:
-------------------
Swig provides the following casting macros, which implement the
corresponding C++ casting operations:
%const_cast(a, Type) const_cast<Type >(a)
%static_cast(a, Type) static_cast<Type >(a)
%reinterpret_cast(a, Type) reinterpret_cast<Type >(a)
%numeric_cast(a, Type) static_cast<Type >(a)
%as_voidptr(a) const_cast<void *>(static_cast<const void *>(a))
%as_voidptrptr(a) reinterpret_cast<void **>(a)
or their C unsafe versions. In C++ we use the safe version unless
SWIG_NO_CPLUSPLUS_CAST is defined (usually via the -nocppcast swig flag).
Memory allocation:
------------------
These allocation/freeing macros are safe to use in C or C++ and
dispatch the proper new/delete/delete[] or free/malloc calls as
needed.
%new_instance(Type) Allocate a new instance of given Type
%new_copy(value,Type) Allocate and initialize a new instance with 'value'
%new_array(size,Type) Allocate a new array with given size and Type
%new_copy_array(cptr,size,Type) Allocate and initialize a new array from 'cptr'
%delete(cptr) Delete an instance
%delete_array(cptr) Delete an array
Auxiliar loop macros:
---------------------
%formacro(Macro, Args...) or %formacro_1(Macro, Args...)
for i in Args
do
Macro($i)
done
%formacro_2(Macro2, Args...)
for i,j in Args
do
Macro2($i, $j)
done
Swig flags:
-----------
%swig_mark_flag(flag)
flag := True
%evalif(flag,expr)
if flag; then
expr
fi
%evalif_2(flag1 flag2,expr)
if flag1 and flag2; then
expr
fi
*/
/* -----------------------------------------------------------------------------
* Basic preprocessor macros
* ----------------------------------------------------------------------------- */
#define %arg(Arg...) Arg
#define %str(Type...) #Type
#define %block(Block...) do { Block; } while(0)
#define %arg(Arg...) Arg
#define %str(Arg) `Arg`
#define %begin_block do {
#define %end_block } while(0)
#define %block(Block...) %begin_block Block; %end_block
/* define a new macro */
%define %define_as(Def, Val...)
@ -41,7 +124,7 @@ nocppval
# define %reinterpret_cast(a,Type...) reinterpret_cast<Type >(a)
# define %numeric_cast(a,Type...) static_cast<Type >(a)
# define %as_voidptr(a) const_cast<void *>(static_cast<const void *>(a))
# define %as_voidptrptr(a) reinterpret_cast<void **>(a)
# define %as_voidptrptr(a) reinterpret_cast<void **>(a)
#else /* C case */
# define %const_cast(a,Type...) (Type)(a)
# define %static_cast(a,Type...) (Type)(a)
@ -81,27 +164,8 @@ nocppval
#define %checkcode(Code) %name_type(TYPECHECK, Code)
/*
Macros to define language dependent object and the void object.
Use them, for example in Tcl, as
%define_swig_object(Tcl_Obj *)
%define_void_object(NULL)
*/
/* VOID_Object */
%define %define_void_object(Obj)
#define VOID_Object Obj
%enddef
/* SWIG_Object */
%define %define_swig_object(Obj)
#define SWIG_Object Obj
%enddef
/* -----------------------------------------------------------------------------
* Auxiliar ugly macros used to write typemaps
* Auxiliar loop macros
* ----------------------------------------------------------------------------- */
@ -117,6 +181,9 @@ macro(arg1)
%define %formacro_1(macro,...)
%_formacro_1(macro,__VA_ARGS__,__fordone__)
%enddef
%define %formacro(macro,...)
%_formacro_1(macro,__VA_ARGS__,__fordone__)
%enddef
/* for loop for macro with two arguments */
%define %_formacro_2(macro, arg1, arg2, ...)
@ -131,30 +198,21 @@ macro(arg1, arg2)
%_formacro_2(macro, __VA_ARGS__, __fordone__)
%enddef
/* -----------------------------------------------------------------------------
* Swig flags
* ----------------------------------------------------------------------------- */
/*
mark a flag, ie, define a macro name but ignore it in
the interface.
the flags latter can be used with %evalif
the flag can be later used with %evalif
*/
%define %swig_mark_flag(x)
%ignore x;
#define x 1
%define x 1 %enddef
%enddef
/*
%swig_equal_type and %swig_order_type flagged a type of having equal (==,!=)
and/or order methods (<=,>=,<,>).
*/
#define SWIG_OrderType(Type...) %name_type(OrderType, Type)
#define SWIG_EqualType(Type...) %name_type(EqualType, Type)
#define %swig_equal_type(...) %swig_mark_flag(SWIG_EqualType(__VA_ARGS__))
#define %swig_order_type(...) \
%swig_mark_flag(SWIG_EqualType(__VA_ARGS__)) \
%swig_mark_flag(SWIG_OrderType(__VA_ARGS__))
/*
%evalif and %evalif_2 are use to evaluate or process
@ -172,17 +230,11 @@ _expr
#endif
%enddef
%define %evalif(_x,...)
%_evalif(%arg(_x),%arg(__VA_ARGS__))
%define %evalif(_x,_expr...)
%_evalif(%arg(_x),%arg(_expr))
%enddef
%define %evalif_2(_x,_y,...)
%_evalif_2(%arg(_x),%arg(_y),%arg(__VA_ARGS__))
%define %evalif_2(_x,_y,_expr...)
%_evalif_2(%arg(_x),%arg(_y),%arg(_expr))
%enddef
/* -----------------------------------------------------------------------------
* Include special macros for fragments
* ----------------------------------------------------------------------------- */
%include <typemaps/fragmacros.swg>

View file

@ -2,10 +2,6 @@
* Language Object * - Just pass straight through unmodified
* ------------------------------------------------------------ */
#if !defined(SWIG_Object)
#error "SWIG_Object must be defined using %define_swig_object"
#endif
%typemap(in) SWIG_Object "$1 = $input;";
%typemap(out,noblock=1) SWIG_Object {

View file

@ -1,68 +1,151 @@
/* -----------------------------------------------------------------------------
* Typemap specializations
* Unified Typemap Library frontend
* ----------------------------------------------------------------------------- */
/* flags for new/convert methods */
/*
This file provides the frontend to the Unified Typemap Library.
When using this library in a SWIG target language, you need to
define a minimum set of fragments, specialized a couple of macros,
and then include this file.
Typically you will create a 'mytypemaps.swg' file in each target
languge, where you will have the following sections:
=== mytypemaps.swg ===
// Fragment section
%include <typemaps/fragments.swg>
<include target language fragments>
// Unified typemap section
<specialized the typemap library macros>
%include <typemaps/swigtypemaps.swg>
// Local typemap section
<add/replace extra target language typemaps>
=== mytypemaps.swg ===
While we add more docs, please take a look at the following cases
to see how you specialized the unified typemap library for a new
target language:
Lib/python/pytypemaps.swg
Lib/tcl/tcltypemaps.swg
Lib/ruby/rubytypemaps.swg
Lib/perl5/perl5typemaps.swg
*/
/* -----------------------------------------------------------------------------
* Language specialization section.
*
* Tune these macros for each language as needed.
* ----------------------------------------------------------------------------- */
/*
The SWIG target language object must be provided.
For example in python you define:
#define SWIG_Object PyObject *
*/
#if !defined(SWIG_Object)
#error "SWIG_Object must be defined as the SWIG target language object"
#endif
/*==== flags for new/convert methods ====*/
#ifndef %convertptr_flags
%ignore %convertptr_flags;
#define %convertptr_flags 0
%define %convertptr_flags 0 %enddef
#endif
#ifndef %newpointer_flags
%ignore %newpointer_flags;
#define %newpointer_flags 0
%define %newpointer_flags 0 %enddef
#endif
#ifndef %newinstance_flags
%ignore %newinstance_flags;
#define %newinstance_flags 0
%define %newinstance_flags 0 %enddef
#endif
/* output and constant manipulation */
#ifndef %set_varoutput
#define %set_varoutput(obj) $result = obj
#endif
/*==== set output ====*/
#ifndef %set_output
#define %set_output(obj) $result = obj
/* simple set output operation */
#define %set_output(obj) $result = obj
#endif
/*==== set variable output ====*/
#ifndef %set_varoutput
/* simple set varoutput operation */
#define %set_varoutput(obj) $result = obj
#endif
/*==== append output ====*/
#ifndef %append_output
#define %append_output(obj) $result = SWIG_AppendOutput($result,obj)
#if defined(SWIG_AppendOutput)
/* simple append operation */
#define %append_output(obj) $result = SWIG_AppendOutput($result,obj)
#else
#error "Language must define SWIG_AppendOutput or %append_output"
#endif
#endif
/*==== set constant ====*/
#ifndef %set_constant
#define %set_constant(name,value) SWIG_SetConstant(name,value)
#if defined(SWIG_SetConstant)
/* simple set constant operation */
#define %set_constant(name,value) SWIG_SetConstant(name,value)
#else
#error "Language must define SWIG_SetConstant or %set_constant"
#endif
#endif
/* setting an error and exit */
/*==== raise an exception ====*/
#ifndef %raise
#if defined(SWIG_Raise)
/* simple raise operation */
#define %raise(obj, type, desc) %error_block(SWIG_Raise(obj, type, desc); SWIG_fail)
#else
#error "Language must define SWIG_Raise or %raise"
#endif
#endif
/*==== director output exception ====*/
#ifdef SWIG_DIRECTOR_TYPEMAPS
#ifndef SWIG_DirOutFail
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
#endif
#endif
/* -----------------------------------------------------------------------------
* Language independent definitions
* ----------------------------------------------------------------------------- */
#define %error_block(Block...) %block(Block)
#define %argument_fail(code, type, argn) %error_block(SWIG_Error(code, %argfail_fmt(type, argn)); SWIG_fail)
#define %argument_nullref(type, argn) %error_block(SWIG_Error(SWIG_ValueError, %argnullref_fmt(type, argn)); SWIG_fail)
#define %variable_fail(code, type, name) %error_block(SWIG_Error(code, %varfail_fmt(type, name)); SWIG_fail)
#define %variable_nullref(type, name) %error_block(SWIG_Error(SWIG_ValueError, %varnullref_fmt(type, name)); SWIG_fail)
#ifndef %raise
#define %raise(obj, type, desc) %error_block(SWIG_Raise(obj, type, desc); SWIG_fail)
#endif
#ifdef SWIG_DIRECTOR_TYPEMAPS
#define %dirout_fail(code, type) SWIG_DirOutFail(code, %outfail_fmt(type))
#define %dirout_nullref(type) SWIG_DirOutFail(SWIG_ValueError, %outnullref_fmt(type))
#endif
/* -----------------------------------------------------------------------------
* All the typemaps
* ----------------------------------------------------------------------------- */
%include <typemaps/fragments.swg>
%include <typemaps/exception.swg>
%include <typemaps/swigtype.swg>

View file

@ -76,7 +76,7 @@
%define %value_varout_typemap(from_meth,frag,Type...)
%typemap(varout,noblock=1,fragment=frag) Type, const Type& {
%set_varoutput(from_meth(%static_cast($1,$basetype)));
%set_varoutput(from_meth(%static_cast($1,Type)));
}
%enddef

View file

@ -2,10 +2,6 @@
* Void * - Accepts any kind of pointer
* ------------------------------------------------------------ */
#if !defined(VOID_Object)
#error "VOID_Object must be defined using %define_void_object"
#endif
/* in */
%typemap(in,noblock=1) void * {
@ -26,9 +22,11 @@
/* out */
%typemap(out,noblock=1) void {
$result = VOID_Object;
}
#if defined(VOID_Object)
%typemap(out,noblock=1) void { $result = VOID_Object; }
#else
%typemap(out,noblock=1) void {}
#endif
/* varin */

View file

@ -1,3 +1,6 @@
%ensure_fragment(SWIG_AsWCharPtrAndSize)
%ensure_fragment(SWIG_FromWCharPtrAndSize)
%include <typemaps/strings.swg>
%typemaps_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen,
"<wchar.h>", WCHAR_MIN, WCHAR_MAX)