SWIG: Declare template specialisations for containers before typemaps.

It seems this is necessary to correctly apply typemaps involving
these template specialisations.
This commit is contained in:
Martin Ling 2015-10-20 23:14:45 +01:00 committed by Uwe Hermann
parent 7977054d61
commit c7855def61
4 changed files with 82 additions and 58 deletions

View File

@ -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"

View File

@ -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);

View File

@ -19,16 +19,7 @@
#pragma SWIG nowarn=325,401
%{
#include <libsigrokcxx/libsigrokcxx.hpp>
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<std::string, std::string>;
%template(DriverMap)
std::map<std::string, std::shared_ptr<sigrok::Driver> >;
%template(InputFormatMap)
std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
%template(OutputFormatMap)
std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
%template(HardwareDeviceVector)
std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
%template(DeviceVector)
std::vector<std::shared_ptr<sigrok::Device> >;
%template(ChannelVector)
std::vector<std::shared_ptr<sigrok::Channel> >;
%template(ChannelGroupMap)
std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
/* 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<const sigrok::ConfigKey *>;
%template(ConfigMap)
std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
%template(OptionVector)
std::vector<std::shared_ptr<sigrok::Option> >;
%template(OptionMap)
std::map<std::string, std::shared_ptr<sigrok::Option> >;
%template(VariantVector)
std::vector<Glib::VariantBase>;
%template(VariantMap)
std::map<std::string, Glib::VariantBase>;
%template(QuantityFlagVector)
std::vector<const sigrok::QuantityFlag *>;
%template(TriggerStageVector)
std::vector<std::shared_ptr<sigrok::TriggerStage> >;
%template(TriggerMatchVector)
std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
#define SR_API
#define SR_PRIV

76
bindings/swig/templates.i Normal file
View File

@ -0,0 +1,76 @@
/*
* This file is part of the libsigrok project.
*
* Copyright (C) 2015 Martin Ling <martin-sigrok@earth.li>
*
* 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 <http://www.gnu.org/licenses/>.
*/
%{
#include <libsigrokcxx/libsigrokcxx.hpp>
using namespace std;
%}
%include "std_string.i"
%include "std_shared_ptr.i"
%include "std_vector.i"
%include "std_map.i"
%template(StringMap) std::map<std::string, std::string>;
%template(DriverMap)
std::map<std::string, std::shared_ptr<sigrok::Driver> >;
%template(InputFormatMap)
std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
%template(OutputFormatMap)
std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
%template(HardwareDeviceVector)
std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
%template(DeviceVector)
std::vector<std::shared_ptr<sigrok::Device> >;
%template(ChannelVector)
std::vector<std::shared_ptr<sigrok::Channel> >;
%template(ChannelGroupMap)
std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
/* 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<const sigrok::ConfigKey *>;
%template(ConfigMap)
std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
%template(OptionVector)
std::vector<std::shared_ptr<sigrok::Option> >;
%template(OptionMap)
std::map<std::string, std::shared_ptr<sigrok::Option> >;
%template(VariantVector)
std::vector<Glib::VariantBase>;
%template(VariantMap)
std::map<std::string, Glib::VariantBase>;
%template(QuantityFlagVector)
std::vector<const sigrok::QuantityFlag *>;
%template(TriggerStageVector)
std::vector<std::shared_ptr<sigrok::TriggerStage> >;
%template(TriggerMatchVector)
std::vector<std::shared_ptr<sigrok::TriggerMatch> >;