From: Martin Ling Date: Tue, 20 Oct 2015 22:14:45 +0000 (+0100) Subject: SWIG: Declare template specialisations for containers before typemaps. X-Git-Tag: libsigrok-0.4.0~189 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c7855def613435e18c1424ce87ffda8a42f1c53f;p=libsigrok.git SWIG: Declare template specialisations for containers before typemaps. It seems this is necessary to correctly apply typemaps involving these template specialisations. --- diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index 34323b16..fb8da272 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -44,6 +44,8 @@ namespace Glib { class VariantBase {}; } +%include "bindings/swig/templates.i" + /* Map between std::vector and java.util.Vector */ %define VECTOR(CValue, JValue) @@ -384,8 +386,9 @@ typedef jobject jdatafeedcallback; %define %enumextras(Class) %enddef -/* Ignore this for now, needs a fix. */ +/* Ignore these for now, need fixes. */ %ignore sigrok::Context::create_analog_packet; +%ignore sigrok::Context::create_meta_packet; %include "bindings/swig/classes.i" diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 49cfba98..9dd34ac6 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -83,6 +83,8 @@ typedef guint pyg_flags_type; import_array(); %} +%include "../../../swig/templates.i" + /* Map file objects to file descriptors. */ %typecheck(SWIG_TYPECHECK_POINTER) int fd { $1 = (PyObject_AsFileDescriptor($input) != -1); diff --git a/bindings/swig/classes.i b/bindings/swig/classes.i index 309bd340..f556ba1a 100644 --- a/bindings/swig/classes.i +++ b/bindings/swig/classes.i @@ -19,16 +19,7 @@ #pragma SWIG nowarn=325,401 -%{ -#include -using namespace std; -%} - %include "typemaps.i" -%include "std_string.i" -%include "std_vector.i" -%include "std_map.i" -%include "std_shared_ptr.i" %include "exception.i" %{ @@ -85,54 +76,6 @@ template< class T > class enable_shared_from_this; %shared_ptr(sigrok::TriggerMatch); %shared_ptr(sigrok::UserDevice); -%template(StringMap) std::map; - -%template(DriverMap) - std::map >; -%template(InputFormatMap) - std::map >; -%template(OutputFormatMap) - std::map >; - -%template(HardwareDeviceVector) - std::vector >; - -%template(DeviceVector) - std::vector >; - -%template(ChannelVector) - std::vector >; - -%template(ChannelGroupMap) - std::map >; - -/* Workaround for SWIG bug. The vector template instantiation - isn't needed but somehow fixes a bug that stops the wrapper - for the map instantiation from compiling. */ -%template(ConfigVector) - std::vector; -%template(ConfigMap) - std::map; - -%template(OptionVector) - std::vector >; -%template(OptionMap) - std::map >; - -%template(VariantVector) - std::vector; -%template(VariantMap) - std::map; - -%template(QuantityFlagVector) - std::vector; - -%template(TriggerStageVector) - std::vector >; - -%template(TriggerMatchVector) - std::vector >; - #define SR_API #define SR_PRIV diff --git a/bindings/swig/templates.i b/bindings/swig/templates.i new file mode 100644 index 00000000..bbb3619c --- /dev/null +++ b/bindings/swig/templates.i @@ -0,0 +1,76 @@ +/* + * This file is part of the libsigrok project. + * + * Copyright (C) 2015 Martin Ling + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +%{ +#include +using namespace std; +%} + +%include "std_string.i" +%include "std_shared_ptr.i" +%include "std_vector.i" +%include "std_map.i" + +%template(StringMap) std::map; + +%template(DriverMap) + std::map >; +%template(InputFormatMap) + std::map >; +%template(OutputFormatMap) + std::map >; + +%template(HardwareDeviceVector) + std::vector >; + +%template(DeviceVector) + std::vector >; + +%template(ChannelVector) + std::vector >; + +%template(ChannelGroupMap) + std::map >; + +/* Workaround for SWIG bug. The vector template instantiation + isn't needed but somehow fixes a bug that stops the wrapper + for the map instantiation from compiling. */ +%template(ConfigVector) + std::vector; +%template(ConfigMap) + std::map; + +%template(OptionVector) + std::vector >; +%template(OptionMap) + std::map >; + +%template(VariantVector) + std::vector; +%template(VariantMap) + std::map; + +%template(QuantityFlagVector) + std::vector; + +%template(TriggerStageVector) + std::vector >; + +%template(TriggerMatchVector) + std::vector >;